Help Identifying Correct Bindings

I need help choosing the correct bindings for a very simple AI API. I accidentally deleted the binding yesterday, and it seems to throw Error 1101. Should I add the Workers AI binding? If so, what should I name the variable? Code:
export default {
async fetch(request, env) {
const tasks = [];
const url = new URL(request.url);
const msg = url.searchParams.get('message')?.trim() || 'I need help.';
const ap = url.searchParams.get('ap')?.trim();
const unitnum = url.searchParams.get('unit')?.trim() ? `Unit ${url.searchParams.get('unit')?.trim()}` : 'everything';

let chat = {
messages: [
{ role: 'system', content: `You are APStudy AI, a friendly assistant whose goal is to help students learn. You are currently helping a student with ${ap} ${unitnum}. You work for APStudy, a website created to help students excel in their AP classes and exams. Always give a concise response.` },
{ role: 'user', content: msg }
],
temperature: 0.5
};
let response = await env.AI.run('@cf/meta/llama-3-8b-instruct', chat);
tasks.push({ inputs: chat, response });

return Response.json(tasks);
}
};
export default {
async fetch(request, env) {
const tasks = [];
const url = new URL(request.url);
const msg = url.searchParams.get('message')?.trim() || 'I need help.';
const ap = url.searchParams.get('ap')?.trim();
const unitnum = url.searchParams.get('unit')?.trim() ? `Unit ${url.searchParams.get('unit')?.trim()}` : 'everything';

let chat = {
messages: [
{ role: 'system', content: `You are APStudy AI, a friendly assistant whose goal is to help students learn. You are currently helping a student with ${ap} ${unitnum}. You work for APStudy, a website created to help students excel in their AP classes and exams. Always give a concise response.` },
{ role: 'user', content: msg }
],
temperature: 0.5
};
let response = await env.AI.run('@cf/meta/llama-3-8b-instruct', chat);
tasks.push({ inputs: chat, response });

return Response.json(tasks);
}
};
Its the code given by CloudFlare as a starting template that I barely edited.
No description
2 Replies
James
James6mo ago
It looks like you want a Workers AI binding with name AI
UrbanPanda
UrbanPandaOP6mo ago
James, thank you so much. The freaking API works now :Sobbing:

Did you find this page helpful?