-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
Added support for cloudflare Workers AI via the OpenAI endpoint #4846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
7009a1b
to
99594bf
Compare
Hmm. I suppose one thing I don't like actually is that function calling does not work on all the models, it's only supported by 4 of them: https://developers.cloudflare.com/workers-ai/models/?capabilities=Function+calling Attempting it on another model and you get a 400. Event with the "supported" models, it doesn't appear to work:
Gives:
eg; null content, no tool calls, just no content. Same with I'll poke this over to some people I know at Cloudflare to see what they say. |
…NT_ID and CLOUDFLARE_API_KEY
…h supports function calling. Made streaming responses configurable
Hello @Stono, thank you raising this, we've released an update in the OpenAI endpoint that should fix tool calling for Workers AI models. Can you try out on your end and let us know if everything looks good? |
Hey, thanks so much for sorting! I'm away until the middle of next week so will test it when I get back |
@thatsKevinJain works a treat with streaming disabled: ![]() However with streaming enabled we get back: ![]() eg a content response rather than a tool call. This can be replicated with the curl setting |
Yes, hermes-2-pro is an older model in our catalog that has a different output style than some of the newer models that adhere more to the openai format, thanks for the raising this, we can look into it, meanwhile can you try with @cf/meta/llama-4-scout-17b-16e-instruct with streaming? |
Hi,
This PR adds support for Cloudflare Workers AI
It's quite a nice PaaS model environment.
https://developers.cloudflare.com/workers-ai/
I did originally add
@langchain/cloudflare
, however that seemed incomplete, didn't support tools etc. Cloudflare provide openai compatible endpoints for their chat models so I'm instead using that.The model data is generated by hitting
GET https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/ai/models/search
; some of them are 0 cost because "beta" models don't have a cost.It was reasonably easy to add a new provider so kudos for the extensible pattern.