INNER CODE UNIT · Python
_call
zachlagden/Pi-hole-Optimized-Blocklists · .github/triage/triage/ai_review.py:321
def _call(system: str, content: list[dict] | str, api_key: str, timeout: float = 240) -> str:
payload = {
"model": MODEL,
"temperature": 0.2,
"max_tokens": 6000,
"messages": [{"role": "system", "content": system}, {"role": "user", "content": content}],
}
response = httpx.post(API_URL, json=payload, headers={"Authorization": f"Bearer {api_key}"}, timeout=timeout)
response.raise_for_status()
choices = response.json().get("choices") or []
message = choices[0].get("message", {}).get("content") if choices else None
if not message:
raise ValueError("the API returned no message")
return str(message)
def _outer_object(text: str) -> dict:
start, end = text.find("{"), text.rfind("}")