wrong chat
This commit is contained in:
1 parent
6a16b1a16a
commit
dd7d0b0a5d
2 files changed
+23
-20
No files matched your search
@@ -68,7 +68,7 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElSkeleton, ElInput } from 'element-plus';
|
import { ElSkeleton, ElInput } from 'element-plus';
|
||||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||||
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router/constants';
|
import { ROUTE_CHAT_CONVERSATION } from '@/router/constants';
|
||||||
import { chatOperator } from '@/operators';
|
import { chatOperator } from '@/operators';
|
||||||
import { IChatConversation } from '@/operators/chat/models';
|
import { IChatConversation } from '@/operators/chat/models';
|
||||||
import { Status } from '@/store/common/models';
|
import { Status } from '@/store/common/models';
|
||||||
|
|||||||
@@ -63,15 +63,18 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
messages() {
|
messages() {
|
||||||
return (
|
return this.$store.state.chat.conversations?.find(
|
||||||
this.$store.state.chat.conversations?.find(
|
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
||||||
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
)?.messages;
|
||||||
)?.messages || []
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
conversationId(): string | undefined {
|
conversationId(): string | undefined {
|
||||||
return this.$route.params.id?.toString();
|
return this.$route.params.id?.toString();
|
||||||
},
|
},
|
||||||
|
conversation() {
|
||||||
|
return this.$store.state.chat.conversations?.find(
|
||||||
|
(conversation: IChatConversation) => conversation.id === this.conversationId
|
||||||
|
);
|
||||||
|
},
|
||||||
application() {
|
application() {
|
||||||
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
|
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
|
||||||
},
|
},
|
||||||
@@ -85,9 +88,21 @@ export default defineComponent({
|
|||||||
return this.$store.state.chat.getApplicationsStatus === Status.Request;
|
return this.$store.state.chat.getApplicationsStatus === Status.Request;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
conversationId() {
|
||||||
|
if (!this.conversation) {
|
||||||
|
this.onCreateNewConversation(this.conversationId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
if (!this.conversation) {
|
||||||
|
this.onCreateNewConversation(this.conversationId);
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onCreateNewConversation() {
|
async onCreateNewConversation(id?: string) {
|
||||||
const newConversationId = uuid();
|
const newConversationId = id || uuid();
|
||||||
await this.$router.push({
|
await this.$router.push({
|
||||||
name: ROUTE_CHAT_CONVERSATION,
|
name: ROUTE_CHAT_CONVERSATION,
|
||||||
params: {
|
params: {
|
||||||
@@ -117,10 +132,6 @@ export default defineComponent({
|
|||||||
this.question = '';
|
this.question = '';
|
||||||
await this.onFetchAnswer();
|
await this.onFetchAnswer();
|
||||||
},
|
},
|
||||||
async onFetchHistory(id?: string) {
|
|
||||||
const { data: data } = await chatOperator.getConversation(id || this.conversationId);
|
|
||||||
this.messages = data.messages || [];
|
|
||||||
},
|
|
||||||
async onFetchAnswer() {
|
async onFetchAnswer() {
|
||||||
const token = this.application?.credential?.token;
|
const token = this.application?.credential?.token;
|
||||||
const endpoint = this.application?.api?.endpoint;
|
const endpoint = this.application?.api?.endpoint;
|
||||||
@@ -153,14 +164,6 @@ export default defineComponent({
|
|||||||
content: response.answer,
|
content: response.answer,
|
||||||
state: IChatMessageState.ANSWERING
|
state: IChatMessageState.ANSWERING
|
||||||
};
|
};
|
||||||
if (!this.conversationId) {
|
|
||||||
this.$router.push({
|
|
||||||
name: ROUTE_CHAT_CONVERSATION,
|
|
||||||
params: {
|
|
||||||
id: response.conversation_id
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user