fix: 调整部分问题

This commit is contained in:
ChenZhaoYu committed 2023-03-06 20:34:29 +08:00
1 parent c8fa086565
commit 50e672e79b
7 files changed
+135 -160

No files matched your search

+11 -25
View File
@@ -24,6 +24,9 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
if (process.env.OPENAI_API_KEY) {
const options: ChatGPTAPIOptions = {
apiKey: process.env.OPENAI_API_KEY,
completionParams: {
model: 'gpt-3.5-turbo',
},
debug: false,
}
@@ -67,28 +70,6 @@ let api: ChatGPTAPI | ChatGPTUnofficialProxyAPI
}
})()
async function chatReply(
message: string,
lastContext?: { conversationId?: string; parentMessageId?: string },
) {
if (!message)
return sendResponse({ type: 'Fail', message: 'Message is empty' })
try {
let options: SendMessageOptions = { timeoutMs }
if (lastContext)
options = { ...lastContext }
const response = await api.sendMessage(message, { ...options })
return sendResponse({ type: 'Success', data: response })
}
catch (error: any) {
return sendResponse({ type: 'Fail', message: error.message })
}
}
async function chatReplyProcess(
message: string,
lastContext?: { conversationId?: string; parentMessageId?: string },
@@ -100,8 +81,12 @@ async function chatReplyProcess(
try {
let options: SendMessageOptions = { timeoutMs }
if (lastContext)
options = { ...lastContext }
if (lastContext) {
if (apiModel === 'ChatGPTAPI')
options = { parentMessageId: lastContext.parentMessageId }
else
options = { ...lastContext }
}
const response = await api.sendMessage(message, {
...options,
@@ -113,6 +98,7 @@ async function chatReplyProcess(
return sendResponse({ type: 'Success', data: response })
}
catch (error: any) {
global.console.error(error)
return sendResponse({ type: 'Fail', message: error.message })
}
}
@@ -131,4 +117,4 @@ async function chatConfig() {
export type { ChatContext, ChatMessage }
export { chatReply, chatReplyProcess, chatConfig }
export { chatReplyProcess, chatConfig }