hub-gif 52c9dc1697 refactor(pipeline/llm): 文本大模型工厂与 OpenAI 兼容适配器
新增 providers 包:协议、Crawler 网关适配器、output 去围栏、token 启发式与工厂;llm_client 与 keyword_suggest 走统一入口。未改各 generate_* 提示词。补充 MA_LLM_TEXT_PROVIDER 说明至 .env.example。

Made-with: Cursor
2026-04-27 09:56:21 +08:00

31 lines
1.0 KiB
Python

"""竞品报告 LLM 调用:经 `providers` 工厂选择后端,并统一对输出做去围栏等归一化。"""
from __future__ import annotations
from .providers.factory import get_text_llm
from .providers.output_normalize import strip_outer_markdown_fence
def call_llm(
system_prompt: str,
user_prompt: str,
*,
temperature: float | None = None,
) -> str:
raw = get_text_llm().complete_text(
system_prompt,
user_prompt,
temperature=temperature,
)
return strip_outer_markdown_fence(raw)
def estimate_chat_input_tokens(system_prompt: str, user_prompt: str) -> int:
"""与当前所选文本后端的预检一致;默认与 ``AI_crawler`` 的保守估算同口径。"""
return get_text_llm().estimate_input_tokens(system_prompt, user_prompt)
def llm_context_window_size() -> int:
"""与当前所选后端的上下文上限一致;默认与 ``AI_crawler.chat_completion_text`` 使用的环境变量一致。"""
return get_text_llm().context_window_tokens()