TranslatorWithThreeFiles / model_service.py
aneesqumar's picture
Create model_service.py
9cb862b verified
Raw
History Blame Contribute Delete
660 Bytes
import os
from groq import Groq
def get_client():
api_key = os.environ.get("GROQ_API_KEY")
if not api_key:
raise RuntimeError(
"GROQ_API_KEY is not set. Add it in Hugging Face Spaces → Settings → Secrets."
)
return Groq(api_key=api_key)
def ask_ai(question: str) -> str:
client = get_client()
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": question}
]
completion = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=messages
)
return completion.choices[0].message.content