From ce94bf7fcf3d260cd2ab5a6147d6f17704406ba7 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Tue, 11 Feb 2025 06:07:57 -0800 Subject: [PATCH] Include chat messages in solution instead of last user prompt --- app/components/chat/Chat.client.tsx | 8 -------- app/components/sidebar/SaveSolution.tsx | 11 +++++------ app/lib/replay/Problems.ts | 3 ++- app/lib/replay/SimulationPrompt.ts | 10 +++++++++- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/app/components/chat/Chat.client.tsx b/app/components/chat/Chat.client.tsx index 075f3d53..4861094f 100644 --- a/app/components/chat/Chat.client.tsx +++ b/app/components/chat/Chat.client.tsx @@ -74,12 +74,6 @@ setInterval(async () => { } }, 1000); -let gLastUserPrompt: string | undefined = "app goes blank getting directions"; - -export function getLastUserPrompt(): string | undefined { - return gLastUserPrompt; -} - export function Chat() { renderLogger.trace('Chat'); @@ -351,8 +345,6 @@ export const ChatImpl = memo( return; } - gLastUserPrompt = _input; - const anthropicApiKey = Cookies.get(anthropicApiKeyCookieName); if (!anthropicApiKey) { const numFreeUses = +(Cookies.get(anthropicNumFreeUsesCookieName) || 0); diff --git a/app/components/sidebar/SaveSolution.tsx b/app/components/sidebar/SaveSolution.tsx index eb7d95c9..f41fd679 100644 --- a/app/components/sidebar/SaveSolution.tsx +++ b/app/components/sidebar/SaveSolution.tsx @@ -2,11 +2,10 @@ import { toast } from "react-toastify"; import ReactModal from 'react-modal'; import { useState } from "react"; import { workbenchStore } from "~/lib/stores/workbench"; -import { BoltProblemStatus, getProblemsUsername, updateProblem } from "~/lib/replay/Problems"; +import { BoltProblemStatus, updateProblem } from "~/lib/replay/Problems"; import type { BoltProblemInput } from "~/lib/replay/Problems"; import { getLastLoadedProblem } from "../chat/LoadProblemButton"; -import { getLastUserSimulationData } from "~/lib/replay/SimulationPrompt"; -import { getLastUserPrompt } from "../chat/Chat.client"; +import { getLastUserSimulationData, getLastChatMessages } from "~/lib/replay/SimulationPrompt"; ReactModal.setAppElement('#root'); @@ -52,8 +51,8 @@ export function SaveSolution() { return; } - const userPrompt = getLastUserPrompt(); - if (!userPrompt) { + const messages = getLastChatMessages(); + if (!messages) { toast.error('No user prompt found'); return; } @@ -71,7 +70,7 @@ export function SaveSolution() { status: BoltProblemStatus.Solved, solution: { simulationData, - userPrompt, + messages, evaluator: formData.evaluator, }, }; diff --git a/app/lib/replay/Problems.ts b/app/lib/replay/Problems.ts index 4ecaa2ff..52ec1331 100644 --- a/app/lib/replay/Problems.ts +++ b/app/lib/replay/Problems.ts @@ -2,6 +2,7 @@ import { toast } from "react-toastify"; import { sendCommandDedicatedClient } from "./ReplayProtocolClient"; +import type { ProtocolMessage } from "./SimulationPrompt"; import Cookies from 'js-cookie'; export interface BoltProblemComment { @@ -12,7 +13,7 @@ export interface BoltProblemComment { export interface BoltProblemSolution { simulationData: any; - userPrompt: string; + messages: ProtocolMessage[]; evaluator: string; } diff --git a/app/lib/replay/SimulationPrompt.ts b/app/lib/replay/SimulationPrompt.ts index 793651f5..7893d983 100644 --- a/app/lib/replay/SimulationPrompt.ts +++ b/app/lib/replay/SimulationPrompt.ts @@ -15,7 +15,7 @@ function createRepositoryContentsPacket(contents: string): SimulationPacket { }; } -type ProtocolMessage = { +export type ProtocolMessage = { role: "user" | "assistant" | "system"; type: "text"; content: string; @@ -200,6 +200,12 @@ export async function getSimulationRecording(): Promise { return gChatManager.recordingIdPromise; } +let gLastChatMessages: ProtocolMessage[] | undefined; + +export function getLastChatMessages(): ProtocolMessage[] | undefined { + return gLastChatMessages; +} + const SystemPrompt = ` The following user message describes a bug or other problem on the page which needs to be fixed. You must respond with a useful explanation that will help the user understand the source of the problem. @@ -232,6 +238,8 @@ export async function getSimulationEnhancedPrompt( }, ]; + gLastChatMessages = messages; + console.log("ChatSendMessage", messages); return gChatManager.sendChatMessage(messages);