feat: InferenceEngine chat/chat_structured 全流程 + 文档补丁(补丁1/2/3)
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from genesis.inference.types import TokenUsage
|
||||
|
||||
|
||||
class FakeLLMClient:
|
||||
"""可编程的假 LLM 客户端:记录调用,按脚本返回(离线)。"""
|
||||
|
||||
def __init__(self, script=None):
|
||||
# script: list[(status, content)];status: "ok" | "raise_timeout" | "raise_network" | "parse_fail"
|
||||
self.script = script or [("ok", "hello")]
|
||||
self.calls: list[dict] = []
|
||||
|
||||
def chat(self, *, model, messages, temperature, max_tokens):
|
||||
self.calls.append({"model": model, "messages": [m.content for m in messages]})
|
||||
status, content = self.script.pop(0)
|
||||
if status == "raise_timeout":
|
||||
from genesis.inference.exceptions import LLMTimeoutError
|
||||
|
||||
raise LLMTimeoutError("timeout")
|
||||
if status == "raise_network":
|
||||
from genesis.inference.exceptions import LLMNetworkError
|
||||
|
||||
raise LLMNetworkError("network")
|
||||
if status == "parse_fail":
|
||||
content = "NOT JSON"
|
||||
return content, TokenUsage(input_tokens=10, output_tokens=2)
|
||||
Reference in New Issue
Block a user