Coverage for providers/base.py: 100%

1 from abc import ABC, abstractmethod

2 from dataclasses import dataclass, field

3

4

5@dataclass

6 class ToolCall:

7 id: str

8 name: str

9 arguments: str # JSON 字符串

10 thought_signature: str | None = None # base64 编码，Vertex AI thinking model 专用

11

12

13@dataclass

14 class LLMResponse:

15 content: str # 文本回复，无工具调用时有值

16 tool_calls: list[ToolCall] = field(default_factory=list)

17 finish_reason: str = "stop" # stop | tool_calls | length

18 prompt_tokens: int = 0

19 completion_tokens: int = 0

20 total_tokens: int = 0

21 raw: object = None # 原始响应对象，供需要时使用

22

23

24 class LLMProvider(ABC):

25

26 @abstractmethod

27 def chat(self, messages: list[dict], tools: list[dict] | None = None) -> LLMResponse:

28 """发送消息，返回统一格式的响应。"""

29 ...