AIX: Moonshot: native search dispatch/parse support

This commit is contained in:
Enrico Ros
2025-11-09 19:27:02 -08:00
parent 4bb1dddf4d
commit 9612572f07
4 changed files with 32 additions and 4 deletions
@@ -417,6 +417,7 @@ export namespace AixWire_API {
vndGeminiGoogleSearch: z.enum(['unfiltered', '1d', '1w', '1m', '6m', '1y']).optional(),
vndGeminiShowThoughts: z.boolean().optional(),
vndGeminiThinkingBudget: z.number().optional(),
vndMoonshotWebSearch: z.enum(['auto']).optional(),
vndOaiResponsesAPI: z.boolean().optional(),
vndOaiReasoningEffort: z.enum(['minimal', 'low', 'medium', 'high']).optional(),
vndOaiRestoreMarkdown: z.boolean().optional(),
@@ -196,6 +196,15 @@ export function aixToOpenAIChatCompletions(openAIDialect: OpenAIDialects, model:
payload.search_parameters = search_parameters;
}
// [Moonshot] Kimi's $web_search builtin function
if (openAIDialect === 'moonshot' && model.vndMoonshotWebSearch === 'auto' && !skipWebSearchDueToCustomTools)
payload.tools = [...(payload.tools || []), {
type: 'builtin_function',
function: {
name: '$web_search',
},
}];
// [Perplexity] Vendor-specific extensions for search models
if (openAIDialect === 'perplexity') {
// Reasoning effort (reuses OpenAI parameter)
@@ -241,7 +241,9 @@ export function createOpenAIChatCompletionsChunkParser(): ChatGenerateParseFunct
for (const deltaToolCall of (delta.tool_calls || [])) {
// validation
if (deltaToolCall.type !== undefined && deltaToolCall.type !== 'function')
if (deltaToolCall.type !== undefined && deltaToolCall.type !== 'function'
&& deltaToolCall.type !== 'builtin_function' // [Moonshot, 2025-11-09] Support Moonshot-over-OpenAI builtin tools
)
throw new Error(`unexpected tool_call type: ${deltaToolCall.type}`);
// Creation - Ensure the tool call exists in our accumulated structure
@@ -434,7 +436,9 @@ export function createOpenAIChatCompletionsParserNS(): ChatGenerateParseFunction
// Note that we relaxed the
const mayBeMistral = toolCall.type === undefined;
if (toolCall.type !== 'function' && !mayBeMistral)
if (toolCall.type !== 'function' && !mayBeMistral
&& toolCall.type !== 'builtin_function' // [Moonshot, 2025-11-09] Support Moonshot-over-OpenAI builtin tools
)
throw new Error(`unexpected tool_call type: ${toolCall.type}`);
pt.startFunctionCallInvocation(toolCall.id, toolCall.function.name, 'incr_str', toolCall.function.arguments);
pt.endMessagePart();
@@ -72,7 +72,10 @@ export namespace OpenAIWire_ContentParts {
* .optional: for Mistral non-streaming generation - this is fairly weak, and does not let the discriminator work;
* please remove this hack asap.
*/
type: z.literal('function').optional(),
type: z.enum([
'function',
'builtin_function', // [Moonshot, 2025-11-09] (NS-parse) Support Moonshot-over-OpenAI builtin tools (builtin_function)
]).optional(),
id: z.string(),
function: z.object({
name: z.string(),
@@ -231,6 +234,14 @@ export namespace OpenAIWire_Tools {
type: z.literal('function'),
function: FunctionDefinition_schema,
}),
// [Moonshot, 2025-11-09] (definition) Support Moonshot-over-OpenAI - builtin_function for Kimi's $web_search
z.object({
type: z.literal('builtin_function'),
function: z.object({
name: z.string(), // Allows names like $web_search
description: z.string().optional(),
}),
}),
]);
export const ToolChoice_schema = z.union([
@@ -575,7 +586,10 @@ export namespace OpenAIWire_API_Chat_Completions {
index: z.number() // index is not present in non-streaming calls
.optional(), // [Mistral] not present
type: z.literal('function').optional(), // currently (2024-10-01) only 'function' is supported
type: z.enum([
'function',
'builtin_function', // [Moonshot, 2025-11-09] (S-parse) Support Moonshot-over-OpenAI builtin tools (builtin_function)
]).optional(),
id: z.string().optional(), // id of the tool call - set likely only in the first chunk