Skip to content

Commit

Permalink
Merge pull request #41 from eosphoros-ai/feat/agent
Browse files Browse the repository at this point in the history
- agent
- knowledge UI upgrade
  • Loading branch information
Aralhi authored Oct 18, 2023
2 parents 583a347 + c0c02a9 commit 2576b12
Show file tree
Hide file tree
Showing 51 changed files with 2,149 additions and 1,861 deletions.
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).


## Devlop Mode

### Getting Started

First, Config Server Url:
next.config.js
```javascript
const nextConfig = {
output: 'export',
experimental: {
esmExternals: 'loose'
},
typescript: {
ignoreBuildErrors: true
},
env: {
API_BASE_URL: process.env.API_BASE_URL || your server url
},
trailingSlash: true
}

```js
const nextConfig = {
output: 'export',
experimental: {
esmExternals: 'loose',
},
typescript: {
ignoreBuildErrors: true,
},
env: {
API_BASE_URL: process.env.API_BASE_URL || 'your server url',
},
trailingSlash: true,
};
```

Second, run the development server:
Expand All @@ -39,19 +40,23 @@ You can start editing the page by modifying `app/page.tsx`. The page auto-update
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

Next.js Documentation - learn about Next.js features and API.
Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

## Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

## Product Mode

### Use In DB-GPT

```bash
npm run compile

Expand Down
33 changes: 22 additions & 11 deletions app/chat-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ import { createContext, useEffect, useMemo, useState } from 'react';
import { apiInterceptors, getDialogueList, getUsableModels } from '@/client/api';
import { useRequest } from 'ahooks';
import { useRouter } from 'next/router';
import { DialogueListResponse } from '@/types/chart';
import { DialogueListResponse, IChatDialogueSchema } from '@/types/chat';
import { useSearchParams } from 'next/navigation';

interface IChatContext {
isContract?: boolean;
isMenuExpand?: boolean;
scene: string;
scene: IChatDialogueSchema['chat_mode'] | (string & {});
chatId: string;
model: string;
dbParam?: string;
modelList: Array<string>;
setModel: (val: string) => void;
agentList: string[];
dialogueList?: DialogueListResponse;
setAgentList?: (val: string[]) => void;
setModel: (val: string) => void;
setIsContract: (val: boolean) => void;
setIsMenuExpand: (val: boolean) => void;
setDbParam: (val: string) => void;
Expand All @@ -28,8 +31,10 @@ const ChatContext = createContext<IChatContext>({
modelList: [],
model: '',
dbParam: undefined,
setModel: () => {},
dialogueList: [],
agentList: [],
setAgentList: () => {},
setModel: () => {},
setIsContract: () => {},
setIsMenuExpand: () => {},
setDbParam: () => void 0,
Expand All @@ -38,11 +43,15 @@ const ChatContext = createContext<IChatContext>({
});

const ChatContextProvider = ({ children }: { children: React.ReactElement }) => {
const { query: { id = '', scene = '' } = {} } = useRouter();
const searchParams = useSearchParams();
const chatId = searchParams?.get('id') ?? '';
const scene = searchParams?.get('scene') ?? '';
const db_param = searchParams?.get('db_param') ?? '';
const [isContract, setIsContract] = useState(false);
const [model, setModel] = useState<string>('');
const [isMenuExpand, setIsMenuExpand] = useState<boolean>(scene !== 'chat_dashboard');
const [dbParam, setDbParam] = useState<string>();
const [dbParam, setDbParam] = useState<string>(db_param);
const [agentList, setAgentList] = useState<string[]>([]);

const {
run: queryDialogueList,
Expand All @@ -66,17 +75,19 @@ const ChatContextProvider = ({ children }: { children: React.ReactElement }) =>
setModel(modelList[0]);
}, [modelList, modelList?.length]);

const currentDialogue = useMemo(() => dialogueList.find((item: any) => item.conv_uid === id), [id, dialogueList]);
const currentDialogue = useMemo(() => dialogueList.find((item: any) => item.conv_uid === chatId), [chatId, dialogueList]);
const contextValue = {
isContract,
isMenuExpand,
scene: scene as string,
chatId: id as string,
scene,
chatId,
modelList,
model,
dbParam,
setModel,
dbParam: dbParam || db_param,
dialogueList,
agentList,
setAgentList,
setModel,
setIsContract,
setIsMenuExpand,
setDbParam,
Expand Down
39 changes: 36 additions & 3 deletions app/i18n.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { STORAGE_LANG_KEY } from '@/constant';
import i18n from 'i18next';
import { initReactI18next } from 'react-i18next';

Expand All @@ -9,7 +8,8 @@ const resources = {
space: 'space',
Vector: 'Vector',
Owner: 'Owner',
Docs: 'Docs',
Count: 'Count',
File_type_Invalid: 'The file type is invalid',
Knowledge_Space_Config: 'Knowledge Space Config',
Choose_a_Datasource_type: 'Choose a Datasource type',
Setup_the_Datasource: 'Setup the Datasource',
Expand Down Expand Up @@ -95,8 +95,12 @@ const resources = {
create_model: 'Create Model',
model_select_tips: 'Please select a model',
submit: 'Submit',
close: 'Close',
start_model_success: 'Start model success',
download_model_tip: 'Please download model first.',
Plugins: 'Plugins',
try_again: 'Try again',
no_data: 'No data',
Open_Sidebar: 'Unfold',
cancel: 'Cancel',
Edit_Success: 'Edit Success',
Expand Down Expand Up @@ -134,6 +138,17 @@ const resources = {
Copry_error: 'Copy failed',
Click_Select: 'Click&Select',
Quick_Start: 'Quick Start',
Select_Plugins: 'Select Plugins',
Search: 'Search',
Update_From_Github: 'Upload From Github',
Reset: 'Reset',
Upload: 'Upload',
Market_Plugins: 'Market Plugin',
My_Plugins: 'My Plugins',
Del_Knowledge_Tips: 'Do you want delete the knowledge',
Del_Document_Tips: 'Do you want delete the Document',
Tips: 'Tips',
Limit_Upload_File_Count_Tips: 'Only one file can be uploaded at a time',
},
},
zh: {
Expand All @@ -142,7 +157,8 @@ const resources = {
space: '知识库',
Vector: '向量',
Owner: '创建人',
Docs: '文档数',
Count: '文档数',
File_type_Invalid: '文件类型错误',
Knowledge_Space_Config: '知识库配置',
Choose_a_Datasource_type: '选择数据源类型',
Setup_the_Datasource: '设置数据源',
Expand Down Expand Up @@ -181,6 +197,7 @@ const resources = {
Delete: '删除',
Operation: '操作',
Submit: '提交',
close: '关闭',
Chunks: '切片',
Content: '内容',
Meta_Data: '元数据',
Expand Down Expand Up @@ -228,6 +245,9 @@ const resources = {
submit: '提交',
start_model_success: '启动模型成功',
download_model_tip: '请先下载模型!',
Plugins: '插件列表',
try_again: '刷新重试',
no_data: '暂无数据',
Prompt: '提示语',
Open_Sidebar: '展开',
cancel: '取消',
Expand Down Expand Up @@ -266,6 +286,17 @@ const resources = {
Copry_error: '复制失败',
Click_Select: '点击选择',
Quick_Start: '快速开始',
Select_Plugins: '选择插件',
Search: '搜索',
Reset: '重置',
Update_From_Github: '更新Github插件',
Upload: '上传',
Market_Plugins: '插件市场',
My_Plugins: '我的插件',
Del_Knowledge_Tips: '你确定删除该知识库吗',
Del_Document_Tips: '你确定删除该文档吗',
Tips: '提示',
Limit_Upload_File_Count_Tips: '一次只能上传一个文件',
},
},
};
Expand All @@ -278,4 +309,6 @@ i18n.use(initReactI18next).init({
},
});

export type I18nKeyMapper = (typeof resources)['en']['translation'];

export default i18n;
81 changes: 80 additions & 1 deletion client/api/request.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AxiosRequestConfig } from 'axios';
import { GET, POST } from '.';
import { DbListResponse, DbSupportTypeResponse, PostDbParams, ChatFeedBackSchema } from '@/types/db';
import { DialogueListResponse, IChatDialogueSchema, NewDialogueParam, SceneResponse, ChatHistoryResponse } from '@/types/chart';
import { DialogueListResponse, IChatDialogueSchema, NewDialogueParam, SceneResponse, ChatHistoryResponse } from '@/types/chat';
import { IModelData, StartModelParams, BaseModelParams, SupportModel } from '@/types/model';
import {
GetEditorSQLRoundRequest,
Expand All @@ -11,6 +11,18 @@ import {
PostEditorSQLRunParams,
PostSQLEditorSubmitParams,
} from '@/types/editor';
import { PostAgentHubUpdateParams, PostAgentQueryParams, PostAgentPluginResponse, PostAgentMyPluginResponse } from '@/types/agent';
import {
AddKnowledgeParams,
ArgumentsParams,
ChunkListParams,
DocumentParams,
IArguments,
IChunkList,
IDocument,
IDocumentResponse,
IKnowLedge,
} from '@/types/knowledge';

/** App */
export const postScenes = () => {
Expand Down Expand Up @@ -104,6 +116,47 @@ export const getEditorSql = (id: string, round: string | number) => {
};

/** knowledge */
export const getArguments = (knowledgeName: string) => {
return POST<any, IArguments>(`/knowledge/${knowledgeName}/arguments`, {});
};
export const saveArguments = (knowledgeName: string, data: ArgumentsParams) => {
return POST<ArgumentsParams, IArguments>(`/knowledge/${knowledgeName}/argument/save`, data);
};

export const getKnowledgeList = () => {
return POST<any, Array<IKnowLedge>>('/knowledge/space/list', {});
};
export const getDocumentList = (knowLedgeName: string, data: Record<string, number>) => {
return POST<Record<string, number>, IDocumentResponse>(`/knowledge/${knowLedgeName}/document/list`, data);
};

export const addDocument = (knowledgeName: string, data: DocumentParams) => {
return POST<DocumentParams, number>(`/knowledge/${knowledgeName}/document/add`, data);
};

export const addKnowledge = (data: AddKnowledgeParams) => {
return POST<AddKnowledgeParams, Array<any>>(`/knowledge/space/add`, data);
};

export const syncDocument = (knowLedgeName: string, data: Record<string, Array<number>>) => {
return POST<Record<string, Array<number>>, string | null>(`/knowledge/${knowLedgeName}/document/sync`, data);
};

export const uploadDocument = (knowLedgeName: string, data: FormData) => {
return POST<FormData, number>(`/knowledge/${knowLedgeName}/document/upload`, data);
};

export const getChunkList = (spaceName: string, data: ChunkListParams) => {
return POST<ChunkListParams, IChunkList>(`/knowledge/${spaceName}/chunk/list`, data);
};

export const delDocument = (knowledgeName: string, data: Record<string, string>) => {
return POST<Record<string, string>, null>(`/knowledge/${knowledgeName}/document/delete`, data);
};

export const delKnowledge = (data: Record<string, string>) => {
return POST<Record<string, string>, null>(`/knowledge/space/delete`, data);
};

/** models */
export const getModelList = () => {
Expand All @@ -122,6 +175,32 @@ export const getSupportModels = () => {
return GET<null, Array<SupportModel>>('/api/v1/worker/model/params');
};

/** Agent */
export const postAgentQuery = (data: PostAgentQueryParams) => {
return POST<PostAgentQueryParams, PostAgentPluginResponse>('/api/v1/agent/query', data);
};
export const postAgentHubUpdate = (data?: PostAgentHubUpdateParams) => {
return POST<PostAgentHubUpdateParams>('/api/v1/agent/hub/update', data ?? { channel: '', url: '', branch: '', authorization: '' });
};
export const postAgentMy = (user?: string) => {
return POST<undefined, PostAgentMyPluginResponse>('/api/v1/agent/my', undefined, { params: { user } });
};
export const postAgentInstall = (pluginName: string, user?: string) => {
return POST('/api/v1/agent/install', undefined, { params: { plugin_name: pluginName, user }, timeout: 60000 });
};
export const postAgentUninstall = (pluginName: string, user?: string) => {
return POST('/api/v1/agent/uninstall', undefined, { params: { plugin_name: pluginName, user }, timeout: 60000 });
};
export const postAgentUpload = (user = '', data: FormData, config?: Omit<AxiosRequestConfig, 'headers'>) => {
return POST<FormData>('/api/v1/personal/agent/upload', data, {
params: { user },
headers: {
'Content-Type': 'multipart/form-data',
},
...config,
});
};

/** chat feedback **/
export const getChatFeedBackSelect = () => {
return GET<null, Record<string, string>>(`/api/v1/feedback/select`, undefined);
Expand Down
4 changes: 4 additions & 0 deletions client/api/tools/interceptors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export const apiInterceptors = <T = any, D = any>(promise: Promise<ApiResponse<T
if (ignoreCodes === '*' || (data.err_code && ignoreCodes && ignoreCodes.includes(data.err_code))) {
return [null, data.data, data, response];
} else {
notification.error({
message: `Request error`,
description: data?.err_msg ?? 'The interface is abnormal. Please try again later',
});
throw new Error(data?.err_msg || 'The interface is abnormal. Please try again later');
}
}
Expand Down
Loading

0 comments on commit 2576b12

Please sign in to comment.