Фиксируем состояние

This commit is contained in:
2026-03-12 20:40:29 +03:00
parent 095d354112
commit b1f825e6b9
220 changed files with 23993 additions and 92568 deletions

View File

@@ -1,5 +1,7 @@
from __future__ import annotations
import math
from app.modules.agent.code_qa_runtime import CodeQaRuntimeExecutor
from app.modules.agent.code_qa_runtime.repo_context import CodeQaRepoContextFactory
from app.modules.agent.code_qa_runtime.retrieval_adapter import CodeQaRetrievalAdapter
@@ -87,6 +89,7 @@ class AgentRuntimeAdapter:
"diagnostics": result.diagnostics.model_dump(mode="json"),
"rag_rows": list(result.retrieval_result.raw_rows) if result.retrieval_result else [],
"validation": result.validation.model_dump(mode="json"),
"token_usage": _token_usage(result),
"steps": list(result.runtime_trace),
}
return ExecutionPayload(actual=actual, details=details)
@@ -169,3 +172,15 @@ def _answer_status(answer_mode: str, llm_used: bool) -> str:
if answer_mode == "normal" and llm_used:
return "answered"
return answer_mode
def _token_usage(result) -> dict:
draft = result.draft_answer
if draft is None:
return {}
system_prompt = PromptLoader().load(draft.prompt_name)
tokens_in_estimate = max(1, int(math.ceil((len(system_prompt or "") + len(draft.prompt_payload or "")) / 4)))
return {
"prompt_name": draft.prompt_name,
"tokens_in_estimate": tokens_in_estimate,
}