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

Function get_llm_client

web/pgadmin/llm/client.py:149–273  ·  view source on GitHub ↗

Get an LLM client instance for the specified or default provider. Args: provider: Optional provider name ('anthropic', 'openai', 'ollama', 'docker'). If not specified, uses the configured default provider. model: Optional model name to us

(
    provider: Optional[str] = None,
    model: Optional[str] = None
)

Source from the content-addressed store, hash-verified

147
148
149def get_llm_client(
150 provider: Optional[str] = None,
151 model: Optional[str] = None
152) -> Optional[LLMClient]:
153 """
154 Get an LLM client instance for the specified or default provider.
155
156 Args:
157 provider: Optional provider name ('anthropic', 'openai', 'ollama',
158 'docker'). If not specified, uses the configured default
159 provider.
160 model: Optional model name to use. If not specified, uses the
161 configured default model for the provider.
162
163 Returns:
164 An LLMClient instance, or None if no provider is configured.
165
166 Raises:
167 ValueError: If an invalid provider is specified.
168 LLMClientError: If the client cannot be initialized.
169 """
170 from pgadmin.llm.utils import (
171 get_default_provider,
172 get_anthropic_api_url, get_anthropic_api_key, get_anthropic_model,
173 get_openai_api_url, get_openai_api_key, get_openai_model,
174 get_ollama_api_url, get_ollama_model,
175 get_docker_api_url, get_docker_model,
176 is_pref_api_url_rejected,
177 is_pref_api_key_path_rejected,
178 )
179
180 # Determine which provider to use
181 if provider is None:
182 provider = get_default_provider()
183 if provider is None:
184 return None
185
186 provider = provider.lower()
187
188 def _rejected_url_error(prov):
189 return LLMClientError(LLMError(
190 message=(
191 f"The configured {prov} API URL is not in the "
192 "allowed list (ALLOWED_LLM_API_URLS). Add it to "
193 "config_local.py, or clear the API URL preference "
194 "to use the system default."
195 ),
196 provider=prov,
197 ))
198
199 def _rejected_key_file_error(prov):
200 return LLMClientError(LLMError(
201 message=(
202 f"The configured {prov} API key file is not within "
203 "your private user storage. Move the key file to "
204 "your private storage directory, or clear the API "
205 "Key File preference to use the system default."
206 ),

Callers 8

generateFunction · 0.90
chat_with_databaseFunction · 0.90
runTestMethod · 0.90
runTestMethod · 0.90
generate_report_syncFunction · 0.90
is_llm_availableFunction · 0.85

Calls 15

get_default_providerFunction · 0.90
is_pref_api_url_rejectedFunction · 0.90
get_anthropic_api_keyFunction · 0.90
get_anthropic_api_urlFunction · 0.90
LLMErrorClass · 0.90
get_anthropic_modelFunction · 0.90
AnthropicClientClass · 0.90
get_openai_api_keyFunction · 0.90
get_openai_api_urlFunction · 0.90
get_openai_modelFunction · 0.90
OpenAIClientClass · 0.90

Tested by 2

runTestMethod · 0.72
runTestMethod · 0.72