From 7228c17d9ec11935719e125fc6987b85a7284485 Mon Sep 17 00:00:00 2001 From: Germey Date: Sun, 17 Mar 2024 21:26:18 +0800 Subject: [PATCH 1/3] update --- src/components/chatdoc/UploadDocument.vue | 1 + src/models/chatdoc.ts | 54 +++++++------ src/operators/auth.ts | 2 +- src/operators/chatdoc.ts | 14 ++-- src/operators/user.ts | 10 +-- src/pages/chatdoc/Conversation.vue | 30 +++----- src/store/chatdoc/actions.ts | 18 ++--- vite.config.ts | 93 +++++++++++++---------- 8 files changed, 120 insertions(+), 102 deletions(-) diff --git a/src/components/chatdoc/UploadDocument.vue b/src/components/chatdoc/UploadDocument.vue index da6e0278..ff362ed5 100644 --- a/src/components/chatdoc/UploadDocument.vue +++ b/src/components/chatdoc/UploadDocument.vue @@ -88,6 +88,7 @@ export default defineComponent({ ElMessage.success(this.$t('chatdoc.message.createDocumentSuccess')); this.dialogVisible = false; this.$store.dispatch('chatdoc/getDocuments', { repositoryId: this.$route.params.repositoryId }); + this.$store.dispatch('chatdoc/getApplication'); }) .catch(() => { ElMessage.error(this.$t('chatdoc.message.createDocumentError')); diff --git a/src/models/chatdoc.ts b/src/models/chatdoc.ts index d54e6d98..17ed38c3 100644 --- a/src/models/chatdoc.ts +++ b/src/models/chatdoc.ts @@ -15,6 +15,16 @@ export interface IChatdocRepository { conversations?: IChatdocConversation[]; } +export interface IChatdocRepositoryRequest extends IChatdocRepository { + action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE; +} + +export interface IChatdocRepositoryResponse extends IChatdocRepository {} +export type IChatdocRepositoriesResponse = { + items: IChatdocRepository[]; + count: number; +}; + export interface IChatdocDocument { id: string; repository_id: string; @@ -22,10 +32,23 @@ export interface IChatdocDocument { file_name: string; } +export interface IChatdocDocumentRequest extends IChatdocDocument { + action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE; + callback_url?: string; +} + +export interface IChatdocDocumentResponse extends IChatdocDocument {} + +export type IChatdocDocumentsResponse = { + items: IChatdocDocument[]; + count: number; +}; + export interface IChatdocConversation { id: string; repository_id: string; messages: IChatdocMessage[]; + question: string; editing?: boolean; deleting?: boolean; } @@ -44,36 +67,21 @@ export enum IChatdocMessageState { FAILED = 'failed' } -export interface IChatdocChatRequest { +export interface IChatdocConversationRequest { + id: string; repository_id: string; - messages: IChatdocMessage[]; + question: string; temperature?: number; knowledge_fallback?: boolean; } -export interface IChatdocDocumentRequest extends IChatdocDocument { - action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE; - callback_url?: string; -} - -export interface IChatdocDocumentResponse extends IChatdocDocument {} - -export type IChatdocConversationsResponse = IChatdocConversation[]; - -export interface IChatdocRepositoryRequest extends IChatdocRepository { - action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE; -} - -export interface IChatdocRepositoryResponse extends IChatdocRepository {} -export type IChatdocRepositoriesResponse = { - items: IChatdocRepository[]; +export type IChatdocConversationsResponse = { + items: IChatdocConversation[]; count: number; }; -export type IChatdocDocumentsResponse = IChatdocDocument[]; -export interface IChatdocChatResponse { +export interface IChatdocConversationResponse { + id: string; answer: string; - delta_answer: string; - repository_id?: string; - conversation_id?: string; + delta_answer?: string; } diff --git a/src/operators/auth.ts b/src/operators/auth.ts index 8fa249bb..036d8b1f 100644 --- a/src/operators/auth.ts +++ b/src/operators/auth.ts @@ -5,7 +5,7 @@ import { getBaseUrlAuth } from '@/utils'; class AuthOperator { async refreshToken(payload: IToken): Promise> { - return httpClient.post('/token/refresh/', payload); + return httpClient.post('/auth/refresh/', payload); } } diff --git a/src/operators/chatdoc.ts b/src/operators/chatdoc.ts index f207d687..5c28130f 100644 --- a/src/operators/chatdoc.ts +++ b/src/operators/chatdoc.ts @@ -111,7 +111,10 @@ class ChatdocOperator { ); } - async getAllConversations(repositoryId: string): Promise> { + async getAllConversations( + repositoryId: string, + options: { token: string } + ): Promise> { return await axios.post( `/chatdoc/conversations`, { @@ -120,6 +123,7 @@ class ChatdocOperator { }, { headers: { + authorization: `Bearer ${options.token}`, accept: 'application/json', 'content-type': 'application/json' }, @@ -273,16 +277,16 @@ class ChatdocOperator { ); } - async chat( - payload: { repositoryId: string; question: string; conversationId?: string; knowledgeFallback?: boolean }, + async chatConversation( + payload: { repositoryId: string; question: string; id?: string; knowledgeFallback?: boolean }, options: { token: string; stream: (response: IChatdocChatResponse) => void } ): Promise> { return await axios.post( - `/chatdoc/chat`, + `/chatdoc/conversations`, { repository_id: payload.repositoryId, question: payload.question, - conversation_id: payload.conversationId, + id: payload.id, stateful: true }, { diff --git a/src/operators/user.ts b/src/operators/user.ts index 5defce45..477fa450 100644 --- a/src/operators/user.ts +++ b/src/operators/user.ts @@ -10,25 +10,25 @@ export interface IInviteesQuery { class UserOperator { async getMe(): Promise> { - return httpClient.get('/me'); + return httpClient.get('/users/me'); } async getInvitees(query: IInviteesQuery): Promise> { - return httpClient.get('/me/invitees', { + return httpClient.get('/users/me/invitees', { params: query }); } async updateMe(data: IUser): Promise> { - return httpClient.put('/me', data); + return httpClient.put('/users/me', data); } async getVerify(): Promise> { - return httpClient.get('/verify'); + return httpClient.get('/users/verify'); } async updateVerify(data: IUser): Promise> { - return httpClient.put('/verify', data); + return httpClient.put('/users/verify', data); } } diff --git a/src/pages/chatdoc/Conversation.vue b/src/pages/chatdoc/Conversation.vue index 6f7e1b18..e959d1f0 100644 --- a/src/pages/chatdoc/Conversation.vue +++ b/src/pages/chatdoc/Conversation.vue @@ -55,12 +55,12 @@ import { log } from '@/utils'; import { ROUTE_CHATDOC_CONVERSATION } from '@/router'; import axios from 'axios'; import { isJSONString } from '@/utils/is'; -import { Status } from '@/models'; +import { IService, Status } from '@/models'; import ApplicationStatus from '@/components/application/Status.vue'; -import { IChatdocChatResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models'; +import { IChatdocConversationResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models'; export default defineComponent({ - name: 'ChatdocChat', + name: 'ChatdocConversation', components: { Layout, Conversations, @@ -92,7 +92,7 @@ export default defineComponent({ repository(): IChatdocRepository | undefined { return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.repositoryId); }, - conversations() { + conversations(): IChatdocConversation[] | undefined { return this.repository?.conversations; }, conversationId(): string | undefined { @@ -107,21 +107,16 @@ export default defineComponent({ initializing() { return this.$store.state.chatdoc.status.getApplication === Status.Request; }, - service() { + service(): IService | undefined { return this.$store.state.chatdoc.service; } }, async mounted() { console.log('start get conversations'); this.loading = true; - this.$store - .dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId }) - .then(() => { - this.loading = false; - }) - .catch(() => { - this.loading = false; - }); + this.$store.dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId }).finally(() => { + this.loading = false; + }); }, methods: { async onSubmit() { @@ -129,7 +124,6 @@ export default defineComponent({ content: this.question, role: ROLE_USER }); - console.debug('onSubmit', this.question); await this.onFetchAnswer(); }, async onScrollDown() { @@ -169,21 +163,21 @@ export default defineComponent({ // request server to get answer this.answering = true; chatdocOperator - .chat( + .chatConversation( { repositoryId: this.repositoryId, question, - conversationId: this.conversationId + id: this.conversationId }, { token, - stream: (response: IChatdocChatResponse) => { + stream: (response: IChatdocConversationResponse) => { this.messages[this.messages.length - 1] = { role: ROLE_ASSISTANT, content: response.answer, state: IChatdocMessageState.ANSWERING }; - conversationId = response.conversation_id; + conversationId = response.id; this.onScrollDown(); } } diff --git a/src/store/chatdoc/actions.ts b/src/store/chatdoc/actions.ts index 8cf2dfc0..7db21369 100644 --- a/src/store/chatdoc/actions.ts +++ b/src/store/chatdoc/actions.ts @@ -2,15 +2,7 @@ import { IRootState } from '../common/models'; import { ActionContext } from 'vuex'; import { log } from '@/utils/log'; import { IChatdocState } from './models'; -import { - IApplication, - IChatdocConversation, - IChatdocDocument, - IChatdocRepositoriesResponse, - IChatdocRepository, - IService, - Status -} from '@/models'; +import { IApplication, IChatdocConversation, IChatdocDocument, IChatdocRepository, IService, Status } from '@/models'; import { chatdocOperator, applicationOperator, serviceOperator } from '@/operators'; import { CHATDOC_SERVICE_ID } from '@/constants'; @@ -195,7 +187,7 @@ export const getDocuments = async ( await chatdocOperator.getAllDocuments(payload.repositoryId, { token }) - ).data; + ).data.items; log(getRepositories, 'get documents success', documents); commit('setRepository', { id: payload.repositoryId, @@ -219,7 +211,11 @@ export const getConversations = async ( }); return []; } - const conversations = (await chatdocOperator.getAllConversations(payload.repositoryId)).data; + const conversations = ( + await chatdocOperator.getAllConversations(payload.repositoryId, { + token + }) + ).data.items; log(getConversations, 'get conversations success', conversations); commit('setRepository', { id: payload.repositoryId, diff --git a/vite.config.ts b/vite.config.ts index c305ecab..174200bf 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,50 +1,65 @@ -import { defineConfig } from 'vite'; +import { ConfigEnv, defineConfig, loadEnv } from 'vite'; import vue from '@vitejs/plugin-vue'; import replace from '@rollup/plugin-replace'; import { string } from 'rollup-plugin-string'; import * as path from 'path'; -export default defineConfig({ - server: { - host: 'localhost', - port: 8080, - proxy: { - '/api': { - target: 'https://platform.acedata.cloud', - changeOrigin: true - }, - '/oauth2': { - target: 'https://auth.acedata.cloud', - changeOrigin: true +export default defineConfig((config: ConfigEnv) => { + process.env = { ...process.env, ...loadEnv(config.mode, process.cwd()) }; + return { + server: { + host: 'localhost', + port: 8084, + proxy: { + '/api/v1/auth': { + target: process.env.VITE_BASE_URL_AUTH, + changeOrigin: true + }, + '/api/v1/users': { + target: process.env.VITE_BASE_URL_AUTH, + changeOrigin: true + }, + '/oauth2/v1/token': { + target: process.env.VITE_BASE_URL_AUTH, + changeOrigin: true + }, + '/api': { + target: process.env.VITE_BASE_URL_PLATFORM, + changeOrigin: true + }, + '/static': { + target: process.env.VITE_BASE_URL_PLATFORM, + changeOrigin: true + } } - } - }, - plugins: [ - vue(), - string({ - include: ['**/*.md', '**/*.tpl', '**/*.theme'] - }), - replace({ - preventAssignment: true - }) - ], - resolve: { - alias: { - '@': path.resolve(__dirname, './src') - } - }, - build: { - sourcemap: false, - rollupOptions: { - output: { - manualChunks(id) { - if (id.includes('node_modules')) { - const modules = ['@vue', 'highlight.js', 'element-plus', 'axios']; - const chunk = modules.find((module) => id.includes(module)); - return chunk ? `vendor-${chunk}` : 'vendor-others'; + }, + plugins: [ + vue(), + string({ + include: ['**/*.md', '**/*.tpl', '**/*.theme'] + }), + replace({ + preventAssignment: true + }) + ], + resolve: { + alias: { + '@': path.resolve(__dirname, './src') + } + }, + build: { + sourcemap: false, + rollupOptions: { + output: { + manualChunks(id) { + if (id.includes('node_modules')) { + const modules = ['@vue', 'element-plus', 'axios', 'highlight.js']; + const chunk = modules.find((module) => id.includes(module)); + return chunk ? `vendor-${chunk}` : 'vendor-others'; + } } } } } - } + }; }); From 250d04bf2a7a3b02d543f2c6f7c3ec951931ec53 Mon Sep 17 00:00:00 2001 From: Germey Date: Sun, 17 Mar 2024 21:27:25 +0800 Subject: [PATCH 2/3] update --- ...datacloud-hub-5d9432a5-29cd-4a38-8d5e-f28e83e7ca73.json | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 change/@acedatacloud-hub-5d9432a5-29cd-4a38-8d5e-f28e83e7ca73.json diff --git a/change/@acedatacloud-hub-5d9432a5-29cd-4a38-8d5e-f28e83e7ca73.json b/change/@acedatacloud-hub-5d9432a5-29cd-4a38-8d5e-f28e83e7ca73.json new file mode 100644 index 00000000..be4c04ff --- /dev/null +++ b/change/@acedatacloud-hub-5d9432a5-29cd-4a38-8d5e-f28e83e7ca73.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "fix chatdoc issues", + "packageName": "@acedatacloud/hub", + "email": "germey@acedata.cloud", + "dependentChangeType": "patch" +} From e586e516bcc78bfa069b3d580929936e6c5886cd Mon Sep 17 00:00:00 2001 From: Germey Date: Mon, 18 Mar 2024 00:47:35 +0800 Subject: [PATCH 3/3] add service --- src/components/common/Price.vue | 4 +- src/constants/action.ts | 1 - src/i18n/zh/index.ts | 2 + src/i18n/zh/service/button.ts | 7 ++ src/i18n/zh/service/field.ts | 6 ++ src/i18n/zh/service/index.ts | 13 +++ src/i18n/zh/service/message.ts | 12 +++ src/i18n/zh/service/title.ts | 5 + src/i18n/zh/service/unit.ts | 12 +++ src/operators/chatdoc.ts | 8 +- src/pages/console/application/Buy.vue | 144 +++++++++++++++++++++++-- src/pages/console/application/List.vue | 69 +++++------- src/router/chatdoc.ts | 8 +- 13 files changed, 225 insertions(+), 66 deletions(-) create mode 100644 src/i18n/zh/service/button.ts create mode 100644 src/i18n/zh/service/field.ts create mode 100644 src/i18n/zh/service/index.ts create mode 100644 src/i18n/zh/service/message.ts create mode 100644 src/i18n/zh/service/title.ts create mode 100644 src/i18n/zh/service/unit.ts diff --git a/src/components/common/Price.vue b/src/components/common/Price.vue index 25eee18c..e50d0e32 100644 --- a/src/components/common/Price.vue +++ b/src/components/common/Price.vue @@ -1,8 +1,7 @@