mirror of
https://github.com/jackhh66/ChatGPT_Web_accessToken.git
synced 2026-12-03 22:09:34 +00:00
fix: 调整部分问题
This commit is contained in:
1 parent
c8fa086565
commit
50e672e79b
7 files changed
+135
-160
No files matched your search
@@ -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 }
|
||||
Reference in new issue
Block a user