Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-trains-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/codemode": patch
---

Allow configurable model in `experimental_codemode` instead of hardcoded `gpt-4.1`
1 change: 1 addition & 0 deletions docs/codemode.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export { CodeModeProxy } from "@cloudflare/codemode/ai";

// Use codemode wrapper
const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
prompt: "You are a helpful assistant...",
tools,
globalOutbound: env.globalOutbound,
Expand Down
1 change: 1 addition & 0 deletions examples/codemode/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class Codemode extends Agent<Env, State> {
this.tools = allTools;

const { prompt, tools: wrappedTools } = await codemode({
model,
prompt: `You are a helpful assistant that can do various tasks...

${getSchedulePrompt({ date: new Date() })}
Expand Down
3 changes: 3 additions & 0 deletions packages/codemode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const tools = {

// Configure Code Mode
const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
prompt: "You are a helpful assistant...",
tools,
globalOutbound: env.globalOutbound,
Expand Down Expand Up @@ -156,6 +157,7 @@ export class CodeModeAgent extends Agent<Env> {
};

const { prompt, tools: wrappedTools } = await codemode({
model: openai("gpt-4o"), // optional, defaults to openai("gpt-4.1")
prompt: "You are a helpful assistant...",
tools: allTools,
globalOutbound: env.globalOutbound,
Expand Down Expand Up @@ -293,6 +295,7 @@ Wraps your tools with Code Mode, converting them into a single code-generating t
- `globalOutbound: Fetcher` - Service binding for network access control
- `loader: WorkerLoader` - Worker Loader binding for code execution
- `proxy: Fetcher<CodeModeProxy>` - Proxy binding for tool execution
- `model?: LanguageModel` - The language model to use for code generation (optional, defaults to `openai("gpt-4.1")`)

**Returns:**

Expand Down
7 changes: 4 additions & 3 deletions packages/codemode/src/ai.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { generateObject, tool, type ToolSet } from "ai";
import { openai } from "@ai-sdk/openai";
import { generateObject, tool, type ToolSet, type LanguageModel } from "ai";
import { z } from "zod";
import { compile as compileJsonSchemaToTs } from "json-schema-to-typescript";
import {
Expand All @@ -9,6 +8,7 @@ import {
} from "zod-to-ts";
import { getAgentByName } from "agents";
import { env, WorkerEntrypoint } from "cloudflare:workers";
import { openai } from "@ai-sdk/openai";

function toCamelCase(str: string) {
return str
Expand Down Expand Up @@ -41,6 +41,7 @@ export async function experimental_codemode(options: {
globalOutbound: Fetcher;
loader: WorkerLoader;
proxy: Fetcher<CodeModeProxy>;
model?: LanguageModel;
}): Promise<{
prompt: string;
tools: ToolSet;
Expand All @@ -67,7 +68,7 @@ export async function experimental_codemode(options: {
execute: async ({ functionDescription }) => {
try {
const response = await generateObject({
model: openai("gpt-4.1"),
model: options.model ? options.model : openai("gpt-4.1"),
schema: z.object({
code: z.string()
}),
Expand Down
Loading