Skip to content

Commit

Permalink
update get docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey Tsui committed Jan 27, 2024
1 parent b6c2f3f commit d6429be
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/operators/chatdoc/constants.ts
Original file line number Diff line number Diff line change
@@ -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';
1 change: 1 addition & 0 deletions src/operators/chatdoc/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions src/operators/chatdoc/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { AxiosProgressEvent, AxiosResponse } from 'axios';
import {
IChatdocChatResponse,
IChatdocDocumentResponse,
IChatdocDocumentsResponse,
IChatdocRepositoriesResponse,
IChatdocRepositoryResponse
} from './models';
Expand Down Expand Up @@ -79,6 +80,27 @@ class ChatdocOperator {
);
}

async getAllDocuments(
repositoryId: string,
options: { token: string }
): Promise<AxiosResponse<IChatdocDocumentsResponse>> {
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<AxiosResponse<IChatdocRepositoriesResponse>> {
return await axios.post(
`/chatdoc/repositories`,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chatdoc/Knowledge.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
})
Expand Down
34 changes: 33 additions & 1 deletion src/store/chatdoc/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -67,6 +67,38 @@ export const getRepositories = async ({
return repositories;
};

export const getDocuments = async (
{ commit, state }: ActionContext<IChatdocState, IRootState>,
payload: { repositoryId: string }
): Promise<IChatdocDocument[]> => {
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<IChatdocState, IRootState>,
payload: { id: string }
Expand Down

0 comments on commit d6429be

Please sign in to comment.