From e7d61b651583962cb67c02e013a1f883f152c203 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Thu, 5 Jun 2025 18:29:10 +0200 Subject: [PATCH] Add function to generate new summary for improved title --- prophet/app.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/prophet/app.py b/prophet/app.py index df41e6b..abe3ed0 100644 --- a/prophet/app.py +++ b/prophet/app.py @@ -116,6 +116,25 @@ def improve_with_groq(original_content: str) -> str: return winner_str +def rewrite_summary_with_groq(orig: Original, improved_title: str) -> str: + client = Groq(api_key=os.getenv("GROQ_API_KEY", "NO_API_KEY_FOUND")) + + summary = client.chat.completions.create( + messages=[ + { + "role": "user", + "content": f"Below there is an original title and an original summary. Then follows an improved title. Write an improved summary based on the original summary which fits to the improved title. Only output the improved summary.\n\nTitle:{orig.title}\nSummary:{orig.summary}\n---\nTitle:{improved_title}\nSummary:", + } + ], + model="llama-3.3-70b-versatile", + ) + summary_str = summary.choices[0].message.content + if not summary_str: + raise ValueError + print("Improved summary", summary_str) + return summary_str + + app = FastAPI() origins = [ @@ -142,8 +161,7 @@ def start() -> None: orig = grab_latest_originals() improvements = [ - Improvement(original=o, title="hithere", summary="alongsummary") - for o in orig + Improvement(original=o, title="hithere", summary="alongsummary") for o in orig ] save_new_improvements(improvements)