Merge branch 'master' of github.com:tencentmusic/supersonic

This commit is contained in:
jerryjzhang
2024-07-06 23:33:35 +08:00
7 changed files with 243 additions and 25 deletions

View File

@@ -90,13 +90,27 @@ export type AgentType = {
updatedAt: string; updatedAt: string;
enableSearch: number; enableSearch: number;
agentConfig: string; agentConfig: string;
llmConfig: { modelConfig: {
provider: string; chatModel: {
baseUrl: string; provider: string;
apiKey: string; baseUrl: string;
modelName: string; apiKey: string;
temperature: number; modelName: string;
timeOut: number; temperature: number;
timeOut: number;
};
embeddingModel: {
apiKey: string;
baseUrl: string;
// logRequests: true,
// logResponses: true,
// maxRetries: number,
// maxToken: number,
modelName: string;
modelPath: string;
provider: string;
vocabularyPath: string;
};
}; };
multiTurnConfig: { multiTurnConfig: {
enableMultiTurn: boolean; enableMultiTurn: boolean;

View File

@@ -0,0 +1,15 @@
import styles from './style.less';
type Props = {};
const MainTitleMark: React.FC<Props> = ({}) => {
return (
<div className={styles.mainTitleMark}>
<i className={styles.mark} />
<i className={styles.mark} />
<i className={styles.mark} />
</div>
);
};
export default MainTitleMark;

View File

@@ -0,0 +1,25 @@
.mainTitleMark {
margin-right: 24px;
margin-left: 8px;
.mark {
display: inline-block;
width: 4px;
height: 11px;
background: var(--tme-primary-color);
border-radius: 4px;
transform: rotate(15deg);
&:not(:last-of-type) {
margin-right: 4px;
}
&:nth-of-type(2) {
opacity: 0.6;
}
&:nth-of-type(3) {
opacity: 0.2;
}
}
}

View File

@@ -12,6 +12,7 @@ import {
message, message,
Space, Space,
} from 'antd'; } from 'antd';
import MainTitleMark from '@/components/MainTitleMark';
import { AgentType } from './type'; import { AgentType } from './type';
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import styles from './style.less'; import styles from './style.less';
@@ -43,10 +44,19 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
const [llmTestLoading, setLlmTestLoading] = useState<boolean>(false); const [llmTestLoading, setLlmTestLoading] = useState<boolean>(false);
const [formData, setFormData] = useState<any>({ const [formData, setFormData] = useState<any>({
enableSearch: true, enableSearch: true,
llmConfig: { modelConfig: {
chatModel: {
timeOut: 60,
provider: 'OPEN_AI',
temperature: 0,
},
embeddingModel: {
provider: 'OPEN_AI',
},
},
embeddingStore: {
provider: 'MILVUS',
timeOut: 60, timeOut: 60,
provider: 'OPEN_AI',
temperature: 0,
}, },
agentConfig: { agentConfig: {
...defaultAgentConfig, ...defaultAgentConfig,
@@ -57,8 +67,8 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
useEffect(() => { useEffect(() => {
if (editAgent) { if (editAgent) {
const sourceData = { ...editAgent }; const sourceData = { ...editAgent };
if (!sourceData.llmConfig) { if (!sourceData.modelConfig) {
delete sourceData.llmConfig; delete sourceData.modelConfig;
} }
const config = jsonParse(editAgent.agentConfig, {}); const config = jsonParse(editAgent.agentConfig, {});
@@ -217,10 +227,15 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
}, },
{ {
label: '大模型配置', label: '大模型配置',
key: 'llmConfig', key: 'modelConfig',
children: ( children: (
<div className={styles.agentFormContainer}> <div className={styles.agentFormContainer}>
<FormItem name={['llmConfig', 'provider']} label="接口协议"> <div className={styles.agentFormTitle}>
<Space>
<MainTitleMark />
</Space>
</div>
<FormItem name={['modelConfig', 'chatModel', 'provider']} label="接口协议">
<Select placeholder=""> <Select placeholder="">
{['OPEN_AI', 'OLLAMA'].map((item) => ( {['OPEN_AI', 'OLLAMA'].map((item) => (
<Select.Option key={item} value={item}> <Select.Option key={item} value={item}>
@@ -229,16 +244,16 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
))} ))}
</Select> </Select>
</FormItem> </FormItem>
<FormItem name={['llmConfig', 'modelName']} label="Model Name"> <FormItem name={['modelConfig', 'chatModel', 'modelName']} label="Model Name">
<Input placeholder="请输入模型名称" /> <Input placeholder="请输入语言模型名称" />
</FormItem> </FormItem>
<FormItem name={['llmConfig', 'baseUrl']} label="Base URL"> <FormItem name={['modelConfig', 'chatModel', 'baseUrl']} label="Base URL">
<Input placeholder="请输入Base URL" /> <Input placeholder="请输入Base URL" />
</FormItem> </FormItem>
<FormItem <FormItem
name={['llmConfig', 'apiKey']} name={['modelConfig', 'chatModel', 'apiKey']}
label="API Key" label="API Key"
hidden={formData?.llmConfig?.provider === 'OLLAMA'} hidden={formData?.modelConfig?.chatModel?.provider === 'OLLAMA'}
getValueFromEvent={(event) => { getValueFromEvent={(event) => {
const value = event.target.value; const value = event.target.value;
return encryptPassword(value); return encryptPassword(value);
@@ -252,7 +267,7 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
<Input.Password placeholder="请输入API Key" visibilityToggle /> <Input.Password placeholder="请输入API Key" visibilityToggle />
</FormItem> </FormItem>
<FormItem name={['llmConfig', 'temperature']} label="Temperature"> <FormItem name={['modelConfig', 'chatModel', 'temperature']} label="Temperature">
<Slider <Slider
min={0} min={0}
max={1} max={1}
@@ -263,9 +278,136 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
}} }}
/> />
</FormItem> </FormItem>
<FormItem name={['llmConfig', 'timeOut']} label="超时时间(秒)"> <FormItem name={['modelConfig', 'chatModel', 'timeOut']} label="超时时间(秒)">
<InputNumber /> <InputNumber />
</FormItem> </FormItem>
<div className={styles.agentFormTitle}>
<Space>
<MainTitleMark />
</Space>
</div>
<FormItem name={['modelConfig', 'embeddingModel', 'provider']} label="接口协议">
<Select placeholder="">
{[
'OPEN_AI',
'OLLAMA',
'LOCAL_AI',
'IN_MEMORY',
'ZHIPU',
'AZURE',
'QIANFAN',
'DASHSCOPE',
].map((item) => (
<Select.Option key={item} value={item}>
{item}
</Select.Option>
))}
</Select>
</FormItem>
<FormItem name={['modelConfig', 'embeddingModel', 'modelName']} label="Model Name">
<Input placeholder="请输入向量模型名称" />
</FormItem>
{formData?.modelConfig?.embeddingModel?.provider === 'IN_MEMORY' ? (
<>
<FormItem name={['modelConfig', 'embeddingModel', 'modelPath']} label="模型路径">
<Input placeholder="请输入模型路径" />
</FormItem>
<FormItem
name={['modelConfig', 'embeddingModel', 'vocabularyPath']}
label="词汇表路径"
>
<Input placeholder="请输入模型路径" />
</FormItem>
</>
) : (
<>
<FormItem name={['modelConfig', 'embeddingModel', 'baseUrl']} label="Base URL">
<Input placeholder="请输入Base URL" />
</FormItem>
<FormItem
name={['modelConfig', 'embeddingModel', 'apiKey']}
label="API Key"
getValueFromEvent={(event) => {
const value = event.target.value;
return encryptPassword(value);
}}
getValueProps={(value) => {
return {
value: value ? decryptPassword(value) : '',
};
}}
>
<Input.Password placeholder="请输入API Key" visibilityToggle />
</FormItem>
</>
)}
</div>
),
},
{
label: '向量库配置',
key: 'embeddingStore',
children: (
<div className={styles.agentFormContainer}>
<FormItem name={['embeddingStore', 'provider']} label="接口协议">
<Select placeholder="">
{['MILVUS', 'CHROMA', 'IN_MEMORY'].map((item) => (
<Select.Option key={item} value={item}>
{item}
</Select.Option>
))}
</Select>
</FormItem>
{formData?.embeddingStore?.provider === 'IN_MEMORY' ? (
<>
<FormItem name={['embeddingStore', 'persistPath']} label="持久化路径">
<Input placeholder="请输入持久化路径" />
</FormItem>
</>
) : (
<>
<FormItem name={['embeddingStore', 'baseUrl']} label="Base URL">
<Input placeholder="请输入Base URL" />
</FormItem>
<FormItem
name={['embeddingStore', 'apiKey']}
label="API Key"
getValueFromEvent={(event) => {
const value = event.target.value;
return encryptPassword(value);
}}
getValueProps={(value) => {
return {
value: value ? decryptPassword(value) : '',
};
}}
>
<Input.Password placeholder="请输入API Key" visibilityToggle />
</FormItem>
<FormItem name={['embeddingStore', 'timeOut']} label="超时时间(秒)">
<InputNumber />
</FormItem>
</>
)}
</div>
),
},
{
label: '提示词配置',
key: 'promptConfig',
children: (
<div className={styles.agentFormContainer}>
<FormItem name={['promptConfig', 'promptTemplate']} label="提示词模板">
<Input.TextArea
style={{ minHeight: 600 }}
placeholder=" &nbsp;自定义提示词模板可嵌入以下变量,将由系统自动进行替换:&#13;&#10;
-&nbsp;{{exemplar}} &nbsp;:替换成few-shot示例示例个数由系统配置&#13;&#10;
-&nbsp;{{question}} &nbsp;:替换成用户问题,拼接了一定的补充信息&#13;&#10;
-&nbsp;{{schema}} &nbsp;:替换成数据语义信息,根据用户问题映射而来"
/>
</FormItem>
</div> </div>
), ),
}, },
@@ -332,12 +474,12 @@ const AgentForm: React.FC<Props> = ({ editAgent, onSaveAgent, onCreateToolBtnCli
<PlusOutlined /> <PlusOutlined />
</Button> </Button>
)} )}
{activeKey === 'llmConfig' && ( {activeKey === 'modelConfig' && (
<Button <Button
type="primary" type="primary"
loading={llmTestLoading} loading={llmTestLoading}
onClick={() => { onClick={() => {
testLLMConnect(formData.llmConfig); testLLMConnect(formData.modelConfig.chatModel);
}} }}
> >

View File

@@ -19,6 +19,12 @@
padding: 20px 0; padding: 20px 0;
} }
.agentFormTitle{
font-size: 16px;
margin-bottom: 20px;
font-weight: 500;
}
.content { .content {
// margin-top: 20px; // margin-top: 20px;
.searchBar { .searchBar {

View File

@@ -65,6 +65,19 @@ export type LlmConfigType = {
timeOut: number; timeOut: number;
}; };
export type EmbeddingModelConfigType = {
apiKey: string;
baseUrl: string;
// logRequests: true,
// logResponses: true,
// maxRetries: number,
// maxToken: number,
modelName: string;
modelPath: string;
provider: string;
vocabularyPath: string;
};
export type MultiTurnConfig = { export type MultiTurnConfig = {
enableMultiTurn: boolean; enableMultiTurn: boolean;
}; };
@@ -84,7 +97,10 @@ export type AgentType = {
status?: 0 | 1; status?: 0 | 1;
enableSearch?: 0 | 1; enableSearch?: 0 | 1;
agentConfig?: AgentConfigType; agentConfig?: AgentConfigType;
llmConfig?: LlmConfigType; modelConfig: {
chatModel: LlmConfigType;
embeddingModel: EmbeddingModelConfigType;
};
multiTurnConfig?: MultiTurnConfig; multiTurnConfig?: MultiTurnConfig;
visualConfig?: VisualConfig; visualConfig?: VisualConfig;
}; };

View File

@@ -476,7 +476,7 @@ const encryptKey = CryptoJS.enc.Hex.parse(
'9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08', '9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08',
); );
export const encryptPassword = (password: string, key?: any) => { export const encryptPassword = (password: string, key?: string) => {
if (!password) { if (!password) {
return password; return password;
} }