Summarize / groqSummarizer.py
IsakNordgren's picture
fler exempel och förbättrad prompt. Testar steg-för-steg-prompting
a7a9d9e
# groq
from groq import Groq
import os
from dotenv import load_dotenv
from prompts import systemPrompt
class GroqSummarizer():
def __init__(self):
self.systemPrompt = systemPrompt
self.client = self.load_groq()
def load_groq(self):
load_dotenv()
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
client = Groq(
api_key=GROQ_API_KEY
)
return client
def summarize(self, text):
chat_completion = self.client.chat.completions.create(
messages=[
{
"role": "system",
'content': self.systemPrompt
},
{
"role": "user",
"content": "\"\"\"" + text + "\"\"\"",
}
],
model="llama3-70b-8192",
)
print(chat_completion.choices[0].message.content)
return chat_completion.choices[0].message.content