fix: убрать хардкод API-ключа (chat.cfm), verify=True (llm.py), отвязать llm_prompt от Lucee

This commit is contained in:
2026-06-27 13:06:21 +04:00
parent 465be4ca04
commit a474b4324b
3 changed files with 14 additions and 26 deletions
+7 -9
View File
@@ -15,14 +15,12 @@
<cfelseif NOT len(form.question)>
<cfset result.error = "question required (POST field)">
<cfelse>
<!--- Собрать все spec_rows --->
<!--- Собрать строки текущей спецификации --->
<cfquery name="rowsData" datasource="baza">
SELECT d.filename, sr.row_num, sr.name, sr.price, sr.qty, sr.sum, sr.date_start
FROM spec_rows sr
JOIN supplements s ON sr.supplement_id = s.id
JOIN documents d ON s.document_id = d.id
WHERE s.contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
ORDER BY s.created_at, sr.row_num
SELECT name, price, qty, sum, date_start
FROM spec_current
WHERE contract_id = <cfqueryparam value="#url.contract_id#" cfsqltype="cf_sql_varchar">
ORDER BY name
</cfquery>
<cfif rowsData.recordCount EQ 0>
@@ -32,7 +30,7 @@
<cfset contextLines = []>
<cfloop query="rowsData">
<cfset arrayAppend(contextLines,
"[" & rowsData.filename & "] строка " & rowsData.row_num & ": " & rowsData.name &
rowsData.name &
" | цена=" & rowsData.price & " | объём=" & rowsData.qty &
" | сумма=" & rowsData.sum & " | начало=" & rowsData.date_start
)>
@@ -50,7 +48,7 @@
Ответь кратко и по делу, опираясь ТОЛЬКО на данные выше. Если данных недостаточно — скажи об этом.">
<!--- Вызов LLM --->
<cfset apiKey = "sk-ucI5YvOticoOQ9Kuj5K9mQ">
<cfset apiKey = createObject("java", "java.lang.System").getenv("LLM_KEY")>
<cfset llmPayload = {
"model": "gpt-oss-120b",
"messages": [{"role": "user", "content": prompt}],
+6 -16
View File
@@ -1,10 +1,8 @@
"""llm_prompt.py — Формирование промпта для LLM-анализа ДС.
Читает активный промпт из БД (через Lucee API). При ошибке — fallback на хардкод."""
Читает активный промпт из БД напрямую (db.prompts). При ошибке — fallback на хардкод."""
import os
import httpx
LUCEE_URL = os.environ.get("LUCEE_URL", "https://contractor.luceek8s.dev.nubes.ru")
from db import prompts as db_prompts
# ── Fallback-промпты (если БД недоступна) ──────────────────────
@@ -178,19 +176,11 @@ EDGE-CASES:
def _fetch_prompt(role: str) -> dict | None:
"""Получить активный промпт из БД. Возвращает {id, body} или None."""
"""Получить активный промпт из БД напрямую (а не через Lucee HTTP)."""
try:
with httpx.Client(http2=True, timeout=10) as client:
resp = client.get(
f"{LUCEE_URL}/prompt.cfm",
params={"action": "get_active", "role": role},
)
resp.raise_for_status()
data = resp.json()
# Lucee serializeJSON → UPPERCASE keys, normalize to lowercase
data = {k.lower(): v for k, v in data.items()}
if data.get("ok") and data.get("body"):
return {"id": data.get("id", ""), "body": data["body"]}
row = db_prompts.get_active(role)
if row and row.get("body"):
return {"id": row.get("id", ""), "body": row["body"]}
except Exception:
pass
return None
+1 -1
View File
@@ -16,7 +16,7 @@ def call_llm(current_spec, doc_text, build_prompt_fn):
"max_tokens": 8000,
"temperature": 0.1,
}
with httpx.Client(http2=True, timeout=120, verify=False) as client:
with httpx.Client(http2=True, timeout=120, verify=True) as client:
resp = client.post(
LLM_URL,
json=payload,