Skip to content

Commit

Permalink
feat(chat): apply endpoints and environment variables with Code App e…
Browse files Browse the repository at this point in the history
…xamples (Issue #2536) (#2782)
  • Loading branch information
IlyaBondar authored Dec 12, 2024
1 parent 8f7361f commit ef547c5
Show file tree
Hide file tree
Showing 20 changed files with 353 additions and 265 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { DEFAULT_SYSTEM_PROMPT } from '@/chat/constants/default-server-settings';
import {
DEFAULT_CONVERSATION_NAME,
DEFAULT_SYSTEM_PROMPT,
DEFAULT_TEMPERATURE,
} from '@/chat/constants/default-ui-settings';
import { defaultReplay } from '@/chat/constants/replay';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ export const ChatInputMessage = ({
/>
<ChatControls
showReplayControls={showReplayControls}
onSend={shouldRegenerate ? onRegenerate : handleSend}
onSend={handleSend}
tooltip={tooltipContent()}
isLastMessageError={isLastMessageError}
isLoading={isLoading}
Expand Down
5 changes: 2 additions & 3 deletions apps/chat/src/components/Chat/ChatSettings/SystemPrompt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { useTranslation } from 'next-i18next';
import { usePromptSelection } from '@/src/hooks/usePromptSelection';
import { useTokenizer } from '@/src/hooks/useTokenizer';

import { DefaultsService } from '@/src/utils/app/data/defaults-service';
import { getPromptLimitDescription } from '@/src/utils/app/modals';

import { DialAIEntityModel } from '@/src/types/models';
import { Prompt } from '@/src/types/prompt';
import { Translation } from '@/src/types/translation';

import { DEFAULT_SYSTEM_PROMPT } from '@/src/constants/default-ui-settings';

import { ConfirmDialog } from '@/src/components/Common/ConfirmDialog';
import { Spinner } from '@/src/components/Common/Spinner';

Expand Down Expand Up @@ -74,7 +73,7 @@ export const SystemPrompt: FC<Props> = ({
} = usePromptSelection(
maxTokensLength,
tokenizer,
prompt ?? DEFAULT_SYSTEM_PROMPT,
prompt ?? DefaultsService.get('defaultSystemPrompt', ''),
onChangePrompt,
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback } from 'react';
import { useFormContext } from 'react-hook-form';

import { useTranslation } from 'next-i18next';

Expand All @@ -12,8 +13,11 @@ import { Translation } from '@/src/types/translation';
import { FilesActions } from '@/src/store/files/files.reducers';
import { useAppDispatch } from '@/src/store/hooks';

import { FEATURES_ENDPOINTS_NAMES } from '@/src/constants/applications';
import { CODE_APPS_EXAMPLES, ExampleTypes } from '@/src/constants/code-apps';

import { CodeData } from '../form';

interface CodeAppExampleLinkProps {
exampleType: ExampleTypes;
folderId: string;
Expand All @@ -28,12 +32,13 @@ export const CodeAppExampleLink = ({
fileNames,
}: CodeAppExampleLinkProps) => {
const { t } = useTranslation(Translation.Marketplace);
const { setValue, getValues } = useFormContext<CodeData>();

const dispatch = useAppDispatch();

const handleClick = useCallback(() => {
const example = CODE_APPS_EXAMPLES[exampleType];
Object.entries(example).map(([newFileName, content]) => {
Object.entries(example.files).forEach(([newFileName, content]) => {
if (!fileNames.includes(newFileName)) {
dispatch(
FilesActions.uploadFile({
Expand All @@ -47,7 +52,38 @@ export const CodeAppExampleLink = ({
);
}
});
}, [dispatch, exampleType, folderId, fileNames]);
if (example.endpoints) {
const endpoints = getValues('endpoints');
Object.entries(example.endpoints).forEach(([endpoint, endpointUrl]) => {
const index = endpoints.findIndex((end) => end.label === endpoint);
if (index === -1) {
setValue(`endpoints.${endpoints.length}`, {
label: endpoint,
value: endpointUrl,
visibleName: FEATURES_ENDPOINTS_NAMES[endpoint],
});
} else {
setValue(`endpoints.${index}.value`, endpointUrl);
}
});
}
if (example.variables) {
const envs = getValues('env');
Object.entries(example.variables).forEach(([variable, getEnvValue]) => {
const index = envs.findIndex((item) => item.label === variable);
if (index === -1) {
setValue(`env.${envs.length}`, {
label: variable,
value: getEnvValue(),
editableKey: true,
visibleName: variable,
});
} else {
setValue(`env.${index}.value`, getEnvValue());
}
});
}
}, [exampleType, fileNames, dispatch, folderId, setValue, getValues]);

return (
<span
Expand Down
Loading

0 comments on commit ef547c5

Please sign in to comment.