export default { async fetch(request, env) { const url = new URL(request.url); // --- API Endpoint --- if (url.pathname === "/api/chat" && request.method === "POST") { try { const body = await request.json(); const model = body.model || "@cf/meta/llama-3.1-8b-instruct"; const messages = body.messages || []; // دریافت تاریخچه چت // فراخوانی هوش مصنوعی کلودفلر با تاریخچه const result = await env.AI.run(model, { messages: messages }); return new Response(JSON.stringify({ response: result.response }), { headers: { "Content-Type": "application/json" } }); } catch (error) { return new Response(JSON.stringify({ error: error.message }), { status: 500, headers: { "Content-Type": "application/json" } }); } } // --- HTML UI --- const html = ` AI Chat - ChatGPT Clone

دستیار هوشمند کلودفلر

`; return new Response(html, { headers: { "Content-Type": "text/html;charset=UTF-8" } }); } };