diff --git a/service/src/chatgpt.ts b/service/src/chatgpt.ts index 43ff8d0..9e310b1 100644 --- a/service/src/chatgpt.ts +++ b/service/src/chatgpt.ts @@ -24,7 +24,7 @@ const api = new ChatGPTAPI({ apiKey }) async function chatReply(message: string) { if (!message) - return sendResponse({ type: 'fail', message: 'Message is empty' }) + return sendResponse({ type: 'Fail', message: 'Message is empty' }) try { // Get the last context from the chat context @@ -43,16 +43,17 @@ async function chatReply(message: string) { if (conversationId && id) chatContext.add({ conversationId, parentMessageId: id }) - return sendResponse({ type: 'success', data: response }) + return sendResponse({ type: 'Success', data: response }) } catch (error: any) { - return sendResponse({ type: 'fail', message: error.message }) + global.console.log(error) + return sendResponse({ type: 'Fail', message: error.message }) } } async function chatReplayOne(message: string, options?: ChatContext) { if (!message) - return sendResponse({ type: 'fail', message: 'Message is empty' }) + return sendResponse({ type: 'Fail', message: 'Message is empty' }) try { let messageOptions: SendMessageOptions = {} @@ -63,18 +64,18 @@ async function chatReplayOne(message: string, options?: ChatContext) { const response = await api.sendMessage(message, { ...messageOptions }) - return sendResponse({ type: 'success', data: response }) + return sendResponse({ type: 'Success', data: response }) } } catch (error: any) { - return sendResponse({ type: 'fail', message: error.message }) + return sendResponse({ type: 'Fail', message: error.message }) } } async function clearChatContext() { // Clear the chat context chatContext.clear() - return sendResponse({ type: 'success', message: 'Chat context cleared' }) + return sendResponse({ type: 'Success', message: 'Chat context cleared' }) } export { chatReply, chatReplayOne, clearChatContext } diff --git a/service/src/utils/index.ts b/service/src/utils/index.ts index 392f9d9..1d83253 100644 --- a/service/src/utils/index.ts +++ b/service/src/utils/index.ts @@ -1,13 +1,13 @@ interface SendResponseOptions { - type: 'success' | 'fail' + type: 'Success' | 'Fail' message?: string data?: any } export function sendResponse(options: SendResponseOptions) { - if (options.type === 'success') { + if (options.type === 'Success') { return Promise.resolve({ - message: options.message ?? 'Success', + message: options.message ?? null, data: options.data ?? null, status: options.type, }) diff --git a/src/api/index.ts b/src/api/index.ts new file mode 100644 index 0000000..b49b52c --- /dev/null +++ b/src/api/index.ts @@ -0,0 +1,14 @@ +import { post } from '@/utils/request' + +export function fetchChatAPI(prompt: string) { + return post({ + url: '/chat', + data: { prompt }, + }) +} + +export function clearConversations() { + return post({ + url: '/clear', + }) +} diff --git a/src/components/business/Chat/components/Message/Text.vue b/src/components/business/Chat/components/Message/Text.vue index 4422dbe..d04fa2c 100644 --- a/src/components/business/Chat/components/Message/Text.vue +++ b/src/components/business/Chat/components/Message/Text.vue @@ -1,6 +1,7 @@ @@ -82,8 +86,12 @@ function addMessage(message: string, reversal = false) {
diff --git a/src/components/business/Chat/layout/sider/index.vue b/src/components/business/Chat/layout/sider/index.vue index bd03a93..f00cea6 100644 --- a/src/components/business/Chat/layout/sider/index.vue +++ b/src/components/business/Chat/layout/sider/index.vue @@ -1,6 +1,6 @@