File tree Expand file tree Collapse file tree 2 files changed +10
-10
lines changed
Expand file tree Collapse file tree 2 files changed +10
-10
lines changed Original file line number Diff line number Diff line change 1- import { GenerateContentResponse } from '@google/genai' ;
1+ import { GenerateContentResponse , FinishReason } from '@google/genai' ;
22import { randomUUID } from 'node:crypto' ;
33
44// --- 更新的 OpenAI 响应结构接口 ---
@@ -87,7 +87,7 @@ export function createOpenAIStreamTransformer(
8787 enqueueChunk ( controller , createChunk ( delta ) ) ;
8888 }
8989
90- if ( part . functionCall ) {
90+ if ( part . functionCall ?. name ) {
9191 const fc = part . functionCall ;
9292 const callId = `call_${ randomUUID ( ) } ` ;
9393
@@ -130,15 +130,11 @@ export function createOpenAIStreamTransformer(
130130 }
131131 }
132132
133- if (
134- finishReason &&
135- finishReason !== 'FINISH_REASON_UNSPECIFIED' &&
136- finishReason !== 'NOT_SET'
137- ) {
133+ if ( finishReason && finishReason !== 'FINISH_REASON_UNSPECIFIED' ) {
138134 const reason =
139- finishReason === ' STOP'
135+ finishReason === FinishReason . STOP
140136 ? 'stop'
141- : finishReason === ' TOOL_CALL'
137+ : finishReason === FinishReason . TOOL_CALL
142138 ? 'tool_calls'
143139 : finishReason . toLowerCase ( ) ;
144140 enqueueChunk ( controller , createChunk ( { } , reason ) ) ;
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import {
1111 type Tool ,
1212 type FunctionDeclaration ,
1313 type GenerateContentConfig ,
14+ FunctionCallingConfigMode ,
1415} from '@google/genai' ;
1516import {
1617 type OpenAIMessage ,
@@ -134,7 +135,10 @@ export class GeminiApiClient {
134135 if ( tool_choice && tool_choice !== 'auto' ) {
135136 generationConfig . toolConfig = {
136137 functionCallingConfig : {
137- mode : tool_choice . type === 'function' ? 'ANY' : 'AUTO' ,
138+ mode :
139+ tool_choice . type === 'function'
140+ ? FunctionCallingConfigMode . ANY
141+ : FunctionCallingConfigMode . AUTO ,
138142 allowedFunctionNames : tool_choice . function
139143 ? [ tool_choice . function . name ]
140144 : undefined ,
You can’t perform that action at this time.
0 commit comments