- 为 pam_deploy_graph 生产代码补充中文模块、类、函数/方法文档字符串 - 将原有英文说明和主要英文异常提示改为中文 - 新增当前整体逻辑结构流程图文档,覆盖模块结构、执行链路、action 路由、人工确认和 checkpoint 续跑 - 新增 Linux 自带运行环境打包脚本,使用 PyInstaller 生成解压即用目录和 tar.gz - 新增 Linux 打包说明,包含构建命令、运行方式、依赖说明和包大小评估 - 同步 README,补充流程图、打包方式、产物路径和大小预估 - 更新相关测试断言以匹配中文错误提示
41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
"""供 CLI 和外部嵌入使用的 LLM client 工厂。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
|
|
from .base import LlmClient
|
|
from .openai_compatible import OpenAICompatibleLlmClient
|
|
from .rule_based import RuleBasedLlmClient
|
|
|
|
|
|
def build_llm_client(
|
|
*,
|
|
base_url: str | None = None,
|
|
api_key: str | None = None,
|
|
model: str | None = None,
|
|
) -> LlmClient:
|
|
"""根据显式参数或环境变量构造 LLM client。"""
|
|
actual_base_url = base_url or os.getenv("PAM_LLM_BASE_URL", "")
|
|
actual_api_key = api_key or os.getenv("PAM_LLM_API_KEY", "")
|
|
actual_model = model or os.getenv("PAM_LLM_MODEL", "")
|
|
|
|
if not actual_base_url and not actual_api_key and not actual_model:
|
|
return RuleBasedLlmClient()
|
|
|
|
missing = []
|
|
if not actual_base_url:
|
|
missing.append("base_url")
|
|
if not actual_api_key:
|
|
missing.append("api_key")
|
|
if not actual_model:
|
|
missing.append("model")
|
|
if missing:
|
|
raise ValueError(f"LLM 配置不完整,缺少: {', '.join(missing)}")
|
|
|
|
return OpenAICompatibleLlmClient(
|
|
base_url=actual_base_url,
|
|
api_key=actual_api_key,
|
|
model=actual_model,
|
|
)
|