Spaces:
Runtime error
Runtime error
Download app/llm.py from capcut8128/docs-qa-backend: direct link, hf CLI and curl.
- Browser
- Download file 795 Bytes
-
https://huggingface.co/spaces/capcut8128/docs-qa-backend/resolve/main/app/llm.py
- Command line
-
hf download hf://spaces/capcut8128/docs-qa-backend/app/llm.py
-
curl -L -o llm.py https://huggingface.co/spaces/capcut8128/docs-qa-backend/resolve/main/app/llm.py
795 Bytes
| """Thin wrapper around the Groq chat API.""" | |
| from functools import lru_cache | |
| from groq import Groq | |
| from .config import settings | |
| def _client() -> Groq: | |
| return Groq(api_key=settings.groq_api_key) | |
| def chat(messages: list[dict], max_tokens: int = 2048, temperature: float = 0.2) -> str: | |
| if not settings.groq_api_key: | |
| raise ValueError("GROQ_API_KEY is not set in .env") | |
| kwargs = dict( | |
| model=settings.llm_model, | |
| messages=messages, | |
| temperature=temperature, | |
| max_tokens=max_tokens, | |
| ) | |
| if "gpt-oss" in settings.llm_model: | |
| kwargs["extra_body"] = {"reasoning_effort": "low"} # faster, saves free-tier tokens | |
| resp = _client().chat.completions.create(**kwargs) | |
| return (resp.choices[0].message.content or "").strip() | |