From d6429be34d2343640d33ce777976be29b8857f0f Mon Sep 17 00:00:00 2001 From: Germey Tsui Date: Sat, 27 Jan 2024 17:49:15 +0800 Subject: [PATCH] update get docs --- src/operators/chatdoc/constants.ts | 1 + src/operators/chatdoc/models.ts | 1 + src/operators/chatdoc/operator.ts | 22 +++++++++++++++++++ src/pages/chatdoc/Knowledge.vue | 2 +- src/store/chatdoc/actions.ts | 34 +++++++++++++++++++++++++++++- 5 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/operators/chatdoc/constants.ts b/src/operators/chatdoc/constants.ts index 37525de..60bf284 100644 --- a/src/operators/chatdoc/constants.ts +++ b/src/operators/chatdoc/constants.ts @@ -1,3 +1,4 @@ export const API_ID_CHATDOC_REPOSITORIES = 'e22e9e3f-5594-4c48-9284-c1847c22c65f'; export const API_ID_CHATDOC_DOCUMENTS = 'afc7917f-d89f-4dc9-95c2-863936b02cad'; +export const API_ID_CHATDOC_CONVERSATIONS = 'afc7917f-d89f-4dc9-95c2-863936b02cad'; export const API_ID_CHATDOC_CHAT = '099eafc8-8167-4557-b8f2-47867ca76e24'; diff --git a/src/operators/chatdoc/models.ts b/src/operators/chatdoc/models.ts index 3b90d16..c864f8c 100644 --- a/src/operators/chatdoc/models.ts +++ b/src/operators/chatdoc/models.ts @@ -39,6 +39,7 @@ export interface IChatdocRepositoryRequest extends IChatdocRepository { export interface IChatdocRepositoryResponse extends IChatdocRepository {} export type IChatdocRepositoriesResponse = IChatdocRepository[]; +export type IChatdocDocumentsResponse = IChatdocDocument[]; export interface IChatdocChatResponse { answer: string; diff --git a/src/operators/chatdoc/operator.ts b/src/operators/chatdoc/operator.ts index 2c0ebc9..4391de8 100644 --- a/src/operators/chatdoc/operator.ts +++ b/src/operators/chatdoc/operator.ts @@ -2,6 +2,7 @@ import axios, { AxiosProgressEvent, AxiosResponse } from 'axios'; import { IChatdocChatResponse, IChatdocDocumentResponse, + IChatdocDocumentsResponse, IChatdocRepositoriesResponse, IChatdocRepositoryResponse } from './models'; @@ -79,6 +80,27 @@ class ChatdocOperator { ); } + async getAllDocuments( + repositoryId: string, + options: { token: string } + ): Promise> { + return await axios.post( + `/chatdoc/documents`, + { + action: ACTION_RETRIEVE_ALL, + repository_id: repositoryId + }, + { + headers: { + authorization: `Bearer ${options.token}`, + accept: 'application/json', + 'content-type': 'application/json' + }, + baseURL: BASE_URL_API + } + ); + } + async getRepositories(ids: string[]): Promise> { return await axios.post( `/chatdoc/repositories`, diff --git a/src/pages/chatdoc/Knowledge.vue b/src/pages/chatdoc/Knowledge.vue index e698cd3..7c544be 100644 --- a/src/pages/chatdoc/Knowledge.vue +++ b/src/pages/chatdoc/Knowledge.vue @@ -41,7 +41,7 @@ export default defineComponent({ async mounted() { this.loading = true; this.$store - .dispatch('chatdoc/getRepository', { id: this.id }) + .dispatch('chatdoc/getDocuments', { repositoryId: this.id }) .then(() => { this.loading = false; }) diff --git a/src/store/chatdoc/actions.ts b/src/store/chatdoc/actions.ts index dcf0f0d..b91c122 100644 --- a/src/store/chatdoc/actions.ts +++ b/src/store/chatdoc/actions.ts @@ -3,7 +3,7 @@ import { IRootState, Status } from '../common/models'; import { ActionContext } from 'vuex'; import { log } from '@/utils/log'; import { IChatdocState } from './models'; -import { IChatdocRepository } from '@/operators/chatdoc/models'; +import { IChatdocDocument, IChatdocRepository } from '@/operators/chatdoc/models'; import { chatdocOperator } from '@/operators/chatdoc/operator'; import { API_ID_CHATDOC_CHAT, @@ -67,6 +67,38 @@ export const getRepositories = async ({ return repositories; }; +export const getDocuments = async ( + { commit, state }: ActionContext, + payload: { repositoryId: string } +): Promise => { + log(getRepositories, 'start to get documents'); + const applications = state.applications; + console.log('applications', applications); + const application = applications?.find( + (application: IApplication) => application.api?.id === API_ID_CHATDOC_DOCUMENTS + ); + console.log('application', application); + const token = application?.credential?.token; + if (!token) { + commit('setRepository', { + id: payload.repositoryId, + documents: [] + }); + return []; + } + const documents = ( + await chatdocOperator.getAllDocuments(payload.repositoryId, { + token + }) + ).data; + log(getRepositories, 'get documents success', documents); + commit('setRepository', { + id: payload.repositoryId, + documents: [] + }); + return documents; +}; + export const getRepository = async ( { commit, state }: ActionContext, payload: { id: string }