Spaces:
Sleeping
Sleeping
Download model_service.py from aneesqumar/TranslatorWithThreeFiles: direct link, hf CLI and curl.
- Browser
- Download file 660 Bytes
-
https://huggingface.co/spaces/aneesqumar/TranslatorWithThreeFiles/resolve/main/model_service.py
- Command line
-
hf download hf://spaces/aneesqumar/TranslatorWithThreeFiles/model_service.py
-
curl -L -o model_service.py https://huggingface.co/spaces/aneesqumar/TranslatorWithThreeFiles/resolve/main/model_service.py
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 | |