Skip to content

Commit e5cf456

Browse files
authored
Fixed an issue where AI Reports are grayed out after setting an API key by auto-selecting the default provider. #9694
* Don't let auto-selection override an explicit default_provider choice. If the same save payload includes a default_provider update (including setting it to empty/disabled), skip the auto-selection logic so the user's explicit choice is respected.
1 parent da55da4 commit e5cf456

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

docs/en_US/release_notes_9_14.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Bug fixes
3333

3434
| `Issue #9279 <https://github.com/pgadmin-org/pgadmin4/issues/9279>`_ - Fixed an issue where OAuth2 authentication fails with 'object has no attribute' if OAUTH2_AUTO_CREATE_USER is False.
3535
| `Issue #9392 <https://github.com/pgadmin-org/pgadmin4/issues/9392>`_ - Ensure that the Geometry Viewer refreshes when re-running queries or switching geometry columns, preventing stale data from being displayed.
36+
| `Issue #9694 <https://github.com/pgadmin-org/pgadmin4/issues/9694>`_ - Fixed an issue where AI Reports are grayed out after setting an API key by auto-selecting the default provider.
3637
| `Issue #9702 <https://github.com/pgadmin-org/pgadmin4/issues/9702>`_ - Fixed misleading AI activity messages that could be mistaken for actual database operations.
3738
| `Issue #9719 <https://github.com/pgadmin-org/pgadmin4/issues/9719>`_ - Fixed an issue where AI Reports fail with OpenAI models that do not support the temperature parameter.
3839
| `Issue #9721 <https://github.com/pgadmin-org/pgadmin4/issues/9721>`_ - Fixed an issue where permissions page is not completely accessible on full scroll.

web/pgadmin/preferences/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,18 @@ def save():
229229
"""
230230
pref_data = get_data()
231231

232+
# Check once whether the user is explicitly setting default_provider
233+
# in this save, so auto-selection doesn't override their choice.
234+
_provider_map = {
235+
'anthropic_api_key_file': 'anthropic',
236+
'openai_api_key_file': 'openai',
237+
'ollama_api_url': 'ollama',
238+
'docker_api_url': 'docker',
239+
}
240+
explicit_provider_choice = any(
241+
item.get('name') == 'default_provider' for item in pref_data
242+
)
243+
232244
for data in pref_data:
233245
if data['name'] in ['vw_edt_tab_title_placeholder',
234246
'qt_tab_title_placeholder',
@@ -243,6 +255,16 @@ def save():
243255
if data['name'] == 'save_app_state' and not data['value']:
244256
delete_tool_data()
245257

258+
# Auto-select the default LLM provider when an API key/URL is
259+
# configured and no provider has been selected yet.
260+
if res and not explicit_provider_choice and \
261+
data['name'] in _provider_map and data['value']:
262+
ai_module = Preferences.module('ai')
263+
if ai_module:
264+
dp_pref = ai_module.preference('default_provider')
265+
if dp_pref and not dp_pref.get():
266+
dp_pref.set(_provider_map[data['name']])
267+
246268
if not res:
247269
return internal_server_error(errormsg=msg)
248270

@@ -309,6 +331,18 @@ def update():
309331
pref_data = get_data()
310332
pref_data = json.loads(pref_data['pref_data'])
311333

334+
# Check once whether the user is explicitly setting default_provider
335+
# in this save, so auto-selection doesn't override their choice.
336+
_provider_map = {
337+
'anthropic_api_key_file': 'anthropic',
338+
'openai_api_key_file': 'openai',
339+
'ollama_api_url': 'ollama',
340+
'docker_api_url': 'docker',
341+
}
342+
explicit_provider_choice = any(
343+
item.get('name') == 'default_provider' for item in pref_data
344+
)
345+
312346
for data in pref_data:
313347
if data['name'] in ['vw_edt_tab_title_placeholder',
314348
'qt_tab_title_placeholder',
@@ -321,6 +355,16 @@ def update():
321355
# set user preferences
322356
pref.set(data['value'])
323357

358+
# Auto-select the default LLM provider when an API key/URL is
359+
# configured and no provider has been selected yet.
360+
if not explicit_provider_choice and \
361+
data['name'] in _provider_map and data['value']:
362+
ai_module = Preferences.module('ai')
363+
if ai_module:
364+
dp_pref = ai_module.preference('default_provider')
365+
if dp_pref and not dp_pref.get():
366+
dp_pref.set(_provider_map[data['name']])
367+
324368
return make_json_response(
325369
data={'data': 'Success'},
326370
status=200

0 commit comments

Comments
 (0)