OpenAICompatibleLlmClient 新增 chat_stream(),使用 OpenAI-compatible /chat/completions 的 stream: true。 chat 普通对话现在优先流式分段输出;流式不可用或服务端不返回 SSE 时,会提示并自动 fallback 到非流式 chat()。 普通 chat 和 log analyze 都会过滤 think 内容,并且日志只记录过滤后的摘要。 更新了 chat/log 分析提示词,明确禁止输出 think/内部思考。 同步 README、打包 README、run.sh --help。 补充了过滤器、OpenAI 流式、CLI fallback、日志分析过滤等测试。
70 lines
2.0 KiB
Python
70 lines
2.0 KiB
Python
"""LLM client 需要实现的共享协议。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable
|
|
from typing import Any, Protocol
|
|
|
|
from pam_deploy_graph.models import (
|
|
ActionResult,
|
|
ExecutionStrategy,
|
|
LlmActionAnalysis,
|
|
LlmDeployPlan,
|
|
LlmIntentResult,
|
|
LlmParamResult,
|
|
LlmSingleActionProposal,
|
|
)
|
|
|
|
|
|
class LlmClient(Protocol):
|
|
"""Agent 使用的最小 LLM 能力接口。"""
|
|
|
|
def understand_request(self, text: str) -> LlmIntentResult:
|
|
"""识别用户自然语言请求的意图。"""
|
|
...
|
|
|
|
def extract_params(self, text: str, base_params: dict[str, Any] | None = None) -> LlmParamResult:
|
|
"""从自然语言中抽取部署参数。"""
|
|
...
|
|
|
|
def generate_plan(
|
|
self,
|
|
*,
|
|
params: dict[str, Any],
|
|
intent: str,
|
|
strategy: ExecutionStrategy,
|
|
) -> LlmDeployPlan:
|
|
"""根据参数和意图生成部署计划。"""
|
|
...
|
|
|
|
def analyze_action_result(
|
|
self,
|
|
*,
|
|
action: str,
|
|
result: ActionResult,
|
|
) -> LlmActionAnalysis:
|
|
"""分析 action 执行结果,并给出是否允许继续执行的建议。"""
|
|
...
|
|
|
|
def chat(self, text: str, context: dict[str, Any] | None = None) -> str:
|
|
"""进行普通自然语言对话,不触发部署 workflow。"""
|
|
...
|
|
|
|
def chat_stream(self, text: str, context: dict[str, Any] | None = None) -> Iterable[str]:
|
|
"""流式进行普通自然语言对话,不触发部署 workflow。"""
|
|
...
|
|
|
|
def analyze_log(self, log_text: str, question: str | None = None, source_path: str = "") -> str:
|
|
"""分析日志文本并给出异常摘要、原因和建议。"""
|
|
...
|
|
|
|
def propose_action(
|
|
self,
|
|
text: str,
|
|
allowed_actions: list[str],
|
|
params: dict[str, Any],
|
|
state_summary: dict[str, Any] | None = None,
|
|
) -> LlmSingleActionProposal:
|
|
"""把自然语言解析为单次 action 调用建议。"""
|
|
...
|