diff --git a/rag/functions/soma_evaluate.py b/rag/functions/soma_evaluate.py index 364222f..a752ae6 100644 --- a/rag/functions/soma_evaluate.py +++ b/rag/functions/soma_evaluate.py @@ -6,7 +6,7 @@ SOMA-анализ (LLM-as-judge) для оценки качества ответ import json import logging -from typing import Dict, Any, Optional +from typing import Dict, Any from rag.services.giga_client import GigaClient from rag.config_models import AppConfig @@ -61,15 +61,13 @@ async def soma_evaluate( default_result["error"] = "Отсутствует промпт soma_evaluate" return default_result - # Формируем полный промпт full_prompt = prompt_template.format( query=query, context=context[:3000] if context else "Нет контекста", answer=answer, ) - # Параметры из конфига (можно сделать отдельную секцию) - temperature = getattr(config, 'soma_temperature', 0.1) # низкая для детерминизма + temperature = getattr(config, 'soma_temperature', 0.1) timeout = getattr(config, 'soma_timeout', 30) try: @@ -79,14 +77,12 @@ async def soma_evaluate( system_prompt=None, file_id=None, temperature=temperature, - timeout=timeout, # нужно добавить timeout в GigaClient.chat (если нет, игнорировать) + timeout=timeout, ) - # Ожидаем JSON data = json.loads(response.strip()) scores = data.get("scores", {}) feedback = data.get("feedback", "") - # Приводим оценки к числам for key in scores: try: scores[key] = float(scores[key]) @@ -94,7 +90,6 @@ async def soma_evaluate( scores[key] = 3.0 overall = sum(scores.values()) / len(scores) if scores else 3.0 - # Порог можно задать в конфиге threshold = getattr(config, 'soma_threshold', 3.5) verdict = "pass" if overall >= threshold else "fail"