Ai cloud flare
const GROQ_API_KEY = "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"; const TAVILY_API_KEY = "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"; const MODEL = "llama-3.3-70b-versatile"; /* ========================= 🧠 ROUTER ========================= */ function routeQuery(text) { const t = text.toLowerCase(); if (/\b(bukas|ngayon|petsa|araw|oras|what time|what date)\b/.test(t)) return "local"; if (/\b(news|latest|update|search|hanapin|weather|current)\b/.test(t)) return "web"; return "ai"; } /* ========================= 🕒 LOCAL BRAIN ========================= */ function handleLocal(text) { const now = new Date(); if (text.toLowerCase().includes("bukas")) { const d = new Date(now); d.setDate(d.getDate() + 1); return `Bukas ay ${d.toLocaleDateString("fil-PH", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}`; } return `Ngayon ay ${now.toLocaleDateString("fil-PH", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}`; } /* ========================= 🤖 GROQ SAFE ========================= */ async function callGroq(messages) { try { const res = await fetch( "https://api.groq.com/openai/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: "Bearer " + GROQ_API_KEY }, body: JSON.stringify({ model: MODEL, messages, temperature: 0.7 }) } ); const data = await res.json(); if (!data.choices?.[0]?.message?.content) { console.log("GROQ ERROR:", data); return "Error sa AI response."; } return data.choices[0].message.content; } catch (e) { return "AI service error."; } } /* ========================= 🌐 TAVILY SAFE ========================= */ async function tavilySearch(query) { try { const res = await fetch("https://api.tavily.com/search", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ api_key: TAVILY_API_KEY, query, max_results: 5 }) }); const data = await res.json(); if (!data?.results) return null; return data.results .map(r => `Title: ${r.title}\nContent: ${r.content}`) .join("\n\n"); } catch (e) { return null; } } /* ========================= 💾 KV MEMORY ========================= */ async function saveMemory(env, id, data) { await env.MEMORY.put(id, JSON.stringify(data)); } async function getMemory(env, id) { const data = await env.MEMORY.get(id); return data ? JSON.parse(data) : null; } /* ========================= 🌟 ORIGINAL UI (RESTORED) ========================= */ const HTML = `🤖
Tech Nethan24 AI
Groq + Tavily AI Search
Online
"Onces you Carry your Own water, you'll know the value of every drops"
Search This Blog
Powered by Blogger.