Stream a chat response from the LLM. Yields text chunks (str) as they arrive, then yields a final LLMResponse with the complete response metadata. The default implementation falls back to non-streaming chat(). Args: messages: List of conversati
(
self,
messages: list[Message],
tools: Optional[list[Tool]] = None,
system_prompt: Optional[str] = None,
max_tokens: int = 4096,
temperature: float = 0.0,
**kwargs
)
| 76 | pass |
| 77 | |
| 78 | def chat_stream( |
| 79 | self, |
| 80 | messages: list[Message], |
| 81 | tools: Optional[list[Tool]] = None, |
| 82 | system_prompt: Optional[str] = None, |
| 83 | max_tokens: int = 4096, |
| 84 | temperature: float = 0.0, |
| 85 | **kwargs |
| 86 | ) -> Generator[Union[str, LLMResponse], None, None]: |
| 87 | """ |
| 88 | Stream a chat response from the LLM. |
| 89 | |
| 90 | Yields text chunks (str) as they arrive, then yields |
| 91 | a final LLMResponse with the complete response metadata. |
| 92 | |
| 93 | The default implementation falls back to non-streaming chat(). |
| 94 | |
| 95 | Args: |
| 96 | messages: List of conversation messages. |
| 97 | tools: Optional list of tools the LLM can use. |
| 98 | system_prompt: Optional system prompt to set context. |
| 99 | max_tokens: Maximum tokens in the response. |
| 100 | temperature: Sampling temperature (0.0 = deterministic). |
| 101 | **kwargs: Additional provider-specific parameters. |
| 102 | |
| 103 | Yields: |
| 104 | str: Text content chunks as they arrive. |
| 105 | LLMResponse: Final response with complete metadata (last item). |
| 106 | """ |
| 107 | # Default: fall back to non-streaming |
| 108 | response = self.chat( |
| 109 | messages=messages, |
| 110 | tools=tools, |
| 111 | system_prompt=system_prompt, |
| 112 | max_tokens=max_tokens, |
| 113 | temperature=temperature, |
| 114 | **kwargs |
| 115 | ) |
| 116 | if response.content: |
| 117 | yield response.content |
| 118 | yield response |
| 119 | |
| 120 | def validate_connection(self) -> tuple[bool, Optional[str]]: |
| 121 | """ |
no test coverage detected