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

Method chat

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

Send a chat request to Docker Model Runner. Args: messages: List of conversation messages. tools: Optional list of tools the model can use. system_prompt: Optional system prompt. max_tokens: Maximum tokens in response. **k

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

Source from the content-addressed store, hash-verified

100 return bool(self._api_url)
101
102 def chat(
103 self,
104 messages: list[Message],
105 tools: Optional[list[Tool]] = None,
106 system_prompt: Optional[str] = None,
107 max_tokens: int = 4096,
108 **kwargs
109 ) -> LLMResponse:
110 """
111 Send a chat request to Docker Model Runner.
112
113 Args:
114 messages: List of conversation messages.
115 tools: Optional list of tools the model can use.
116 system_prompt: Optional system prompt.
117 max_tokens: Maximum tokens in response.
118 **kwargs: Additional parameters.
119
120 Returns:
121 LLMResponse containing the model's response.
122
123 Raises:
124 LLMClientError: If the request fails.
125 """
126 # Build the request payload
127 converted_messages = self._convert_messages(messages)
128
129 # Add system prompt at the beginning if provided
130 if system_prompt:
131 converted_messages.insert(0, {
132 'role': 'system',
133 'content': system_prompt
134 })
135
136 payload = {
137 'model': self._model,
138 'messages': converted_messages,
139 'max_completion_tokens': max_tokens,
140 }
141
142 if tools:
143 payload['tools'] = self._convert_tools(tools)
144 payload['tool_choice'] = 'auto'
145
146 # Make the API request
147 try:
148 response_data = self._make_request(payload)
149 return self._parse_response(response_data)
150 except LLMClientError:
151 raise
152 except Exception as e:
153 raise LLMClientError(LLMError(
154 message=f"Request failed: {str(e)}",
155 provider=self.provider_name
156 ))
157
158 def _convert_messages(self, messages: list[Message]) -> list[dict]:
159 """Convert Message objects to OpenAI API format."""

Callers

nothing calls this directly

Calls 6

_convert_messagesMethod · 0.95
_convert_toolsMethod · 0.95
_make_requestMethod · 0.95
_parse_responseMethod · 0.95
LLMClientErrorClass · 0.90
LLMErrorClass · 0.90

Tested by

no test coverage detected