From 4b733ab883f0b035e0301ed4b29c6aa70de99f22 Mon Sep 17 00:00:00 2001 From: Germey Date: Mon, 22 Jan 2024 00:40:10 +0800 Subject: [PATCH] update draft knowledge --- src/operators/chatdoc/models.ts | 3 ++ src/pages/chatdoc/Index.vue | 49 +++++++++++++++++++++++++++++++-- src/pages/chatdoc/Knowledge.vue | 46 +++++++++++++++++++++++++++---- src/router/chatdoc.ts | 2 +- src/store/chatdoc/actions.ts | 32 +++++++++++++++++++++ src/store/chatdoc/mutations.ts | 15 ++++++++++ src/store/common/models.ts | 2 ++ 7 files changed, 140 insertions(+), 9 deletions(-) diff --git a/src/operators/chatdoc/models.ts b/src/operators/chatdoc/models.ts index 4116a38..3b90d16 100644 --- a/src/operators/chatdoc/models.ts +++ b/src/operators/chatdoc/models.ts @@ -2,6 +2,9 @@ import { ACTION_CREATE, ACTION_DELETE, ACTION_UPDATE, ROLE_ASSISTANT, ROLE_SYSTE export interface IChatdocRepository { id: string; + name?: string; + description?: string; + documents?: IChatdocDocument[]; } export interface IChatdocDocument { diff --git a/src/pages/chatdoc/Index.vue b/src/pages/chatdoc/Index.vue index b95fd11..0a7be9d 100644 --- a/src/pages/chatdoc/Index.vue +++ b/src/pages/chatdoc/Index.vue @@ -1,22 +1,65 @@ + + diff --git a/src/pages/chatdoc/Knowledge.vue b/src/pages/chatdoc/Knowledge.vue index 023bc83..e698cd3 100644 --- a/src/pages/chatdoc/Knowledge.vue +++ b/src/pages/chatdoc/Knowledge.vue @@ -1,22 +1,58 @@ diff --git a/src/router/chatdoc.ts b/src/router/chatdoc.ts index 7ce8064..496728d 100644 --- a/src/router/chatdoc.ts +++ b/src/router/chatdoc.ts @@ -18,7 +18,7 @@ export default { component: () => import('@/pages/chatdoc/Chat.vue') }, { - path: 'knowledge', + path: 'knowledge/:id', name: ROUTE_CHATDOC_KNOWLEDGE, component: () => import('@/pages/chatdoc/Knowledge.vue') }, diff --git a/src/store/chatdoc/actions.ts b/src/store/chatdoc/actions.ts index c930134..dcf0f0d 100644 --- a/src/store/chatdoc/actions.ts +++ b/src/store/chatdoc/actions.ts @@ -15,6 +15,10 @@ export const setApplications = async ({ commit }: any, payload: IApplication[]): commit('setApplications', payload); }; +export const setRepository = async ({ commit }: any, payload: { repository: IChatdocRepository }): Promise => { + commit('setRepository', payload); +}; + export const getApplications = async ({ commit, rootState @@ -63,9 +67,37 @@ export const getRepositories = async ({ return repositories; }; +export const getRepository = async ( + { commit, state }: ActionContext, + payload: { id: string } +): Promise => { + log(getRepository, 'start to get repository'); + // commit('setGetRepositoryStatus', Status.Request); + const applications = state.applications; + const application = applications?.find( + (application: IApplication) => application.api?.id === API_ID_CHATDOC_REPOSITORIES + ); + const token = application?.credential?.token; + if (!token) { + commit('setRepository', { id: payload.id }); + return Promise.reject('no token'); + } + const repository = ( + await chatdocOperator.getRepository(payload.id, { + token + }) + ).data; + // commit('setGetRepositoryStatus', Status.Success); + log(getRepository, 'get repository success', repository); + commit('setRepository', repository); + return repository; +}; + export default { setApplications, getApplications, getRepositories, + getRepository, + setRepository, resetAll }; diff --git a/src/store/chatdoc/mutations.ts b/src/store/chatdoc/mutations.ts index 73d64c6..b3a6528 100644 --- a/src/store/chatdoc/mutations.ts +++ b/src/store/chatdoc/mutations.ts @@ -20,6 +20,20 @@ export const setRepositories = (state: IChatdocState, payload: IChatdocRepositor state.repositories = payload; }; +export const setRepository = (state: IChatdocState, payload: { repository: IChatdocRepository }): void => { + // find the repository and set it + const { repository } = payload; + const repositories = state.repositories; + if (!repositories) { + return; + } + const index = repositories.findIndex((item: IChatdocRepository) => item.id === repository.id); + if (index === -1) { + return; + } + repositories[index] = repository; +}; + export const setGetRepositoriesStatus = (state: IChatdocState, payload: Status): void => { state.getRepositoriesStatus = payload; }; @@ -28,6 +42,7 @@ export default { setApplications, setGetApplicationsStatus, setRepositories, + setRepository, setGetRepositoriesStatus, resetAll }; diff --git a/src/store/common/models.ts b/src/store/common/models.ts index 073fe91..82b04b6 100644 --- a/src/store/common/models.ts +++ b/src/store/common/models.ts @@ -1,6 +1,7 @@ import { IUser } from '@/operators'; import { IMidjourneyState } from '../midjourney/models'; import { IChatState } from '../chat/models'; +import { IChatdocState } from '../chatdoc/models'; export enum Status { Request = 'Request', @@ -28,4 +29,5 @@ export interface ICommonState { export interface IRootState extends ICommonState { midjourney: IMidjourneyState; chat: IChatState; + chatdoc: IChatdocState; }