Skip to content

Commit

Permalink
feat(chat): add QUICK_APPS_MODEL env variable (Issue #2736) (#2739)
Browse files Browse the repository at this point in the history
Co-authored-by: Magomed-Elbi Dzhukalaev <[email protected]>
  • Loading branch information
Gimir and Magomed-Elbi Dzhukalaev authored Dec 4, 2024
1 parent 101c8ba commit 67cb498
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 16 deletions.
1 change: 1 addition & 0 deletions apps/chat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ AI DIAL Chat uses environment variables for configuration. All environment varia
| `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 | |
| `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_MODEL` | No | A model that will be used in Quick Apps | 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
1 change: 1 addition & 0 deletions apps/chat/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ declare global {
DIAL_API_HOST: string;

QUICK_APPS_HOST?: string;
QUICK_APPS_MODEL?: string;

DIAL_API_VERSION?: string;
APP_BASE_PATH?: string;
Expand Down
6 changes: 4 additions & 2 deletions apps/chat/src/components/Chat/ChatSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ export const ChatSettings = ({
);
const [currentAssistentModelId, setCurrentAssistentModelId] = useState(
conversation.assistantModelId ??
DefaultsService.get('assistantSubmodelId') ??
FALLBACK_ASSISTANT_SUBMODEL_ID,
DefaultsService.get(
'assistantSubmodelId',
FALLBACK_ASSISTANT_SUBMODEL_ID,
),
);
const [currentSelectedAddonsIds, setCurrentSelectedAddonsIds] = useState(
conversation.selectedAddons || [],
Expand Down
6 changes: 4 additions & 2 deletions apps/chat/src/components/Chat/ConversationSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ export const ConversationSettings = ({
<AssistantSubModelSelector
assistantModelId={
assistantModelId ??
DefaultsService.get('assistantSubmodelId') ??
FALLBACK_ASSISTANT_SUBMODEL_ID
DefaultsService.get(
'assistantSubmodelId',
FALLBACK_ASSISTANT_SUBMODEL_ID,
)
}
onSelectAssistantSubModel={onSelectAssistantSubModel}
disabled={isPlayback}
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Common/ApplicationWizard/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ 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';
import { DEFAULT_VERSION } from '@/src/constants/public';
import { DEFAULT_QUICK_APPS_HOST } from '@/src/constants/quick-apps';

import { DynamicField } from '@/src/components/Common/Forms/DynamicFormFields';

Expand Down
3 changes: 0 additions & 3 deletions apps/chat/src/constants/default-ui-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,3 @@ 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';
5 changes: 5 additions & 0 deletions apps/chat/src/constants/quick-apps.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const QUICK_APP_CONFIG_DIVIDER = '>>>>>>>>>>';

export const DEFAULT_QUICK_APPS_MODEL = 'gpt-4o';

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

DefaultsService.setDefaults({
assistantSubmodelId,
quickAppsHost,
quickAppsModel,
});
DataService.init(storageType);
}),
Expand Down
12 changes: 10 additions & 2 deletions apps/chat/src/store/settings/settings.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ 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';
DEFAULT_QUICK_APPS_MODEL,
} from '@/src/constants/quick-apps';

import { RootState } from '..';

Expand Down Expand Up @@ -41,6 +42,7 @@ export interface SettingsState {
topics: string[];
codeEditorPythonVersions: string[];
quickAppsHost?: string;
quickAppsModel?: string;
}

const initialState: SettingsState = {
Expand Down Expand Up @@ -333,6 +335,11 @@ const selectQuickAppsHost = createSelector(
(state) => state.quickAppsHost ?? DEFAULT_QUICK_APPS_HOST,
);

const selectQuickAppsModel = createSelector(
[rootSelector],
(state) => state.quickAppsModel ?? DEFAULT_QUICK_APPS_MODEL,
);

export const SettingsActions = settingsSlice.actions;
export const SettingsSelectors = {
selectAppName,
Expand Down Expand Up @@ -364,4 +371,5 @@ export const SettingsSelectors = {
selectCodeEditorPythonVersions,
selectOverlayDefaultModelId,
selectQuickAppsHost,
selectQuickAppsModel,
};
10 changes: 7 additions & 3 deletions apps/chat/src/utils/app/application.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DefaultsService } from '@/src/utils/app/data/defaults-service';
import { getTopicColors } from '@/src/utils/app/style-helpers';

import {
Expand All @@ -15,7 +16,10 @@ import { QuickAppConfig } from '@/src/types/quick-apps';

import { DESCRIPTION_DELIMITER_REGEX } from '@/src/constants/chat';
import { DEFAULT_TEMPERATURE } from '@/src/constants/default-ui-settings';
import { QUICK_APP_CONFIG_DIVIDER } from '@/src/constants/quick-apps';
import {
DEFAULT_QUICK_APPS_MODEL,
QUICK_APP_CONFIG_DIVIDER,
} from '@/src/constants/quick-apps';

import { ApiUtils, getApplicationApiKey } from '../server/api';
import { constructPath } from './file';
Expand Down Expand Up @@ -152,7 +156,7 @@ export const getQuickAppConfig = (entity: DialAIEntityModel) => {
parsedConfig = {
description: getModelDescription(entity),
instructions: '',
model: 'gpt-4o',
model: DefaultsService.get('quickAppsModel', DEFAULT_QUICK_APPS_MODEL),
name: entity.name,
temperature: DEFAULT_TEMPERATURE,
web_api_toolset: {},
Expand Down Expand Up @@ -184,7 +188,7 @@ export const createQuickAppConfig = ({
name,
temperature,
web_api_toolset: JSON.parse(config ?? '{}'),
model: 'gpt-4o',
model: DefaultsService.get('quickAppsModel', DEFAULT_QUICK_APPS_MODEL),
};

return [description.trim(), JSON.stringify(preparedConfig)].join(
Expand Down
3 changes: 1 addition & 2 deletions apps/chat/src/utils/app/clean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ export const cleanConversation = (

const assistantModelId =
conversation.assistantModelId ??
DefaultsService.get('assistantSubmodelId') ??
FALLBACK_ASSISTANT_SUBMODEL_ID;
DefaultsService.get('assistantSubmodelId', FALLBACK_ASSISTANT_SUBMODEL_ID);

const cleanConversation: Conversation = {
id:
Expand Down
6 changes: 6 additions & 0 deletions apps/chat/src/utils/app/data/defaults-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface Defaults {
assistantSubmodelId: string;
quickAppsHost: string;
quickAppsModel: string;
}

export class DefaultsService {
Expand All @@ -12,6 +13,11 @@ export class DefaultsService {
);
}

public static get(key: keyof Defaults): string | undefined;
public static get(
key: keyof Defaults,
defaultValue: Defaults[keyof Defaults],
): string;
public static get(
key: keyof Defaults,
defaultValue?: Defaults[keyof Defaults],
Expand Down
6 changes: 5 additions & 1 deletion apps/chat/src/utils/server/get-common-page-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ 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';
import {
DEFAULT_QUICK_APPS_HOST,
DEFAULT_QUICK_APPS_MODEL,
} from '@/src/constants/quick-apps';

import { authOptions } from '@/src/pages/api/auth/[...nextauth]';

Expand Down Expand Up @@ -132,6 +135,7 @@ export const getCommonPageProps: GetServerSideProps = async ({
'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,
quickAppsModel: process.env.QUICK_APPS_MODEL || DEFAULT_QUICK_APPS_MODEL,
};

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

0 comments on commit 67cb498

Please sign in to comment.