Unable to run AI models locally in pages

It works just fine in production, but I believe there should be a way to get it running locally. I am using the new opennext cloudflare stack, this is what the code looks like, weirdly it says Error: 10000: Authentication error
import { getCloudflareContext } from "@opennextjs/cloudflare";
import { NextResponse, type NextRequest } from "next/server";
import { z } from "zod";
import { createWorkersAI } from "workers-ai-provider";
import { generateText } from "ai";
// import { generateObject } from "ai";

export async function GET(request: NextRequest) {
const AI = getCloudflareContext().env.AI;

// const workersai = createWorkersAI({ binding: AI });

// const s = await generateText({
// model: workersai("@cf/meta/llama-3.1-8b-instruct"),

// prompt: "Hello, world!",
// });

const response = await AI.run("@cf/meta/llama-3.1-8b-instruct", {
prompt: "What is the origin of the phrase Hello, World",
});

return NextResponse.json(JSON.stringify(response));
}
import { getCloudflareContext } from "@opennextjs/cloudflare";
import { NextResponse, type NextRequest } from "next/server";
import { z } from "zod";
import { createWorkersAI } from "workers-ai-provider";
import { generateText } from "ai";
// import { generateObject } from "ai";

export async function GET(request: NextRequest) {
const AI = getCloudflareContext().env.AI;

// const workersai = createWorkersAI({ binding: AI });

// const s = await generateText({
// model: workersai("@cf/meta/llama-3.1-8b-instruct"),

// prompt: "Hello, world!",
// });

const response = await AI.run("@cf/meta/llama-3.1-8b-instruct", {
prompt: "What is the origin of the phrase Hello, World",
});

return NextResponse.json(JSON.stringify(response));
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?