feat(backend): add centralized llm query function
This commit is contained in:
@@ -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", "")
|
||||
Reference in New Issue
Block a user