-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support api-version and change default-model in adding azure-openai a…
…nd openai (#2799) ### What problem does this PR solve? #2701 #2712 #2749 ### Type of change -[x] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) --------- Co-authored-by: Kevin Hu <[email protected]>
- Loading branch information
1 parent
bfaef2c
commit 18f8074
Showing
11 changed files
with
203 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
web/src/pages/user-setting/setting-model/azure-openai-modal/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { useTranslate } from '@/hooks/common-hooks'; | ||
import { IModalProps } from '@/interfaces/common'; | ||
import { IAddLlmRequestBody } from '@/interfaces/request/llm'; | ||
import { Form, Input, Modal, Select, Switch } from 'antd'; | ||
import omit from 'lodash/omit'; | ||
|
||
type FieldType = IAddLlmRequestBody & { | ||
api_version: string; | ||
vision: boolean; | ||
}; | ||
|
||
const { Option } = Select; | ||
|
||
const AzureOpenAIModal = ({ | ||
visible, | ||
hideModal, | ||
onOk, | ||
loading, | ||
llmFactory, | ||
}: IModalProps<IAddLlmRequestBody> & { llmFactory: string }) => { | ||
const [form] = Form.useForm<FieldType>(); | ||
|
||
const { t } = useTranslate('setting'); | ||
|
||
const handleOk = async () => { | ||
const values = await form.validateFields(); | ||
const modelType = | ||
values.model_type === 'chat' && values.vision | ||
? 'image2text' | ||
: values.model_type; | ||
|
||
const data = { | ||
...omit(values, ['vision']), | ||
model_type: modelType, | ||
llm_factory: llmFactory, | ||
}; | ||
console.info(data); | ||
|
||
onOk?.(data); | ||
}; | ||
const optionsMap = { | ||
Default: [ | ||
{ value: 'chat', label: 'chat' }, | ||
{ value: 'embedding', label: 'embedding' }, | ||
{ value: 'image2text', label: 'image2text' }, | ||
], | ||
}; | ||
const getOptions = (factory: string) => { | ||
return optionsMap.Default; | ||
}; | ||
return ( | ||
<Modal | ||
title={t('addLlmTitle', { name: llmFactory })} | ||
open={visible} | ||
onOk={handleOk} | ||
onCancel={hideModal} | ||
okButtonProps={{ loading }} | ||
> | ||
<Form | ||
name="basic" | ||
style={{ maxWidth: 600 }} | ||
autoComplete="off" | ||
layout={'vertical'} | ||
form={form} | ||
> | ||
<Form.Item<FieldType> | ||
label={t('modelType')} | ||
name="model_type" | ||
initialValue={'embedding'} | ||
rules={[{ required: true, message: t('modelTypeMessage') }]} | ||
> | ||
<Select placeholder={t('modelTypeMessage')}> | ||
{getOptions(llmFactory).map((option) => ( | ||
<Option key={option.value} value={option.value}> | ||
{option.label} | ||
</Option> | ||
))} | ||
</Select> | ||
</Form.Item> | ||
<Form.Item<FieldType> | ||
label={t('addLlmBaseUrl')} | ||
name="api_base" | ||
rules={[{ required: true, message: t('baseUrlNameMessage') }]} | ||
> | ||
<Input placeholder={t('baseUrlNameMessage')} /> | ||
</Form.Item> | ||
<Form.Item<FieldType> | ||
label={t('apiKey')} | ||
name="api_key" | ||
rules={[{ required: false, message: t('apiKeyMessage') }]} | ||
> | ||
<Input placeholder={t('apiKeyMessage')} /> | ||
</Form.Item> | ||
<Form.Item<FieldType> | ||
label={t('modelName')} | ||
name="llm_name" | ||
initialValue="gpt-3.5-turbo" | ||
rules={[{ required: true, message: t('modelNameMessage') }]} | ||
> | ||
<Input placeholder={t('modelNameMessage')} /> | ||
</Form.Item> | ||
<Form.Item<FieldType> | ||
label={t('apiVersion')} | ||
name="api_version" | ||
initialValue="2024-02-01" | ||
rules={[{ required: false, message: t('apiVersionMessage') }]} | ||
> | ||
<Input placeholder={t('apiVersionMessage')} /> | ||
</Form.Item> | ||
<Form.Item noStyle dependencies={['model_type']}> | ||
{({ getFieldValue }) => | ||
getFieldValue('model_type') === 'chat' && ( | ||
<Form.Item | ||
label={t('vision')} | ||
valuePropName="checked" | ||
name={'vision'} | ||
> | ||
<Switch /> | ||
</Form.Item> | ||
) | ||
} | ||
</Form.Item> | ||
</Form> | ||
</Modal> | ||
); | ||
}; | ||
|
||
export default AzureOpenAIModal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters