Skip to content

Commit b4935f2

Browse files
committed
fix: remove unwanted quotes from translation output and simplify prompts
1 parent 8e154ca commit b4935f2

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

app/summarizer.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def setup_argparse():
1515
"-u", "--url", required=True, help="URL of the document to summarize"
1616
)
1717
parser.add_argument(
18-
"-l", "--language",
18+
"-t", "--translate",
1919
help="Target language for translation (if specified, translation is enabled)"
2020
)
2121
return parser.parse_args()
@@ -30,22 +30,11 @@ def load_document(url):
3030
def setup_summarization_chain():
3131
"""Setup the summarization chain with a prompt template and ChatOllama."""
3232
prompt_template = PromptTemplate(
33-
template="""As a professional summarizer, create a detailed and comprehensive summary of the provided text, be it an article, post, conversation, or passage, while adhering to these guidelines:
34-
1. Craft a summary that is detailed, thorough, in-depth, and complex, while maintaining clarity.
33+
template="""Create a detailed and comprehensive summary of the following text. Provide only the summary without any headers, quotes, or additional text:
3534
36-
2. Incorporate main ideas and essential information, eliminating extraneous language and focusing on critical aspects.
35+
{text}
3736
38-
3. Rely strictly on the provided text, without including external information.
39-
40-
4. Format the summary in paragraph form for easy understanding.
41-
42-
5.Conclude your notes with [End of Notes, Message #X] to indicate completion, where "X" represents the total number of messages that I have sent. In other words, include a message counter where you start with #1 and add 1 to the message counter every time I send a message.
43-
44-
By following this optimized prompt, you will generate an effective summary that encapsulates the essence of the given text in a clear, detailed, and reader-friendly manner. Optimize output as markdown file.
45-
46-
"{text}"
47-
48-
DETAILED SUMMARY:""",
37+
SUMMARY:""",
4938
input_variables=["text"],
5039
)
5140

@@ -57,11 +46,11 @@ def setup_summarization_chain():
5746
def setup_translation_chain(target_language="Spanish"):
5847
"""Setup the translation chain with a prompt template and ChatOllama."""
5948
prompt_template = PromptTemplate(
60-
template="""As a professional translator, provide a detailed and comprehensive translation of the provided text into {target_language}, ensuring that the translation is accurate, coherent, and faithful to the original text.
49+
template="""Translate the following text into {target_language}. Provide only the translation without any quotes, headers, or additional text. The output should be clean and direct:
6150
62-
"{text}"
51+
{text}
6352
64-
DETAILED TRANSLATION:""",
53+
TRANSLATION:""",
6554
input_variables=["text", "target_language"],
6655
)
6756

@@ -92,12 +81,12 @@ def main():
9281
print()
9382

9483
# Translate if language is specified
95-
if args.language:
84+
if args.translate:
9685
print("=" * 60)
97-
print(f"TRANSLATION TO {args.language.upper()}")
86+
print(f"TRANSLATION TO {args.translate.upper()}")
9887
print("=" * 60)
9988
try:
100-
translation = translate_text(summary, args.language)
89+
translation = translate_text(summary, args.translate)
10190
print(translation)
10291
except Exception as e:
10392
print(f"Translation failed: {e}")

0 commit comments

Comments
 (0)