feat: implement AI chat interface with Supabase persistence and edge API route integration

This commit is contained in:
Poyraz Avsever
2026-05-08 14:32:07 +03:00
parent b1615d72ba
commit e38a809ff9
3 changed files with 582 additions and 361 deletions
+30 -2
View File
@@ -1,6 +1,6 @@
import { NextResponse } from "next/server";
type ChatProvider = "groq" | "openai" | "ollama";
type ChatProvider = "groq" | "openai" | "ollama" | "gemini";
type ChatRequestBody = {
provider?: ChatProvider;
@@ -46,7 +46,35 @@ export async function POST(request: Request) {
let assistantReply = "";
if (provider === "groq") {
if (provider === "gemini") {
const response = await fetch(
`https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro:generateContent?key=${apiKey}`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
system_instruction: {
parts: [{ text: "Sen MindSpace adlı kullanıcının kişisel yapay zeka terapistisin ve sırdaşısın. Şefkatli, yargılamayan ve destekleyici cevaplar ver. Kullanıcının iş süreçlerini asiste edebilirsin." }]
},
contents: [
{
parts: [{ text: userMessageContent }]
}
]
}),
}
);
if (!response.ok) {
throw new Error("Gemini API hatası");
}
const data = await response.json();
assistantReply = data.candidates?.[0]?.content?.parts?.[0]?.text ?? "";
} else if (provider === "groq") {
const response = await fetch(
"https://api.groq.com/openai/v1/chat/completions",
{