From 2fab6904260099d9a011734763e62ebba91cf448 Mon Sep 17 00:00:00 2001 From: soryu Date: Fri, 2 Jan 2026 22:00:45 +0000 Subject: Update LLM to keep context --- makima/frontend/src/components/files/CliInput.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'makima/frontend/src/components') diff --git a/makima/frontend/src/components/files/CliInput.tsx b/makima/frontend/src/components/files/CliInput.tsx index 0ac840a..c1e6b6d 100644 --- a/makima/frontend/src/components/files/CliInput.tsx +++ b/makima/frontend/src/components/files/CliInput.tsx @@ -1,5 +1,5 @@ import { useState, useCallback, useRef, useEffect } from "react"; -import { chatWithFile, type BodyElement, type LlmModel } from "../../lib/api"; +import { chatWithFile, type BodyElement, type LlmModel, type ChatMessage } from "../../lib/api"; import { SimpleMarkdown } from "../SimpleMarkdown"; interface CliInputProps { @@ -26,6 +26,8 @@ export function CliInput({ fileId, onUpdate }: CliInputProps) { const [messages, setMessages] = useState([]); const [expanded, setExpanded] = useState(false); const [model, setModel] = useState("claude-opus"); + // Track conversation history for context continuity + const [conversationHistory, setConversationHistory] = useState([]); const inputRef = useRef(null); const messagesRef = useRef(null); @@ -55,7 +57,8 @@ export function CliInput({ fileId, onUpdate }: CliInputProps) { setLoading(true); try { - const response = await chatWithFile(fileId, userMessage, model); + // Send request with conversation history for context + const response = await chatWithFile(fileId, userMessage, model, conversationHistory); // Add assistant response const assistantMsgId = (Date.now() + 1).toString(); @@ -73,6 +76,13 @@ export function CliInput({ fileId, onUpdate }: CliInputProps) { }, ]); + // Update conversation history for next request + setConversationHistory((prev) => [ + ...prev, + { role: "user", content: userMessage }, + { role: "assistant", content: response.response }, + ]); + // Update parent with new body/summary onUpdate(response.updatedBody, response.updatedSummary); } catch (err) { @@ -90,11 +100,12 @@ export function CliInput({ fileId, onUpdate }: CliInputProps) { inputRef.current?.focus(); } }, - [input, loading, fileId, model, onUpdate] + [input, loading, fileId, model, onUpdate, conversationHistory] ); const clearMessages = useCallback(() => { setMessages([]); + setConversationHistory([]); }, []); return ( -- cgit v1.2.3