Merge branch 'stuff' into gemini

This commit is contained in:
JK-le-dev 2025-10-19 11:28:43 -05:00
commit 6ab09eb94e
5 changed files with 15 additions and 66 deletions

View file

@ -1,6 +1,6 @@
services:
web-app:
image: ghcr.io/${REPO_NAME_LOWER}/web-app:${IMAGE_TAG}
image: ghcr.io/${REPO_NAME_LOWER}/fallback-web-app:${IMAGE_TAG}
restart: always
ports:
- "127.0.0.1:3034:3000"

View file

@ -3,14 +3,14 @@ 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";
import { useChatBackend } from "src/context/chat-backend-context";
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,
});
@ -31,11 +31,7 @@ export default function ChatLayout() {
<div className="flex flex-col flex-start w-full max-w-3xl gap-4 p-4">
<ChatHeader onDeleteAll={handleDeleteAll} />
<ChatWindow messages={messages} />
<MessageInput
onSend={handleSend}
onMessage={addMessage}
onDeleteAll={handleDeleteAll}
/>
<MessageInput onSend={handleSend} onDeleteAll={handleDeleteAll} />
</div>
);
}

View file

@ -20,10 +20,9 @@ export default function ChatHeader({
setIngesting(true);
const res = await fetch("/api/files/import-demo", { method: "POST" });
const json = await res.json().catch(() => ({}));
const imported = json.imported ?? "?";
const skipped = json.skipped ?? "?";
const summary = `Imported: ${imported}, Skipped: ${skipped}`;
setToast(json.error ? `${summary} - ${json.error}` : summary);
setToast(
`Imported: ${json.imported ?? "?"}, Skipped: ${json.skipped ?? "?"}`
);
setTimeout(() => setToast(""), 4000);
} catch (e) {
setToast("Import failed");

View file

@ -5,7 +5,11 @@ import ChatBackendContext from "src/context/chat-backend-context";
import { motion } from "motion/react";
import { BotMessageSquare } from "lucide-react";
export default function MessageInput({ onSend, onMessage }) {
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ apiKey: import.meta.env.GEMINI_API_KEY });
export default function MessageInput({ onSend }) {
const [text, setText] = useState("");
const textareaRef = useRef(null);
@ -15,52 +19,10 @@ export default function MessageInput({ onSend, onMessage }) {
}, []);
async function handleSubmit(e) {
e.preventDefault();
if (!text.trim()) return;
// send user message locally
e.preventDefault();
if (text.trim() === "") return;
onSend(text.trim());
// create query on backend
try {
if (onMessage)
onMessage("assistant", "Queued: sending request to server...");
const createRes = await fetch(`/api/query/create`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ q: text, top_k: 5 }),
});
const createJson = await createRes.json();
const id = createJson.id;
if (!id) throw new Error("no id returned");
// poll status
let status = "Queued";
if (onMessage) onMessage("assistant", `Status: ${status}`);
while (status !== "Completed" && status !== "Failed") {
await new Promise((r) => setTimeout(r, 1000));
const sRes = await fetch(`/api/query/status?id=${id}`);
const sJson = await sRes.json();
status = sJson.status;
if (onMessage) onMessage("assistant", `Status: ${status}`);
if (status === "Cancelled") break;
}
if (status === "Completed") {
const resultRes = await fetch(`/api/query/result?id=${id}`);
const resultJson = await resultRes.json();
const final =
resultJson?.result?.final_answer ||
JSON.stringify(resultJson?.result || {});
if (onMessage) onMessage("assistant", final);
} else {
if (onMessage)
onMessage("assistant", `Query status ended as: ${status}`);
}
} catch (err) {
console.error(err);
if (onMessage) onMessage("assistant", `Error: ${err.message}`);
}
setText("");
}
@ -71,7 +33,6 @@ export default function MessageInput({ onSend, onMessage }) {
<div className="flex justify-between items-center">
<div className="flex items-center gap-2">
<DownButton />
<BackendToggle />
</div>
</div>

View file

@ -1,13 +1,6 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import "./index.css";
import App from "./app/index.jsx";
import { ChatBackendProvider } from "./context/chat-backend-context";
createRoot(document.getElementById("root")).render(
<StrictMode>
<ChatBackendProvider>
<App />
</ChatBackendProvider>
</StrictMode>
);
createRoot(document.getElementById("root")).render(<App />);