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
3 changes: 2 additions & 1 deletion examples/playground/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable */
// Generated by Wrangler by running `wrangler types env.d.ts --include-runtime false` (hash: f103d0d6947e92f53f1c4ba8d54acaa6)
// Generated by Wrangler by running `wrangler types env.d.ts --include-runtime false` (hash: 58d9bb5230a737a6ca0946ef9228fa8c)
declare namespace Cloudflare {
interface GlobalProps {
mainModule: typeof import("./src/server");
Expand All @@ -11,6 +11,7 @@ declare namespace Cloudflare {
Stateful: DurableObjectNamespace<import("./src/server").Stateful>;
Chat: DurableObjectNamespace<import("./src/server").Chat>;
Rpc: DurableObjectNamespace<import("./src/server").Rpc>;
AI: Ai;
ASSETS: Fetcher;
}
}
Expand Down
12 changes: 11 additions & 1 deletion examples/playground/src/model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import { createWorkersAI } from "workers-ai-provider";
import { openai } from "@ai-sdk/openai";
import type { LanguageModelV3 } from "@ai-sdk/provider";
import { env } from "cloudflare:workers";

export const model = openai("gpt-4o");
export const model: LanguageModelV3 = (() => {
if (env.OPENAI_API_KEY) {
return openai("gpt-4");
} else {
const workersai = createWorkersAI({ binding: env.AI });
return workersai("@cf/meta/llama-2-7b-chat-int8");
}
})();
4 changes: 4 additions & 0 deletions examples/playground/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"nodejs_compat",
"nodejs_compat_populate_process_env"
],
"ai": {
"binding": "AI",
"remote": true
},
"assets": {
"binding": "ASSETS"
},
Expand Down
Loading