Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /Mother-AI-OS_mother /mother /llm /response.py
| """Unified response types for LLM providers.""" | |
| from dataclasses import dataclass, field | |
| from typing import Any | |
| class ToolCall: | |
| """Represents a tool call from the LLM.""" | |
| id: str | |
| name: str | |
| arguments: dict[str, Any] | |
| class ToolResult: | |
| """Represents the result of a tool execution.""" | |
| tool_call_id: str | |
| content: str | list[dict[str, Any]] | |
| is_error: bool = False | |
| class Usage: | |
| """Token usage statistics.""" | |
| input_tokens: int = 0 | |
| output_tokens: int = 0 | |
| def total_tokens(self) -> int: | |
| """Total tokens used.""" | |
| return self.input_tokens + self.output_tokens | |
| class LLMResponse: | |
| """Unified response from any LLM provider.""" | |
| text: str | None = None | |
| tool_calls: list[ToolCall] = field(default_factory=list) | |
| stop_reason: str | None = None | |
| usage: dict[str, int] | Usage = field(default_factory=dict) | |
| raw_response: Any = None | |
| def has_tool_calls(self) -> bool: | |
| """Check if response contains tool calls.""" | |
| return len(self.tool_calls) > 0 | |
| def is_complete(self) -> bool: | |
| """Check if the response indicates completion.""" | |
| return self.stop_reason in ("end_turn", "stop", "STOP", None) and not self.has_tool_calls | |
Xet Storage Details
- Size:
- 1.32 kB
- Xet hash:
- 53fc5113918c373c08a5c786388af1ccade9ffd5161fddd0401375ce1f8c0105
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.