feat(api): 统一 LLM JSON 调用层 llm_json_call,按域 Schema 迁移 chat/memoir agents

This commit is contained in:
Kevin
2026-04-03 13:34:27 +08:00
parent 41518bda11
commit 43d1689e9c
28 changed files with 1006 additions and 352 deletions

View File

@@ -14,13 +14,15 @@ from dataclasses import dataclass
from typing import Any
from app.agents.memoir.prompts import get_chapter_classification_json_prompt
from app.agents.memoir.schemas import ClassificationOutput
from app.agents.stage_constants import (
CHAPTER_CATEGORIES,
STAGE_KEYWORD_WEIGHTS,
STAGE_TO_DEFAULT_CATEGORY,
)
from app.core.config import settings
from app.core.json_utils import extract_json_payload
from app.core.langchain_llm import invoke_json_object
from app.core.llm_call import llm_json_call
from app.core.logging import get_logger
logger = get_logger(__name__)
@@ -135,13 +137,14 @@ class ClassificationAgent:
if llm:
try:
prompt = get_chapter_classification_json_prompt(text)
raw = invoke_json_object(
out = llm_json_call(
llm,
prompt,
max_tokens=256,
ClassificationOutput,
max_tokens=settings.memoir_classification_max_tokens,
agent="ClassificationAgent.classify",
)
category = _parse_category_from_llm_response(raw)
category = _normalize_llm_category(out.category)
if category == "none":
logger.info(
"event=chapter_classification_summary_fallback reason=llm_none "