fix: update buildSdkMessages to handle undefined output in API clients (#7293)

* fix: update buildSdkMessages to handle undefined output in API clients

* fix: update vision model check to include model name in regex validation
This commit is contained in:
SuYao 2025-06-17 23:11:12 +08:00 committed by GitHub
parent 0bf98cce9e
commit df2bcec768
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 23 additions and 9 deletions

View File

@ -110,7 +110,7 @@ export abstract class BaseApiClient<
abstract buildSdkMessages( abstract buildSdkMessages(
currentReqMessages: TMessageParam[], currentReqMessages: TMessageParam[],
output: TRawOutput | string, output: TRawOutput | string | undefined,
toolResults: TMessageParam[], toolResults: TMessageParam[],
toolCalls?: TToolCall[] toolCalls?: TToolCall[]
): TMessageParam[] ): TMessageParam[]

View File

@ -337,10 +337,14 @@ export class OpenAIAPIClient extends OpenAIBaseClient<
public buildSdkMessages( public buildSdkMessages(
currentReqMessages: OpenAISdkMessageParam[], currentReqMessages: OpenAISdkMessageParam[],
output: string, output: string | undefined,
toolResults: OpenAISdkMessageParam[], toolResults: OpenAISdkMessageParam[],
toolCalls: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[] toolCalls: OpenAI.Chat.Completions.ChatCompletionMessageToolCall[]
): OpenAISdkMessageParam[] { ): OpenAISdkMessageParam[] {
if (!output && toolCalls.length === 0) {
return [...currentReqMessages, ...toolResults]
}
const assistantMessage: OpenAISdkMessageParam = { const assistantMessage: OpenAISdkMessageParam = {
role: 'assistant', role: 'assistant',
content: output, content: output,

View File

@ -227,10 +227,18 @@ export class OpenAIResponseAPIClient extends OpenAIBaseClient<
public buildSdkMessages( public buildSdkMessages(
currentReqMessages: OpenAIResponseSdkMessageParam[], currentReqMessages: OpenAIResponseSdkMessageParam[],
output: string, output: string | undefined,
toolResults: OpenAIResponseSdkMessageParam[], toolResults: OpenAIResponseSdkMessageParam[],
toolCalls: OpenAIResponseSdkToolCall[] toolCalls: OpenAIResponseSdkToolCall[]
): OpenAIResponseSdkMessageParam[] { ): OpenAIResponseSdkMessageParam[] {
if (!output && toolCalls.length === 0) {
return [...currentReqMessages, ...toolResults]
}
if (!output) {
return [...currentReqMessages, ...(toolCalls || []), ...(toolResults || [])]
}
const assistantMessage: OpenAIResponseSdkMessageParam = { const assistantMessage: OpenAIResponseSdkMessageParam = {
role: 'assistant', role: 'assistant',
content: [{ type: 'input_text', text: output }] content: [{ type: 'input_text', text: output }]

View File

@ -153,7 +153,7 @@ function createToolHandlingTransform(
if (toolResult.length > 0) { if (toolResult.length > 0) {
const output = ctx._internal.toolProcessingState?.output const output = ctx._internal.toolProcessingState?.output
const newParams = buildParamsWithToolResults(ctx, currentParams, output!, toolResult, toolCalls) const newParams = buildParamsWithToolResults(ctx, currentParams, output, toolResult, toolCalls)
await executeWithToolHandling(newParams, depth + 1) await executeWithToolHandling(newParams, depth + 1)
} }
} catch (error) { } catch (error) {
@ -243,7 +243,7 @@ async function executeToolUseResponses(
function buildParamsWithToolResults( function buildParamsWithToolResults(
ctx: CompletionsContext, ctx: CompletionsContext,
currentParams: CompletionsParams, currentParams: CompletionsParams,
output: SdkRawOutput | string, output: SdkRawOutput | string | undefined,
toolResults: SdkMessageParam[], toolResults: SdkMessageParam[],
toolCalls: SdkToolCall[] toolCalls: SdkToolCall[]
): CompletionsParams { ): CompletionsParams {

View File

@ -184,7 +184,7 @@ const visionAllowedModels = [
'deepseek-vl(?:[\\w-]+)?', 'deepseek-vl(?:[\\w-]+)?',
'kimi-latest', 'kimi-latest',
'gemma-3(?:-[\\w-]+)', 'gemma-3(?:-[\\w-]+)',
'doubao-1.6-seed(?:-[\\w-]+)' 'doubao-seed-1[.-]6(?:-[\\w-]+)'
] ]
const visionExcludedModels = [ const visionExcludedModels = [
@ -238,7 +238,8 @@ export const FUNCTION_CALLING_MODELS = [
'glm-4(?:-[\\w-]+)?', 'glm-4(?:-[\\w-]+)?',
'learnlm(?:-[\\w-]+)?', 'learnlm(?:-[\\w-]+)?',
'gemini(?:-[\\w-]+)?', // 提前排除了gemini的嵌入模型 'gemini(?:-[\\w-]+)?', // 提前排除了gemini的嵌入模型
'grok-3(?:-[\\w-]+)?' 'grok-3(?:-[\\w-]+)?',
'doubao-seed-1[.-]6(?:-[\\w-]+)?'
] ]
const FUNCTION_CALLING_EXCLUDED_MODELS = [ const FUNCTION_CALLING_EXCLUDED_MODELS = [
@ -2320,7 +2321,8 @@ export const GEMINI_SEARCH_MODELS = [
'gemini-2.5-pro-preview-03-25', 'gemini-2.5-pro-preview-03-25',
'gemini-2.5-pro-preview-05-06', 'gemini-2.5-pro-preview-05-06',
'gemini-2.5-flash-preview', 'gemini-2.5-flash-preview',
'gemini-2.5-flash-preview-04-17' 'gemini-2.5-flash-preview-04-17',
'gemini-2.5-flash-preview-05-20'
] ]
export const OPENAI_NO_SUPPORT_DEV_ROLE_MODELS = ['o1-preview', 'o1-mini'] export const OPENAI_NO_SUPPORT_DEV_ROLE_MODELS = ['o1-preview', 'o1-mini']
@ -2365,7 +2367,7 @@ export function isVisionModel(model: Model): boolean {
// } // }
if (model.provider === 'doubao') { if (model.provider === 'doubao') {
return VISION_REGEX.test(model.name) || model.type?.includes('vision') || false return VISION_REGEX.test(model.name) || VISION_REGEX.test(model.id) || model.type?.includes('vision') || false
} }
return VISION_REGEX.test(model.id) || model.type?.includes('vision') || false return VISION_REGEX.test(model.id) || model.type?.includes('vision') || false