47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
import json
|
|
import time
|
|
|
|
from utils.langgraph_agent import RULES, run_agent
|
|
|
|
|
|
async def evaluate_servico(servico: dict, guia: dict, file_content: str) -> dict:
|
|
codigo_servico_raw = str(servico.get("codigoServico", ""))
|
|
code = "".join(c for c in codigo_servico_raw if c.isdigit())
|
|
|
|
if code not in RULES:
|
|
return {
|
|
"codigoServico": codigo_servico_raw,
|
|
"resultado": "SKIPPED",
|
|
"motivo": f"Codigo '{code}' nao encontrado nas regras",
|
|
"agentOutput": "",
|
|
"tempoAgentSegundos": 0,
|
|
}
|
|
|
|
query_data = {
|
|
"atendimento": guia.get("atendimento", {}),
|
|
"guia": guia.get("guia", {}),
|
|
"servico": servico,
|
|
"historico": guia.get("historico", {}),
|
|
}
|
|
query = json.dumps(query_data, indent=2, ensure_ascii=False)
|
|
|
|
t0 = time.time()
|
|
try:
|
|
result = await run_agent(query, code, file_content)
|
|
agent_output = result["response"]
|
|
input_tokens = result["input_tokens"]
|
|
output_tokens = result["output_tokens"]
|
|
except Exception as e:
|
|
agent_output = f"ERROR: {str(e)}"
|
|
input_tokens = 0
|
|
output_tokens = 0
|
|
|
|
return {
|
|
"codigoServico": codigo_servico_raw,
|
|
"resultado": "Aprovado" if "".join(c for c in agent_output.lower() if c.isalpha()).startswith("aprov") else "Reprovado",
|
|
"agentOutput": agent_output,
|
|
"input_tokens": input_tokens,
|
|
"output_tokens": output_tokens,
|
|
"tempoAgentSegundos": round(time.time() - t0, 2),
|
|
}
|