Add support for advanced AI.run configuration in runWithTools + Add support for OpenAI-like function call output format#19
Conversation
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.
|
maybe review? it's been 2.5 months. @Dhravya |
I think that cloudflare moved to a different AI Library to call the AI Workers, this one is still solid but with bad type infer. Dunno if my implementation is working with the latest wrangler versions |
do you know what library it is? I couldn't find anything else on running cloudflare ai with tools, other than this one. |
Check here: Cloudflare Agents There's this new |
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.