feat(backend): add centralized llm query function

This commit is contained in:
Steven Tischer
2026-05-28 16:41:26 +02:00
parent 28c79e113a
commit afd414e004
+31
View File
@@ -0,0 +1,31 @@
from typing import Any
import httpx
from .. import config
def call(
system_prompt: str,
user_prompt: str,
model: str = None,
stream: bool = False
) -> str:
headers = {
"Authorization": f"Bearer {config.settings.llm_api_token}",
"Content-Type": "application/json"
}
if model is None:
model = config.settings.llm_model
payload = {
"model": model,
"prompt": f"{system_prompt}\n{user_prompt}",
"stream": stream
}
with httpx.Client(timeout=30.0) as client:
response = client.post(config.settings.llm_api_url, json=payload, headers=headers)
response.raise_for_status()
data = response.json()
return data.get("response", "")