Skip to content

Commit

Permalink
chore(chat): fix QUICK_APPS_HOST variable (Issue #2675) (#2719)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar authored Dec 3, 2024
1 parent 6de3b5f commit 2570c10
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ AI DIAL Chat uses environment variables for configuration. All environment varia
| `RECENT_MODELS_IDS` | No | A list of IDs for recently-used models | Any string | |
| `RECENT_ADDONS_IDS` | No | A list of IDs for recently-used addons | Any string | |
| `THEMES_CONFIG_HOST` | No | The host URL for a custom themes configuration.<br />Can lead to public and private resource.<br />Refer to [Theme Customization](../../docs/THEME-CUSTOMIZATION.md) to learn more. | Any string | |
| `NEXT_PUBLIC_QUICK_APPS_HOST` | No | The host URL for a Quick Apps Completion URLs.<br />Can lead to public and private resource. more. | Any string | |
| `QUICK_APPS_HOST` | No | The host URL for a Quick Apps Completion URLs.<br />Can lead to public and private resource. more. | Any string | |
| `FOOTER_HTML_MESSAGE` | No | A message that will be displayed in the application's footer.<br />Specify in HTML format. | Any string | |
| `ANNOUNCEMENT_HTML_MESSAGE` | No | A message of the announcement banner.<br />Specify in HTML format. | Any string | |
| `AZURE_FUNCTIONS_API_HOST` | No | Azure Functions API Host | Any string | |
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare global {
DIAL_API_KEY: string;
DIAL_API_HOST: string;

NEXT_PUBLIC_QUICK_APPS_HOST?: string;
QUICK_APPS_HOST?: string;

DIAL_API_VERSION?: string;
APP_BASE_PATH?: string;
Expand Down
5 changes: 3 additions & 2 deletions apps/chat/src/components/Common/ApplicationWizard/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getModelDescription,
getQuickAppConfig,
} from '@/src/utils/app/application';
import { DefaultsService } from '@/src/utils/app/data/defaults-service';
import { constructPath, notAllowedSymbols } from '@/src/utils/app/file';
import { getNextDefaultName } from '@/src/utils/app/folders';
import { ApiUtils } from '@/src/utils/server/api';
Expand All @@ -30,6 +31,7 @@ import {
} from '@/src/constants/applications';
import {
DEFAULT_APPLICATION_NAME,
DEFAULT_QUICK_APPS_HOST,
DEFAULT_TEMPERATURE,
} from '@/src/constants/default-ui-settings';
import { MIME_FORMAT_REGEX } from '@/src/constants/file';
Expand Down Expand Up @@ -379,8 +381,7 @@ export const getApplicationData = (
name: formData.name.trim(),
});
preparedData.completionUrl = constructPath(
process.env.NEXT_PUBLIC_QUICK_APPS_HOST ??
'http://quickapps.dial-development.svc.cluster.local',
DefaultsService.get('quickAppsHost', DEFAULT_QUICK_APPS_HOST),
'openai/deployments',
ApiUtils.safeEncodeURIComponent(formData.name.trim()),
'chat/completions',
Expand Down
3 changes: 3 additions & 0 deletions apps/chat/src/constants/default-ui-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ export const DEFAULT_SYSTEM_PROMPT =
export const DEFAULT_TEMPERATURE = parseFloat(
process.env.NEXT_PUBLIC_DEFAULT_TEMPERATURE ?? '1',
);

export const DEFAULT_QUICK_APPS_HOST =
'http://quickapps.dial-development.svc.cluster.local';
2 changes: 2 additions & 0 deletions apps/chat/src/store/settings/settings.epic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@ const initEpic: AppEpic = (action$, state$) =>
const storageType = SettingsSelectors.selectStorageType(state$.value);
const assistantSubmodelId =
SettingsSelectors.selectDefaultAssistantSubmodelId(state$.value);
const quickAppsHost = SettingsSelectors.selectQuickAppsHost(state$.value);

DefaultsService.setDefaults({
assistantSubmodelId,
quickAppsHost,
});
DataService.init(storageType);
}),
Expand Down
13 changes: 11 additions & 2 deletions apps/chat/src/store/settings/settings.reducers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { PayloadAction, createSelector, createSlice } from '@reduxjs/toolkit';

import { FeatureType, PageType } from '@/src/types/common';
Expand All @@ -8,7 +7,10 @@ import {
} from '@/src/types/custom-visualizers';
import { StorageType } from '@/src/types/storage';

import { FALLBACK_ASSISTANT_SUBMODEL_ID } from '@/src/constants/default-ui-settings';
import {
DEFAULT_QUICK_APPS_HOST,
FALLBACK_ASSISTANT_SUBMODEL_ID,
} from '@/src/constants/default-ui-settings';

import { RootState } from '..';

Expand Down Expand Up @@ -38,6 +40,7 @@ export interface SettingsState {
allowVisualizerSendMessages?: boolean;
topics: string[];
codeEditorPythonVersions: string[];
quickAppsHost?: string;
}

const initialState: SettingsState = {
Expand Down Expand Up @@ -325,6 +328,11 @@ const selectOverlayDefaultModelId = createSelector([rootSelector], (state) => {
return state.overlayDefaultModelId;
});

const selectQuickAppsHost = createSelector(
[rootSelector],
(state) => state.quickAppsHost ?? DEFAULT_QUICK_APPS_HOST,
);

export const SettingsActions = settingsSlice.actions;
export const SettingsSelectors = {
selectAppName,
Expand Down Expand Up @@ -355,4 +363,5 @@ export const SettingsSelectors = {
selectTopics,
selectCodeEditorPythonVersions,
selectOverlayDefaultModelId,
selectQuickAppsHost,
};
1 change: 1 addition & 0 deletions apps/chat/src/utils/app/data/defaults-service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface Defaults {
assistantSubmodelId: string;
quickAppsHost: string;
}

export class DefaultsService {
Expand Down
2 changes: 2 additions & 0 deletions apps/chat/src/utils/server/get-common-page-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SettingsState } from '@/src/store/settings/settings.reducers';

import { ISOLATED_MODEL_QUERY_PARAM } from '@/src/constants/chat';
import {
DEFAULT_QUICK_APPS_HOST,
FALLBACK_ASSISTANT_SUBMODEL_ID,
FALLBACK_MODEL_ID,
} from '@/src/constants/default-ui-settings';
Expand Down Expand Up @@ -130,6 +131,7 @@ export const getCommonPageProps: GetServerSideProps = async ({
process.env.TOPICS ??
'Business,Development,User Experience,Analysis,SQL,SDLC,Talk-To-Your-Data,RAG,Text Generation,Image Generation,Image Recognition'
).split(','),
quickAppsHost: process.env.QUICK_APPS_HOST || DEFAULT_QUICK_APPS_HOST,
};

if (params?.has(ISOLATED_MODEL_QUERY_PARAM)) {
Expand Down

0 comments on commit 2570c10

Please sign in to comment.