Spaces:
Sleeping
Sleeping
Create groq_llm.py
Browse files- groq_llm.py +18 -0
groq_llm.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# groq_llm.py
|
| 2 |
+
import openai
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
openai.api_key = os.getenv("GROQ_API_KEY")
|
| 6 |
+
|
| 7 |
+
def get_groq_response(user_input, system_prompt, language="English"):
|
| 8 |
+
messages = [
|
| 9 |
+
{"role": "system", "content": f"You are an AI assistant. Respond in {language}. {system_prompt}"},
|
| 10 |
+
{"role": "user", "content": user_input}
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
response = openai.ChatCompletion.create(
|
| 14 |
+
model="llama3-70b-8192",
|
| 15 |
+
messages=messages,
|
| 16 |
+
temperature=0.7
|
| 17 |
+
)
|
| 18 |
+
return response.choices[0].message.content.strip()
|