Create Index.js

This commit is contained in:
Web4 2025-02-25 10:21:30 -05:00 committed by GitHub
parent 93f694ef1c
commit 3315c3cac0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

27
Index.js Normal file
View File

@ -0,0 +1,27 @@
export default {
async fetch(request, env) {
const tasks = [];
// prompt - simple completion style input
let simple = {
prompt: 'Tell me a joke about Cloudflare'
};
let response = await env.AI.run('@cf/meta/llama-3-8b-instruct', simple);
tasks.push({ inputs: simple, response });
// messages - chat style input
let chat = {
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Who won the world series in 2020?' }
]
};
response = await env.AI.run('@cf/meta/llama-3-8b-instruct', chat);
tasks.push({ inputs: chat, response });
return Response.json(tasks);
}
};