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