- 新增 OpenAI-compatible LLM client,支持 base_url、api_key、model 配置 - 固化意图识别、参数抽取、部署计划生成的结构化 JSON 提示词 - 增加 MCP client 配置读取和真实 session 接入说明 - 实现 checkpoint 自动保存、resume 断点续跑和已完成步骤跳过 - 实现人工确认流程,支持失败 IP 回滚 approve/reject - 新增 chat 常驻式 CLI 对话框,支持自然语言分析、参数设置、执行确认、状态查看、回滚确认和续跑 - 同步 README,补充 LLM、MCP、checkpoint、confirm/resume、chat 使用方式 - 增加相关单元测试,覆盖 LLM client、MCP 配置、确认/续跑和交互式 CLI
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
"""LLM client factory for CLI and embedding code."""
|
|
|
|
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:
|
|
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"Incomplete LLM config: missing {', '.join(missing)}")
|
|
|
|
return OpenAICompatibleLlmClient(
|
|
base_url=actual_base_url,
|
|
api_key=actual_api_key,
|
|
model=actual_model,
|
|
)
|