fix: site/ with __init__.py — proper Python package, no stdlib conflict
Deploy contracts-flask / validate (push) Successful in 0s
Deploy contracts-flask / validate (push) Successful in 0s
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
"""LLM service — call LLM API with optional DI."""
|
||||
import os, json
|
||||
|
||||
LLM_URL = "https://api.aillm.ru/v1/chat/completions"
|
||||
LLM_KEY = os.environ.get("LLM_KEY") or os.environ.get("LLM_API_KEY", "")
|
||||
LLM_MODEL = "gpt-oss-120b"
|
||||
|
||||
# Ленивый singleton — обратная совместимость
|
||||
_llm_client = None
|
||||
|
||||
|
||||
def _get_default_client():
|
||||
global _llm_client
|
||||
if _llm_client is None:
|
||||
from site.services.llm_client import HttpxLLMClient
|
||||
_llm_client = HttpxLLMClient(url=LLM_URL, key=LLM_KEY, model=LLM_MODEL)
|
||||
return _llm_client
|
||||
|
||||
|
||||
def call_llm(current_spec, doc_text, build_prompt_fn, llm_client=None):
|
||||
"""Call LLM. Returns (parsed_result, prompt_id).
|
||||
llm_client: LLMClient (optional). Default — HttpxLLMClient (prod).
|
||||
"""
|
||||
if llm_client is None:
|
||||
llm_client = _get_default_client()
|
||||
|
||||
prompt, prompt_id = build_prompt_fn(current_spec, doc_text)
|
||||
raw_text = llm_client.complete(prompt)
|
||||
|
||||
json_text = raw_text
|
||||
if "```json" in json_text:
|
||||
json_text = json_text.split("```json")[1].split("```")[0]
|
||||
elif "```" in json_text:
|
||||
json_text = json_text.split("```")[1].split("```")[0]
|
||||
return json.loads(json_text.strip()), prompt_id
|
||||
Reference in New Issue
Block a user