add responding
This commit is contained in:
1 parent
48e6d1bfb4
commit
7ca606ae20
4 files changed
+44
-49
No files matched your search
@@ -88,6 +88,7 @@ export default defineComponent({
|
|||||||
.content {
|
.content {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 8px 15px;
|
padding: 8px 15px;
|
||||||
|
max-width: 800px;
|
||||||
// background-color: aqua;
|
// background-color: aqua;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,8 @@ import {
|
|||||||
IChatResponse,
|
IChatResponse,
|
||||||
API_ID_CHATGPT,
|
API_ID_CHATGPT,
|
||||||
applicationOperator,
|
applicationOperator,
|
||||||
IApplication
|
IApplication,
|
||||||
|
IChatMessageState
|
||||||
} from '@/operators';
|
} from '@/operators';
|
||||||
import InputBox from '@/components/chat/InputBox.vue';
|
import InputBox from '@/components/chat/InputBox.vue';
|
||||||
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
||||||
@@ -35,6 +36,7 @@ import { chatOperator } from '@/operators';
|
|||||||
import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import ApiStatus from '@/components/common/ApiStatus.vue';
|
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||||
|
import { ROUTE_CHAT_CONVERSATION } from '@/router';
|
||||||
|
|
||||||
export interface IData {
|
export interface IData {
|
||||||
messages: IChatMessage[];
|
messages: IChatMessage[];
|
||||||
@@ -61,48 +63,7 @@ export default defineComponent({
|
|||||||
initializing: false,
|
initializing: false,
|
||||||
applied: undefined,
|
applied: undefined,
|
||||||
application: undefined,
|
application: undefined,
|
||||||
messages: [
|
messages: []
|
||||||
{
|
|
||||||
role: ROLE_USER,
|
|
||||||
content: 'hello'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_ASSISTANT,
|
|
||||||
content: '## ok \n\n hello, how can I assist you? \n ```python\nprint("hello")\n```'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_USER,
|
|
||||||
content: 'hello'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_ASSISTANT,
|
|
||||||
content: '## ok \n\n hello, how can I assist you? \n ```python\nprint("hello")\n```'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_USER,
|
|
||||||
content: 'hello'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_ASSISTANT,
|
|
||||||
content: '## ok \n\n hello, how can I assist you? \n ```python\nprint("hello")\n```'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_USER,
|
|
||||||
content: 'hello'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_ASSISTANT,
|
|
||||||
content: '## ok \n\n hello, how can I assist you? \n ```python\nprint("hello")\n```'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_USER,
|
|
||||||
content: 'hello'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
role: ROLE_ASSISTANT,
|
|
||||||
content: '## ok \n\n hello, how can I assist you? \n ```python\nprint("hello")\n```'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -111,6 +72,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
console.log('mounted');
|
||||||
this.onLoadModel();
|
this.onLoadModel();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
@@ -133,18 +95,23 @@ export default defineComponent({
|
|||||||
role: ROLE_USER
|
role: ROLE_USER
|
||||||
});
|
});
|
||||||
this.question = '';
|
this.question = '';
|
||||||
|
|
||||||
await this.onFetchAnswer();
|
await this.onFetchAnswer();
|
||||||
},
|
},
|
||||||
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;
|
||||||
const question = this.messages[this.messages.length - 1].content;
|
const question = this.messages[this.messages.length - 1].content;
|
||||||
console.log('q', question);
|
|
||||||
if (!token || !endpoint || !question) {
|
if (!token || !endpoint || !question) {
|
||||||
console.error('no token or endpoint or question');
|
console.error('no token or endpoint or question');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
console.log('token', token);
|
this.messages.push({
|
||||||
|
content: '',
|
||||||
|
role: ROLE_ASSISTANT,
|
||||||
|
state: IChatMessageState.PENDING
|
||||||
|
});
|
||||||
|
// request server to get answer
|
||||||
chatOperator
|
chatOperator
|
||||||
.request(
|
.request(
|
||||||
{
|
{
|
||||||
@@ -156,13 +123,24 @@ export default defineComponent({
|
|||||||
token,
|
token,
|
||||||
endpoint,
|
endpoint,
|
||||||
stream: (response: IChatResponse) => {
|
stream: (response: IChatResponse) => {
|
||||||
console.log('response', response);
|
this.messages[this.messages.length - 1].content = response.answer;
|
||||||
|
if (!this.conversationId) {
|
||||||
|
this.$router.push({
|
||||||
|
name: ROUTE_CHAT_CONVERSATION,
|
||||||
|
params: {
|
||||||
|
id: response.conversation_id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
.then(() => {
|
||||||
|
this.messages[this.messages.length - 1].state = IChatMessageState.FINISHED;
|
||||||
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
if (this.messages && this.messages.length > 0) {
|
if (this.messages && this.messages.length > 0) {
|
||||||
this.messages[this.messages.length - 1].state = ChatMessageState.FAILED;
|
this.messages[this.messages.length - 1].state = IChatMessageState.FAILED;
|
||||||
}
|
}
|
||||||
if (axios.isCancel(error)) {
|
if (axios.isCancel(error)) {
|
||||||
this.messages[this.messages.length - 1].error = {
|
this.messages[this.messages.length - 1].error = {
|
||||||
@@ -181,7 +159,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// console.log('this.response', response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -200,6 +177,11 @@ export default defineComponent({
|
|||||||
width: 100%;
|
width: 100%;
|
||||||
overflow-y: scroll;
|
overflow-y: scroll;
|
||||||
padding: 15px 0;
|
padding: 15px 0;
|
||||||
|
.messages {
|
||||||
|
.message {
|
||||||
|
margin-bottom: 15px;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
.bottom {
|
.bottom {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
+12
-1
@@ -1,4 +1,10 @@
|
|||||||
import { ROUTE_AUTH_CALLBACK, ROUTE_AUTH_LOGIN, ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_INDEX } from './constants';
|
import {
|
||||||
|
ROUTE_AUTH_CALLBACK,
|
||||||
|
ROUTE_AUTH_LOGIN,
|
||||||
|
ROUTE_CHAT_CONVERSATION,
|
||||||
|
ROUTE_CHAT_CONVERSATION_NEW,
|
||||||
|
ROUTE_CHAT_INDEX
|
||||||
|
} from './constants';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
path: '/chat',
|
path: '/chat',
|
||||||
@@ -9,6 +15,11 @@ export default {
|
|||||||
name: ROUTE_CHAT_INDEX,
|
name: ROUTE_CHAT_INDEX,
|
||||||
component: () => import('@/pages/chat/Index.vue')
|
component: () => import('@/pages/chat/Index.vue')
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'conversation',
|
||||||
|
name: ROUTE_CHAT_CONVERSATION_NEW,
|
||||||
|
component: () => import('@/pages/chat/Conversation.vue')
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'conversation/:id',
|
path: 'conversation/:id',
|
||||||
name: ROUTE_CHAT_CONVERSATION,
|
name: ROUTE_CHAT_CONVERSATION,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ export const ROUTE_AUTH_CALLBACK = 'auth-callback';
|
|||||||
|
|
||||||
export const ROUTE_CHAT_INDEX = 'chat-index';
|
export const ROUTE_CHAT_INDEX = 'chat-index';
|
||||||
export const ROUTE_CHAT_CONVERSATION = 'chat-conversation';
|
export const ROUTE_CHAT_CONVERSATION = 'chat-conversation';
|
||||||
|
export const ROUTE_CHAT_CONVERSATION_NEW = 'chat-conversation-new';
|
||||||
|
|
||||||
export const ROUTE_PAINT_INDEX = 'paint-index';
|
export const ROUTE_PAINT_INDEX = 'paint-index';
|
||||||
export const ROUTE_PAINT_HISTORY = 'paint-history';
|
export const ROUTE_PAINT_HISTORY = 'paint-history';
|
||||||
|
|||||||
Reference in new issue
Block a user