Update code for tool call

This commit is contained in:
Xin Wang
2026-02-10 16:28:20 +08:00
parent 539cf2fda2
commit 4b8da32787
7 changed files with 676 additions and 91 deletions

View File

@@ -7,7 +7,7 @@ StreamEngine pattern.
from abc import ABC, abstractmethod
from dataclasses import dataclass, field
from typing import AsyncIterator, Optional, List, Dict, Any
from typing import AsyncIterator, Optional, List, Dict, Any, Literal
from enum import Enum
@@ -52,6 +52,15 @@ class LLMMessage:
return d
@dataclass
class LLMStreamEvent:
"""Structured LLM stream event."""
type: Literal["text_delta", "tool_call", "done"]
text: Optional[str] = None
tool_call: Optional[Dict[str, Any]] = None
@dataclass
class TTSChunk:
"""TTS audio chunk."""
@@ -170,7 +179,7 @@ class BaseLLMService(ABC):
messages: List[LLMMessage],
temperature: float = 0.7,
max_tokens: Optional[int] = None
) -> AsyncIterator[str]:
) -> AsyncIterator[LLMStreamEvent]:
"""
Generate response in streaming mode.
@@ -180,7 +189,7 @@ class BaseLLMService(ABC):
max_tokens: Maximum tokens to generate
Yields:
Text chunks as they are generated
Stream events (text delta/tool call/done)
"""
pass