debug: расширенный вывод в /test debug (hash + края ключа)

This commit is contained in:
2026-06-14 07:57:06 +04:00
parent 5dd06c6dce
commit 667cd0c306
+14 -4
View File
@@ -102,11 +102,16 @@ def test():
return jsonify(result)
if action == "llm":
# Тест LLM: отправить промпт → получить ответ
prompt = data.get("prompt", "Скажи 'Привет, мир!'")
model = data.get("model") # None = default
max_tokens = data.get("max_tokens", 500)
model = data.get("model")
max_tokens = data.get("max_tokens", 100)
result = llm_client.ask(prompt, model=model, max_tokens=max_tokens)
# добавим отладочную информацию
result["_debug"] = {
"key_prefix": os.environ.get("LLM_API_KEY", "")[:6] + "...",
"key_len": len(os.environ.get("LLM_API_KEY", "")),
"url": os.environ.get("LLM_API_URL", llm_client.DEFAULT_URL),
}
if "error" in result:
return jsonify(result), 500
return jsonify(result)
@@ -114,10 +119,15 @@ def test():
if action == "debug":
# Показать переменные окружения (с маскировкой ключей)
import os as _os
import hashlib
vars_info = {}
for k, v in sorted(_os.environ.items()):
if any(x in k.upper() for x in ("KEY", "PASS", "SECRET", "TOKEN")):
vars_info[k] = f"{v[:6]}... (len={len(v)})" if v else "(empty)"
if v:
h = hashlib.sha256(v.encode()).hexdigest()
vars_info[k] = f"{v[:4]}...{v[-4:]} (len={len(v)}, hash={h[:8]})"
else:
vars_info[k] = "(empty)"
elif any(x in k.upper() for x in ("DB_", "LLM_", "FLASK", "PORT")):
vars_info[k] = v
# добавим проверку h2 и httpx