from groq import Groq import os # Initialize Groq client api_key = os.getenv("GROQ_API_KEY") client = Groq(api_key=api_key) def summarize_topic(topic): if not topic.strip(): return "Please provide a valid topic to generate a summary." messages = [ { "role": "system", "content": "You are a summarizer. Your task is to provide a clear and concise summary of any given topic." }, { "role": "user", "content": f"{topic}" } ] completion = client.chat.completions.create( model="llama3-70b-8192", messages=messages, temperature=0.7, max_tokens=200, top_p=1, stream=True, stop=None, ) summary_content = "" for chunk in completion: summary_content += chunk.choices[0].delta.content or "" return summary_content