Skip to content

Add support for advanced AI.run configuration in runWithTools + Add support for OpenAI-like function call output format#19

Open
Hiutaky wants to merge 3 commits into
cloudflare:mainfrom
Hiutaky:main
Open

Add support for advanced AI.run configuration in runWithTools + Add support for OpenAI-like function call output format#19
Hiutaky wants to merge 3 commits into
cloudflare:mainfrom
Hiutaky:main

Conversation

@Hiutaky
Copy link
Copy Markdown

@Hiutaky Hiutaky commented Apr 15, 2026

Make runWithTools generic over the model to infer input/output types,
and accept a 4th parameter for advanced ChatCompletions options
(temperature, max_tokens, top_p, seed, response_format, etc.)
that are passed through to ai.run calls.

Previously only Mistral-like responses ({ tool_calls: [{ name, arguments }] })
were handled. This adds an extractToolCalls helper that normalizes tool calls
from both Mistral-like and OpenAI-like ({ choices: [{ message: { tool_calls:
[{ function: { name, arguments } }] } }] }) response formats.

Also updates @cloudflare/workers-types and exports BaseAiTextGenerationModels
from local types to fix compatibility with newer package versions.

Hiutaky added 3 commits April 15, 2026 15:46
Previously only Mistral-like responses ({ tool_calls: [{ name, arguments }] })
were handled. This adds an extractToolCalls helper that normalizes tool calls
from both Mistral-like and OpenAI-like ({ choices: [{ message: { tool_calls:
[{ function: { name, arguments } }] } }] }) response formats.

Also updates @cloudflare/workers-types and exports BaseAiTextGenerationModels
from local types to fix compatibility with newer package versions.
Make runWithTools generic over the model to infer input/output types,
and accept a 4th parameter for advanced ChatCompletions options
(temperature, max_tokens, top_p, seed, response_format, etc.)
that are passed through to ai.run calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant