-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsummarizer.py
More file actions
29 lines (23 loc) · 871 Bytes
/
summarizer.py
File metadata and controls
29 lines (23 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
from dotenv import load_dotenv
from groq import Groq
load_dotenv()
client = Groq(api_key=os.getenv("GROQ_API_KEY"))
MODEL = "meta-llama/llama-4-scout-17b-16e-instruct" # You can change this to any Groq-supported model
async def summarize_text(text: str) -> str:
prompt = (
"You are a helpful assistant that summarizes text clearly and concisely.\n\n"
f"Text to summarize:\n{text}\n\nSummary:"
)
completion = client.chat.completions.create(
model=MODEL,
messages=[
{"role": "system", "content": "You summarize texts into clear, short bullet points."},
{"role": "user", "content": prompt}
],
temperature=0.5,
max_tokens=512,
top_p=1,
stream=False, # We keep this False for simplicity
)
return completion.choices[0].message.content.strip()