You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,53 @@ Tools can be configured in two ways:
127
127
1. With an `execute` function for automatic execution
128
128
2. Without an `execute` function, requiring confirmation and using the `executions` object to handle the confirmed action
129
129
130
+
### Use a different AI model provider
131
+
132
+
The starting [`server.ts`](https://github.com/cloudflare/agents-starter/blob/main/src/server.ts) implementation uses the [`ai-sdk`](https://sdk.vercel.ai/docs/introduction) and the [OpenAI provider](https://sdk.vercel.ai/providers/ai-sdk-providers/openai), but you can use any AI model provider by:
133
+
134
+
1. Installing an alternative AI provider for the `ai-sdk`, such as the [`workers-ai-provider`](https://sdk.vercel.ai/providers/community-providers/cloudflare-workers-ai) or [`anthropic`](https://sdk.vercel.ai/providers/ai-sdk-providers/anthropic) provider:
135
+
2. Replacing the AI SDK with the [OpenAI SDK](https://github.com/openai/openai-node)
136
+
3. Using the Cloudflare [Workers AI + AI Gateway](https://developers.cloudflare.com/ai-gateway/providers/workersai/#workers-binding) binding API directly
137
+
138
+
For example, to use the [`workers-ai-provider`](https://sdk.vercel.ai/providers/community-providers/cloudflare-workers-ai), install the package:
139
+
140
+
```sh
141
+
npm install workers-ai-provider
142
+
```
143
+
144
+
Add an `ai` binding to `wrangler.jsonc`:
145
+
146
+
```jsonc
147
+
// rest of file
148
+
"ai": {
149
+
"binding":"AI"
150
+
}
151
+
// rest of file
152
+
```
153
+
154
+
Replace the `@ai-sdk/openai` import and usage with the `workers-ai-provider`:
155
+
156
+
```diff
157
+
// server.ts
158
+
// Change the imports
159
+
- import { createOpenAI } from "@ai-sdk/openai";
160
+
+ import { createWorkersAI } from 'workers-ai-provider';
0 commit comments