From 6442e371eee387006eae30c8fffb7a527fbefd5c Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Thu, 30 Jan 2025 11:43:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=81=97=E6=BC=8F=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/openai/chatgpt-api.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/utils/openai/chatgpt-api.ts b/utils/openai/chatgpt-api.ts index e322ce7..0987a5c 100644 --- a/utils/openai/chatgpt-api.ts +++ b/utils/openai/chatgpt-api.ts @@ -182,6 +182,7 @@ export class ChatGPTAPI { conversationId, parentMessageId: messageId, text: '', + thinking_text: '', functionCall: undefined, toolCalls: undefined, conversation: [] @@ -261,6 +262,7 @@ export class ChatGPTAPI { } else { result.delta = delta.content if (delta?.content) result.text += delta.content + if (delta?.reasoning_content) result.thinking_text += delta.reasoning_content } if (delta.role) { result.role = delta.role @@ -290,14 +292,14 @@ export class ChatGPTAPI { const msg = `OpenAI error ${ res.status || res.statusText }: ${reason}` - const error = new types.ChatGPTError(msg, { cause: res }) + const error = new types.ChatGPTError(msg) error.statusCode = res.status error.statusText = res.statusText return reject(error) } const response: types.openai.CreateChatCompletionResponse = - await res.json() + (await res.json()) as types.openai.CreateChatCompletionResponse if (this._debug) { console.log(response) } @@ -314,6 +316,8 @@ export class ChatGPTAPI { result.functionCall = message.function_call } else if (message.tool_calls) { result.functionCall = message.tool_calls.map(tool => tool.function)[0] + } else if (message.reasoning_content) { + result.thinking_text = message.reasoning_content } if (message.role) { result.role = message.role @@ -379,19 +383,23 @@ export class ChatGPTAPI { } } - get apiKey(): string { + // @ts-ignore + get apiKey(): string { return this._apiKey } - set apiKey(apiKey: string) { + // @ts-ignore + set apiKey(apiKey: string) { this._apiKey = apiKey } - get apiOrg(): string { + // @ts-ignore + get apiOrg(): string { return this._apiOrg } - set apiOrg(apiOrg: string) { + // @ts-ignore + set apiOrg(apiOrg: string) { this._apiOrg = apiOrg } @@ -525,7 +533,7 @@ export class ChatGPTAPI { content: parentMessage.text, name: parentMessage.name, function_call: parentMessage.functionCall ? parentMessage.functionCall : undefined, - tools: parentMessage.toolCalls ? parentMessage.toolCalls : undefined + // tool_calls: parentMessage.toolCalls ? parentMessage.toolCalls : undefined }, ...nextMessages.slice(systemMessageOffset) ])