Spaces:
Sleeping
Sleeping
File size: 660 Bytes
9cb862b | 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 | 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
|