[ ] export default { [ ] async fetch(request, env) { [ ] const url = new URL(request.url); [ ] // Chat API [ ] if (url.pathname === "/chat" && request.method === "POST") { [ ] const body = await request.json(); [ ] const message = body.message; [ ] const history = body.history || []; [ ] // Live search for news/price [ ] let searchData = ""; [ ] const msg = message.toLowerCase(); [ ] if (msg.includes("news") || msg.includes("latest") || msg.includes("price") || msg.includes("today")) { [ ] try { [ ] const searchRes = await fetch("https://api.duckgo.com/?q=" + encodeURIComponent(message) + "&format=json"); [ ] const searchJson = await searchRes.json(); [ ] searchData = searchJson.AbstractText || searchJson.Answer || ""; [ ] } catch(e) {} [ ] } [ ] // Call Gemini [ ] const prompt = "You are TEXTGPT. Chat History: " + JSON.stringify(history) + ". Live Info: " + searchData + ". User: " + message; [ ] const geminiRes = await fetch("https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-flash:generateContent?key=" + env.GEMINI_API_KEY, { [ ] method: "POST", [ ] headers: {"Content-Type": "application/json"}, [ ] body: JSON.stringify({ [ ] contents: [{parts: [{text: prompt}]}] [ ] }) [ ] }); [ ] const data = await geminiRes.json(); [ ] const reply = data.candidates[0].content.parts[0].text; [ ] return new Response(JSON.stringify({ reply: reply }), { [ ] headers: { "Content-Type": "application/json" } [ ] }); [ ] } [ ] // Website [ ] return new Response('TEXTGPT
MADE BY FARHAN
🚀

TEXTGPT is launching...

TEXTGPT

● POWERED BY GEMINI + LIVE SEARCH

', { [ ] headers: { "Content-Type": "text/html" } [ ] }); [ ] } [ ] }