Update app.py
Browse files
app.py
CHANGED
|
@@ -306,14 +306,19 @@ def find_alternative_anchor(blocks, target_url, original_anchor):
|
|
| 306 |
# Return in format compatible with existing code
|
| 307 |
chosen_keyword = result.get("chosen_keyword", keywords[0] if keywords else original_anchor)
|
| 308 |
new_content = result.get("new_content", "")
|
| 309 |
-
|
| 310 |
-
reasoning = result.get("reasoning", "")
|
| 311 |
|
| 312 |
# Format the response for compatibility
|
| 313 |
-
#
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
|
| 316 |
-
return chosen_keyword, f"{position_text}\n\n{new_content}"
|
| 317 |
|
| 318 |
except Exception as e:
|
| 319 |
print(f"[Alternative] Critical error: {e}")
|
|
@@ -678,15 +683,15 @@ def gpt_generate_content_with_keyword(source_blocks, keywords, target_url, langu
|
|
| 678 |
"The addition should flow seamlessly with the existing content. "
|
| 679 |
"\n\nYOUR TASK:\n"
|
| 680 |
"1. Choose the ONE keyword that fits most naturally with the article's context\n"
|
| 681 |
-
"2. Create new content (1-3 sentences
|
| 682 |
-
"3.
|
| 683 |
"4. The keyword should be wrapped in an HTML link to the target URL\n"
|
| 684 |
f"5. Write in {language} and preserve special characters\n"
|
| 685 |
"\n\nReturn JSON with keys:\n"
|
| 686 |
"- 'chosen_keyword': the keyword you selected\n"
|
| 687 |
"- 'new_content': the HTML content with <a href> link\n"
|
| 688 |
-
"- '
|
| 689 |
-
"
|
| 690 |
)
|
| 691 |
|
| 692 |
user = {
|
|
@@ -697,7 +702,8 @@ def gpt_generate_content_with_keyword(source_blocks, keywords, target_url, langu
|
|
| 697 |
"requirements": {
|
| 698 |
"natural_flow": True,
|
| 699 |
"include_link": True,
|
| 700 |
-
"preserve_tone": True
|
|
|
|
| 701 |
}
|
| 702 |
}
|
| 703 |
|
|
@@ -805,7 +811,7 @@ def run_tool(source_url, target_url, anchor_text, smart_rewrite, plain_text, sug
|
|
| 805 |
|
| 806 |
if alt_content:
|
| 807 |
# Parse if there's position information
|
| 808 |
-
if "[Insert after
|
| 809 |
parts = alt_content.split("\n\n", 1)
|
| 810 |
position_info = parts[0] if len(parts) > 0 else ""
|
| 811 |
actual_content = parts[1] if len(parts) > 1 else alt_content
|
|
@@ -820,7 +826,8 @@ def run_tool(source_url, target_url, anchor_text, smart_rewrite, plain_text, sug
|
|
| 820 |
result += f"\n\n{'='*50}\n\n"
|
| 821 |
result += f"π Result 2 - Suggested new content to add:\n"
|
| 822 |
result += f"π‘ Using keyword: '{alt_anchor}'\n"
|
| 823 |
-
if position_info:
|
|
|
|
| 824 |
result += f"π {position_info}\n"
|
| 825 |
result += f"\n{alt_output}"
|
| 826 |
|
|
|
|
| 306 |
# Return in format compatible with existing code
|
| 307 |
chosen_keyword = result.get("chosen_keyword", keywords[0] if keywords else original_anchor)
|
| 308 |
new_content = result.get("new_content", "")
|
| 309 |
+
insert_after_sentence = result.get("insert_after_sentence", "")
|
|
|
|
| 310 |
|
| 311 |
# Format the response for compatibility
|
| 312 |
+
# Truncate the sentence for display if it's too long
|
| 313 |
+
if insert_after_sentence:
|
| 314 |
+
if len(insert_after_sentence) > 100:
|
| 315 |
+
position_text = f"[Insert after: ...{insert_after_sentence[-80:]}]"
|
| 316 |
+
else:
|
| 317 |
+
position_text = f"[Insert after: {insert_after_sentence}]"
|
| 318 |
+
else:
|
| 319 |
+
position_text = ""
|
| 320 |
|
| 321 |
+
return chosen_keyword, f"{position_text}\n\n{new_content}" if position_text else new_content
|
| 322 |
|
| 323 |
except Exception as e:
|
| 324 |
print(f"[Alternative] Critical error: {e}")
|
|
|
|
| 683 |
"The addition should flow seamlessly with the existing content. "
|
| 684 |
"\n\nYOUR TASK:\n"
|
| 685 |
"1. Choose the ONE keyword that fits most naturally with the article's context\n"
|
| 686 |
+
"2. Create new content (1-3 sentences) that naturally includes this keyword\n"
|
| 687 |
+
"3. Identify the EXACT sentence after which this content should be inserted\n"
|
| 688 |
"4. The keyword should be wrapped in an HTML link to the target URL\n"
|
| 689 |
f"5. Write in {language} and preserve special characters\n"
|
| 690 |
"\n\nReturn JSON with keys:\n"
|
| 691 |
"- 'chosen_keyword': the keyword you selected\n"
|
| 692 |
"- 'new_content': the HTML content with <a href> link\n"
|
| 693 |
+
"- 'insert_after_sentence': the exact sentence from the article after which to insert the new content (copy it exactly)\n"
|
| 694 |
+
"DO NOT include 'reasoning' or any explanations"
|
| 695 |
)
|
| 696 |
|
| 697 |
user = {
|
|
|
|
| 702 |
"requirements": {
|
| 703 |
"natural_flow": True,
|
| 704 |
"include_link": True,
|
| 705 |
+
"preserve_tone": True,
|
| 706 |
+
"no_explanations": True
|
| 707 |
}
|
| 708 |
}
|
| 709 |
|
|
|
|
| 811 |
|
| 812 |
if alt_content:
|
| 813 |
# Parse if there's position information
|
| 814 |
+
if "[Insert after:" in alt_content:
|
| 815 |
parts = alt_content.split("\n\n", 1)
|
| 816 |
position_info = parts[0] if len(parts) > 0 else ""
|
| 817 |
actual_content = parts[1] if len(parts) > 1 else alt_content
|
|
|
|
| 826 |
result += f"\n\n{'='*50}\n\n"
|
| 827 |
result += f"π Result 2 - Suggested new content to add:\n"
|
| 828 |
result += f"π‘ Using keyword: '{alt_anchor}'\n"
|
| 829 |
+
if position_info and "[Insert after:" in position_info:
|
| 830 |
+
# Extract and format the position info nicely
|
| 831 |
result += f"π {position_info}\n"
|
| 832 |
result += f"\n{alt_output}"
|
| 833 |
|