Skip to content

Commit 23bd335

Browse files
authored
Fixed an issue where AI features are visible in the UI even when LLM_ENABLED is set to False.
1 parent 0bc4edb commit 23bd335

File tree

6 files changed

+27
-8
lines changed

6 files changed

+27
-8
lines changed

docs/en_US/release_notes_9_14.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Bug fixes
3232
| `Issue #9729 <https://github.com/pgadmin-org/pgadmin4/issues/9729>`_ - Fixed an issue where some LLM models would not use database tools in the AI assistant, instead returning text descriptions of tool calls.
3333
| `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.
3434
| `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.
35+
| `Issue #9709 <https://github.com/pgadmin-org/pgadmin4/issues/9709>`_ - Fixed an issue where AI features (AI Assistant tab, AI Reports menus, and AI Preferences) were visible in the UI even when LLM_ENABLED is set to False.
3536
| `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.
3637
| `Issue #9721 <https://github.com/pgadmin-org/pgadmin4/issues/9721>`_ - Fixed an issue where permissions page is not completely accessible on full scroll.
3738
| `Issue #9732 <https://github.com/pgadmin-org/pgadmin4/issues/9732>`_ - Improve the AI Assistant user prompt to be more descriptive of the actual functionality.

web/pgadmin/browser/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,7 @@ def utils():
538538
"Administrator") else restricted_shared_storage_list,
539539
enable_server_passexec_cmd=config.ENABLE_SERVER_PASS_EXEC_CMD,
540540
max_server_tags_allowed=config.MAX_SERVER_TAGS_ALLOWED,
541+
llm_enabled=config.LLM_ENABLED,
541542
), 200)
542543
response.headers['Content-Type'] = MIMETYPE_APP_JS
543544
response.headers['Cache-Control'] = NO_CACHE_CONTROL

web/pgadmin/browser/templates/browser/js/utils.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ define('pgadmin.browser.utils',
7272
/* Enable server password exec command */
7373
pgAdmin['enable_server_passexec_cmd'] = '{{enable_server_passexec_cmd}}';
7474

75+
/* LLM/AI features enabled */
76+
pgAdmin['llm_enabled'] = '{{llm_enabled}}' == 'True';
77+
7578
// Define list of nodes on which Query tool option doesn't appears
7679
let unsupported_nodes = pgAdmin.unsupported_nodes = [
7780
'server_group', 'server', 'coll-tablespace', 'tablespace',

web/pgadmin/llm/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ def register_preferences(self):
4545
"""
4646
Register preferences for LLM providers.
4747
"""
48+
# Don't register AI preferences if LLM is disabled at system level
49+
if not getattr(config, 'LLM_ENABLED', False):
50+
return
51+
4852
self.preference = Preferences('ai', gettext('AI'))
4953

5054
# Default Provider Setting

web/pgadmin/llm/static/js/ai_tools.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import AIReport from './AIReport';
1111
import { AllPermissionTypes, BROWSER_PANELS } from '../../../browser/static/js/constants';
1212
import getApiInstance from '../../../static/js/api_instance';
13+
import MainMenuFactory from '../../../browser/static/js/MainMenuFactory';
1314
import url_for from 'sources/url_for';
1415

1516
// AI Reports Module
@@ -36,9 +37,14 @@ define([
3637

3738
this.initialized = true;
3839

39-
// Check LLM status
40+
// Check LLM status and only register menus if enabled
4041
this.checkLLMStatus();
4142

43+
return this;
44+
},
45+
46+
// Register AI Reports menus
47+
registerMenus: function() {
4248
// Register AI Reports menu category
4349
pgBrowser.add_menu_category({
4450
name: 'ai_tools',
@@ -158,11 +164,9 @@ define([
158164
}
159165

160166
pgBrowser.add_menus(menus);
161-
162-
return this;
163167
},
164168

165-
// Check if LLM is configured
169+
// Check if LLM is configured, register menus only if system-enabled
166170
checkLLMStatus: function() {
167171
const api = getApiInstance();
168172
api.get(url_for('llm.status'))
@@ -172,6 +176,12 @@ define([
172176
this.llmSystemEnabled = res.data.data?.system_enabled || false;
173177
}
174178
this.llmStatusChecked = true;
179+
180+
// Only register menus if LLM is enabled at system level
181+
if (this.llmSystemEnabled) {
182+
this.registerMenus();
183+
MainMenuFactory.createMainMenus();
184+
}
175185
})
176186
.catch(() => {
177187
this.llmEnabled = false;

web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
233233
tabs: [
234234
LayoutDocker.getPanel({id: PANELS.QUERY, title: gettext('Query'), content: <Query onTextSelect={(text) => setSelectedText(text)} setQtStatePartial={setQtStatePartial}/>}),
235235
LayoutDocker.getPanel({id: PANELS.HISTORY, title: gettext('Query History'), content: <QueryHistory />}),
236-
LayoutDocker.getPanel({id: PANELS.AI_ASSISTANT, title: gettext('AI Assistant'), content: <NLQChatPanel />}),
236+
...(pgAdmin.llm_enabled ? [LayoutDocker.getPanel({id: PANELS.AI_ASSISTANT, title: gettext('AI Assistant'), content: <NLQChatPanel />})] : []),
237237
],
238238
},
239239
{
@@ -442,7 +442,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
442442
eventBus.current.registerListener(QUERY_TOOL_EVENTS.REINIT_QT_CONNECTION, initializeQueryTool);
443443

444444
eventBus.current.registerListener(QUERY_TOOL_EVENTS.FOCUS_PANEL, (qtPanelId)=>{
445-
docker.current.focus(qtPanelId);
445+
docker.current?.focus(qtPanelId);
446446
});
447447

448448
eventBus.current.registerListener(QUERY_TOOL_EVENTS.SET_CONNECTION_STATUS, (status)=>{
@@ -464,9 +464,9 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
464464
if(qtPanelId == currentTabId) {
465465
setQtStatePartial({is_visible: true});
466466

467-
if(docker.current.isTabVisible(PANELS.QUERY)) {
467+
if(docker.current?.isTabVisible(PANELS.QUERY)) {
468468
docker.current.focus(PANELS.QUERY);
469-
} else if(docker.current.isTabVisible(PANELS.HISTORY)) {
469+
} else if(docker.current?.isTabVisible(PANELS.HISTORY)) {
470470
docker.current.focus(PANELS.HISTORY);
471471
}
472472

0 commit comments

Comments
 (0)