add gemini back

This commit is contained in:
JK-le-dev 2025-10-19 11:27:39 -05:00
commit c993b3e048
6 changed files with 56 additions and 91 deletions

View file

@ -2,6 +2,20 @@ import React, { useState } from "react";
import ChatHeader from "src/components/ui/chat/chat-header";
import ChatWindow from "src/components/ui/chat/chat-window";
import MessageInput from "src/components/ui/chat/message-input";
import { GoogleGenAI } from "@google/genai";
let userInput = [];
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY });
async function AIResponse(userInputArray) {
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: userInputArray,
});
return response.text;
}
export default function ChatLayout() {
const [messages, setMessages] = useState([
@ -11,21 +25,13 @@ export default function ChatLayout() {
},
]);
function addMessage(role, content) {
const msg = { role, content };
setMessages((s) => [...s, msg]);
}
function handleSend(text) {
async function handleSend(text) {
const userMsg = { role: "user", content: text };
userInput.push(text);
const res = await AIResponse(userInput);
setMessages((s) => [...s, userMsg]);
// fake assistant reply after short delay
setTimeout(() => {
setMessages((s) => [
...s,
{ role: "assistant", content: `You said: ${text}` },
]);
setMessages((s) => [...s, { role: "assistant", content: res }]);
}, 600);
}
@ -38,11 +44,7 @@ export default function ChatLayout() {
<div className="flex flex-col flex-start w-full max-w-3xl gap-4 p-4">
<ChatHeader />
<ChatWindow messages={messages} />
<MessageInput
onSend={handleSend}
onMessage={addMessage}
onDeleteAll={handleDeleteAll}
/>
<MessageInput onSend={handleSend} onDeleteAll={handleDeleteAll} />
</div>
);
}