MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / chat_stream

Method chat_stream

web/pgadmin/llm/providers/docker.py:380–419  ·  view source on GitHub ↗

Stream a chat response from Docker Model Runner.

(
        self,
        messages: list[Message],
        tools: Optional[list[Tool]] = None,
        system_prompt: Optional[str] = None,
        max_tokens: int = 4096,
        temperature: float = 0.0,
        **kwargs
    )

Source from the content-addressed store, hash-verified

378 )
379
380 def chat_stream(
381 self,
382 messages: list[Message],
383 tools: Optional[list[Tool]] = None,
384 system_prompt: Optional[str] = None,
385 max_tokens: int = 4096,
386 temperature: float = 0.0,
387 **kwargs
388 ) -> Generator[Union[str, LLMResponse], None, None]:
389 """Stream a chat response from Docker Model Runner."""
390 converted_messages = self._convert_messages(messages)
391
392 if system_prompt:
393 converted_messages.insert(0, {
394 'role': 'system',
395 'content': system_prompt
396 })
397
398 payload = {
399 'model': self._model,
400 'messages': converted_messages,
401 'max_completion_tokens': max_tokens,
402 'temperature': temperature,
403 'stream': True,
404 'stream_options': {'include_usage': True}
405 }
406
407 if tools:
408 payload['tools'] = self._convert_tools(tools)
409 payload['tool_choice'] = 'auto'
410
411 try:
412 yield from self._process_stream(payload)
413 except LLMClientError:
414 raise
415 except Exception as e:
416 raise LLMClientError(LLMError(
417 message=f"Streaming request failed: {str(e)}",
418 provider=self.provider_name
419 ))
420
421 def _process_stream(
422 self, payload: dict

Callers

nothing calls this directly

Calls 5

_convert_messagesMethod · 0.95
_convert_toolsMethod · 0.95
_process_streamMethod · 0.95
LLMClientErrorClass · 0.90
LLMErrorClass · 0.90

Tested by

no test coverage detected