Deploy contracts-flask / validate (push) Canceled after 0s
- #1 process.py: target_id→target_hash (UPDATE/DELETE больше не UNRESOLVED) - #2 Dockerfile: COPY upload - #3 prompts.py: убран created_by из SELECT - #4 prompts_bp.py: save_new_version/delete_prompt - #5 llm.py/classify.py: LLM-конфиг из config.py - #6/#7 compare.js: escHtml (XSS) - #8-#10: комментарии + мёртвый gen_random_uuid
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
"""LLM service — call LLM API with optional DI."""
|
|
import json
|
|
|
|
from config import LLM_URL, LLM_KEY, LLM_MODEL
|
|
|
|
# Ленивый singleton — обратная совместимость
|
|
_llm_client = None
|
|
|
|
|
|
def _get_default_client():
|
|
global _llm_client
|
|
if _llm_client is None:
|
|
from 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
|