Skip to content

Commit

Permalink
update draft knowledge
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Jan 21, 2024
1 parent 0461c79 commit 4b733ab
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/operators/chatdoc/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
49 changes: 46 additions & 3 deletions src/pages/chatdoc/Index.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,65 @@
<template>
<layout>
<template #chatdoc> Index </template>
<template #chatdoc>
<el-card @click="onCreate">
<font-awesome-icon :icon="['fas', 'book']" />
</el-card>
<el-card
v-for="(repository, repositoryIndex) in repositories"
:key="repositoryIndex"
class="repository"
@click="onClick(repository)"
>
{{ repository.id }}
</el-card>
</template>
</layout>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Chatdoc.vue';
import { ElCard } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IChatdocRepository } from '@/operators';
import { ROUTE_CHATDOC_KNOWLEDGE } from '@/router';
export default defineComponent({
name: 'ChatdocKnowledge',
components: {
Layout
Layout,
ElCard,
FontAwesomeIcon
},
data() {
return {};
},
computed: {
repositories() {
return this.$store.state.chatdoc.repositories;
}
},
async mounted() {},
methods: {}
methods: {
onCreate() {
console.log('onCreate');
},
onClick(repository: IChatdocRepository) {
console.log('onClick', repository);
this.$router.push({
name: ROUTE_CHATDOC_KNOWLEDGE,
params: {
id: repository.id
}
});
}
}
});
</script>

<style lang="scss" scoped>
.repository {
width: 300px;
margin-bottom: 20px;
}
</style>
46 changes: 41 additions & 5 deletions src/pages/chatdoc/Knowledge.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,58 @@
<template>
<layout>
<template #chatdoc> Knowledge </template>
<template #chatdoc>
<el-button @click="onUpload">upload</el-button>
<el-card v-for="(document, documentIndex) in documents" :key="documentIndex" class="document">
{{ document.id }}
</el-card>
<el-alert v-if="documents?.length === 0" type="info" description="no documents" />
</template>
</layout>
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Chatdoc.vue';
import { IChatdocRepository } from '@/operators';
import { ElCard, ElButton, ElAlert } from 'element-plus';
export default defineComponent({
name: 'ChatdocKnowledge',
components: {
Layout
Layout,
ElButton,
ElCard,
ElAlert
},
data() {
return {};
return {
loading: false,
id: this.$route.params.id.toString()
};
},
async mounted() {},
methods: {}
computed: {
repository(): IChatdocRepository | undefined {
return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.id);
},
documents() {
return this.repository?.documents;
}
},
async mounted() {
this.loading = true;
this.$store
.dispatch('chatdoc/getRepository', { id: this.id })
.then(() => {
this.loading = false;
})
.catch(() => {
this.loading = false;
});
},
methods: {
onUpload() {
console.log('onUpload');
}
}
});
</script>
2 changes: 1 addition & 1 deletion src/router/chatdoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
},
Expand Down
32 changes: 32 additions & 0 deletions src/store/chatdoc/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
commit('setRepository', payload);
};

export const getApplications = async ({
commit,
rootState
Expand Down Expand Up @@ -63,9 +67,37 @@ export const getRepositories = async ({
return repositories;
};

export const getRepository = async (
{ commit, state }: ActionContext<IChatdocState, IRootState>,
payload: { id: string }
): Promise<IChatdocRepository> => {
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
};
15 changes: 15 additions & 0 deletions src/store/chatdoc/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand All @@ -28,6 +42,7 @@ export default {
setApplications,
setGetApplicationsStatus,
setRepositories,
setRepository,
setGetRepositoriesStatus,
resetAll
};
2 changes: 2 additions & 0 deletions src/store/common/models.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -28,4 +29,5 @@ export interface ICommonState {
export interface IRootState extends ICommonState {
midjourney: IMidjourneyState;
chat: IChatState;
chatdoc: IChatdocState;
}

0 comments on commit 4b733ab

Please sign in to comment.