Skip to content

Commit 09ee60a

Browse files
author
AceDataCloud
committed
Refine chatdoc and base code interface (#2)
1 parent 28da026 commit 09ee60a

21 files changed

+352
-168
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "fix chatdoc issues",
4+
"packageName": "@acedatacloud/hub",
5+
"email": "germey@acedata.cloud",
6+
"dependentChangeType": "patch"
7+
}

src/components/chatdoc/UploadDocument.vue

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export default defineComponent({
8888
ElMessage.success(this.$t('chatdoc.message.createDocumentSuccess'));
8989
this.dialogVisible = false;
9090
this.$store.dispatch('chatdoc/getDocuments', { repositoryId: this.$route.params.repositoryId });
91+
this.$store.dispatch('chatdoc/getApplication');
9192
})
9293
.catch(() => {
9394
ElMessage.error(this.$t('chatdoc.message.createDocumentError'));

src/components/common/Price.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<template>
22
<div class="price-text">
33
<span v-if="price > 0" class="unfree"
4-
>¥{{ price }} {{ unit ? ` / ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : ''
5-
}}{{ $t('common.message.startPrice') }}
4+
>${{ price }} {{ unit ? ` / ${unit}` : '' }}{{ start ? $t('common.message.startPrice') : '' }}
65
</span>
76
<span v-else class="free">
87
{{ $t('common.message.free') }}
@@ -12,7 +11,6 @@
1211

1312
<script>
1413
import { defineComponent } from 'vue';
15-
1614
export default defineComponent({
1715
name: 'ApiPrice',
1816
props: {

src/constants/action.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export const ACTION_UPDATE = 'update';
33
export const ACTION_DELETE = 'delete';
44
export const ACTION_RETRIEVE = 'retrieve';
55
export const ACTION_RETRIEVE_BATCH = 'retrieve_batch';
6-
export const ACTION_RETRIEVE_ALL = 'retrieve_all';

src/i18n/zh/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import order from './order';
99
import distribution from './distribution';
1010
import user from './user';
1111
import chatdoc from './chatdoc';
12+
import service from './service';
1213

1314
export default {
1415
chat,
16+
service,
1517
chatdoc,
1618
user,
1719
order,

src/i18n/zh/service/button.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default {
2+
learnMore: 'Learn More',
3+
apply: 'Apply Now',
4+
introduction: 'Service Introduction',
5+
apis: 'API Description',
6+
pricing: 'Pricing'
7+
};

src/i18n/zh/service/field.ts

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
price: 'Price',
3+
introduction: 'Introduction',
4+
apis: 'API',
5+
proxies: 'Proxy'
6+
};

src/i18n/zh/service/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import message from './message';
2+
import unit from './unit';
3+
import button from './button';
4+
import field from './field';
5+
import title from './title';
6+
7+
export default {
8+
message,
9+
unit,
10+
button,
11+
field,
12+
title
13+
};

src/i18n/zh/service/message.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
free: 'Free',
3+
around: 'Around',
4+
welcomeCredits: 'Welcome Credits',
5+
appliedCount: 'Number of Applications',
6+
indexTitle: 'Your smart choice for digital services',
7+
indexSubtitle: 'Empower your work and life with standardized excellence in services.',
8+
fromPrice: 'From ',
9+
packages: 'We offer a variety of packages for credits, the more packages you buy, the more discounts you get.',
10+
offer: 'Offer',
11+
partnersTitle: 'Trusted by leading partners'
12+
};

src/i18n/zh/service/title.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
apis: 'API',
3+
proxies: 'Proxy',
4+
packages: 'Packages'
5+
};

src/i18n/zh/service/unit.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default {
2+
credit: 'Credit',
3+
Credit: 'Credit',
4+
credits: 'Credits',
5+
Credits: 'Credits',
6+
call: 'Call',
7+
Call: 'Call',
8+
calls: 'Calls',
9+
Calls: 'Calls',
10+
MB: 'MB',
11+
GB: 'GB'
12+
};

src/models/chatdoc.ts

+31-23
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,40 @@ export interface IChatdocRepository {
1515
conversations?: IChatdocConversation[];
1616
}
1717

18+
export interface IChatdocRepositoryRequest extends IChatdocRepository {
19+
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
20+
}
21+
22+
export interface IChatdocRepositoryResponse extends IChatdocRepository {}
23+
export type IChatdocRepositoriesResponse = {
24+
items: IChatdocRepository[];
25+
count: number;
26+
};
27+
1828
export interface IChatdocDocument {
1929
id: string;
2030
repository_id: string;
2131
file_url: string;
2232
file_name: string;
2333
}
2434

35+
export interface IChatdocDocumentRequest extends IChatdocDocument {
36+
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
37+
callback_url?: string;
38+
}
39+
40+
export interface IChatdocDocumentResponse extends IChatdocDocument {}
41+
42+
export type IChatdocDocumentsResponse = {
43+
items: IChatdocDocument[];
44+
count: number;
45+
};
46+
2547
export interface IChatdocConversation {
2648
id: string;
2749
repository_id: string;
2850
messages: IChatdocMessage[];
51+
question: string;
2952
editing?: boolean;
3053
deleting?: boolean;
3154
}
@@ -44,36 +67,21 @@ export enum IChatdocMessageState {
4467
FAILED = 'failed'
4568
}
4669

47-
export interface IChatdocChatRequest {
70+
export interface IChatdocConversationRequest {
71+
id: string;
4872
repository_id: string;
49-
messages: IChatdocMessage[];
73+
question: string;
5074
temperature?: number;
5175
knowledge_fallback?: boolean;
5276
}
5377

54-
export interface IChatdocDocumentRequest extends IChatdocDocument {
55-
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
56-
callback_url?: string;
57-
}
58-
59-
export interface IChatdocDocumentResponse extends IChatdocDocument {}
60-
61-
export type IChatdocConversationsResponse = IChatdocConversation[];
62-
63-
export interface IChatdocRepositoryRequest extends IChatdocRepository {
64-
action: typeof ACTION_CREATE | typeof ACTION_UPDATE | typeof ACTION_DELETE;
65-
}
66-
67-
export interface IChatdocRepositoryResponse extends IChatdocRepository {}
68-
export type IChatdocRepositoriesResponse = {
69-
items: IChatdocRepository[];
78+
export type IChatdocConversationsResponse = {
79+
items: IChatdocConversation[];
7080
count: number;
7181
};
72-
export type IChatdocDocumentsResponse = IChatdocDocument[];
7382

74-
export interface IChatdocChatResponse {
83+
export interface IChatdocConversationResponse {
84+
id: string;
7585
answer: string;
76-
delta_answer: string;
77-
repository_id?: string;
78-
conversation_id?: string;
86+
delta_answer?: string;
7987
}

src/operators/auth.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { getBaseUrlAuth } from '@/utils';
55

66
class AuthOperator {
77
async refreshToken(payload: IToken): Promise<AxiosResponse<ITokenResponse>> {
8-
return httpClient.post('/token/refresh/', payload);
8+
return httpClient.post('/auth/refresh/', payload);
99
}
1010
}
1111

src/operators/chatdoc.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
IChatdocRepositoriesResponse,
99
IChatdocRepositoryResponse
1010
} from '@/models';
11-
import { ACTION_RETRIEVE_ALL, ACTION_UPDATE, BASE_URL_API } from '@/constants';
11+
import { ACTION_UPDATE, BASE_URL_API } from '@/constants';
1212
import { ACTION_CREATE, ACTION_DELETE, ACTION_RETRIEVE, ACTION_RETRIEVE_BATCH } from '@/constants';
1313

1414
class ChatdocOperator {
@@ -77,7 +77,7 @@ class ChatdocOperator {
7777
return await axios.post(
7878
`/chatdoc/repositories`,
7979
{
80-
action: ACTION_RETRIEVE_ALL
80+
action: ACTION_RETRIEVE_BATCH
8181
},
8282
{
8383
headers: {
@@ -97,7 +97,7 @@ class ChatdocOperator {
9797
return await axios.post(
9898
`/chatdoc/documents`,
9999
{
100-
action: ACTION_RETRIEVE_ALL,
100+
action: ACTION_RETRIEVE_BATCH,
101101
repository_id: repositoryId
102102
},
103103
{
@@ -111,15 +111,19 @@ class ChatdocOperator {
111111
);
112112
}
113113

114-
async getAllConversations(repositoryId: string): Promise<AxiosResponse<IChatdocConversationsResponse>> {
114+
async getAllConversations(
115+
repositoryId: string,
116+
options: { token: string }
117+
): Promise<AxiosResponse<IChatdocConversationsResponse>> {
115118
return await axios.post(
116119
`/chatdoc/conversations`,
117120
{
118-
action: ACTION_RETRIEVE_ALL,
121+
action: ACTION_RETRIEVE_BATCH,
119122
repository_id: repositoryId
120123
},
121124
{
122125
headers: {
126+
authorization: `Bearer ${options.token}`,
123127
accept: 'application/json',
124128
'content-type': 'application/json'
125129
},
@@ -273,16 +277,16 @@ class ChatdocOperator {
273277
);
274278
}
275279

276-
async chat(
277-
payload: { repositoryId: string; question: string; conversationId?: string; knowledgeFallback?: boolean },
280+
async chatConversation(
281+
payload: { repositoryId: string; question: string; id?: string; knowledgeFallback?: boolean },
278282
options: { token: string; stream: (response: IChatdocChatResponse) => void }
279283
): Promise<AxiosResponse<IChatdocChatResponse>> {
280284
return await axios.post(
281-
`/chatdoc/chat`,
285+
`/chatdoc/conversations`,
282286
{
283287
repository_id: payload.repositoryId,
284288
question: payload.question,
285-
conversation_id: payload.conversationId,
289+
id: payload.id,
286290
stateful: true
287291
},
288292
{

src/operators/user.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,25 @@ export interface IInviteesQuery {
1010

1111
class UserOperator {
1212
async getMe(): Promise<AxiosResponse<IUserDetailResponse>> {
13-
return httpClient.get('/me');
13+
return httpClient.get('/users/me');
1414
}
1515

1616
async getInvitees(query: IInviteesQuery): Promise<AxiosResponse<IUserListResponse>> {
17-
return httpClient.get('/me/invitees', {
17+
return httpClient.get('/users/me/invitees', {
1818
params: query
1919
});
2020
}
2121

2222
async updateMe(data: IUser): Promise<AxiosResponse<IUserDetailResponse>> {
23-
return httpClient.put('/me', data);
23+
return httpClient.put('/users/me', data);
2424
}
2525

2626
async getVerify(): Promise<AxiosResponse<IUserDetailResponse>> {
27-
return httpClient.get('/verify');
27+
return httpClient.get('/users/verify');
2828
}
2929

3030
async updateVerify(data: IUser): Promise<AxiosResponse<IUserDetailResponse>> {
31-
return httpClient.put('/verify', data);
31+
return httpClient.put('/users/verify', data);
3232
}
3333
}
3434

src/pages/chatdoc/Conversation.vue

+12-18
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ import { log } from '@/utils';
5555
import { ROUTE_CHATDOC_CONVERSATION } from '@/router';
5656
import axios from 'axios';
5757
import { isJSONString } from '@/utils/is';
58-
import { Status } from '@/models';
58+
import { IService, Status } from '@/models';
5959
import ApplicationStatus from '@/components/application/Status.vue';
60-
import { IChatdocChatResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models';
60+
import { IChatdocConversationResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models';
6161
6262
export default defineComponent({
63-
name: 'ChatdocChat',
63+
name: 'ChatdocConversation',
6464
components: {
6565
Layout,
6666
Conversations,
@@ -92,7 +92,7 @@ export default defineComponent({
9292
repository(): IChatdocRepository | undefined {
9393
return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.repositoryId);
9494
},
95-
conversations() {
95+
conversations(): IChatdocConversation[] | undefined {
9696
return this.repository?.conversations;
9797
},
9898
conversationId(): string | undefined {
@@ -107,29 +107,23 @@ export default defineComponent({
107107
initializing() {
108108
return this.$store.state.chatdoc.status.getApplication === Status.Request;
109109
},
110-
service() {
110+
service(): IService | undefined {
111111
return this.$store.state.chatdoc.service;
112112
}
113113
},
114114
async mounted() {
115115
console.log('start get conversations');
116116
this.loading = true;
117-
this.$store
118-
.dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId })
119-
.then(() => {
120-
this.loading = false;
121-
})
122-
.catch(() => {
123-
this.loading = false;
124-
});
117+
this.$store.dispatch('chatdoc/getConversations', { repositoryId: this.repositoryId }).finally(() => {
118+
this.loading = false;
119+
});
125120
},
126121
methods: {
127122
async onSubmit() {
128123
this.messages.push({
129124
content: this.question,
130125
role: ROLE_USER
131126
});
132-
console.debug('onSubmit', this.question);
133127
await this.onFetchAnswer();
134128
},
135129
async onScrollDown() {
@@ -169,21 +163,21 @@ export default defineComponent({
169163
// request server to get answer
170164
this.answering = true;
171165
chatdocOperator
172-
.chat(
166+
.chatConversation(
173167
{
174168
repositoryId: this.repositoryId,
175169
question,
176-
conversationId: this.conversationId
170+
id: this.conversationId
177171
},
178172
{
179173
token,
180-
stream: (response: IChatdocChatResponse) => {
174+
stream: (response: IChatdocConversationResponse) => {
181175
this.messages[this.messages.length - 1] = {
182176
role: ROLE_ASSISTANT,
183177
content: response.answer,
184178
state: IChatdocMessageState.ANSWERING
185179
};
186-
conversationId = response.conversation_id;
180+
conversationId = response.id;
187181
this.onScrollDown();
188182
}
189183
}

0 commit comments

Comments
 (0)