From 43ab9b36563ed10e974ced98aa7134404d331d34 Mon Sep 17 00:00:00 2001 From: Brian Hackett Date: Wed, 12 Feb 2025 14:19:57 -0800 Subject: [PATCH] Support saving solutions without an associated evaluator --- app/components/chat/LoadProblemButton.tsx | 6 +++++- app/components/sidebar/SaveProblem.tsx | 2 ++ app/components/sidebar/SaveSolution.tsx | 19 +++++++++++-------- app/lib/replay/Problems.ts | 2 +- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/components/chat/LoadProblemButton.tsx b/app/components/chat/LoadProblemButton.tsx index 10b358a4..3f90e61b 100644 --- a/app/components/chat/LoadProblemButton.tsx +++ b/app/components/chat/LoadProblemButton.tsx @@ -14,7 +14,11 @@ interface LoadProblemButtonProps { } export function setLastLoadedProblem(problem: BoltProblem) { - localStorage.setItem('loadedProblem', JSON.stringify(problem)); + try { + localStorage.setItem('loadedProblem', JSON.stringify(problem)); + } catch (error) { + console.error('Failed to set last loaded problem:', error); + } } export function getLastLoadedProblem(): BoltProblem | undefined { diff --git a/app/components/sidebar/SaveProblem.tsx b/app/components/sidebar/SaveProblem.tsx index bc47ddf9..3574dfa2 100644 --- a/app/components/sidebar/SaveProblem.tsx +++ b/app/components/sidebar/SaveProblem.tsx @@ -7,6 +7,8 @@ import type { BoltProblemInput } from "~/lib/replay/Problems"; ReactModal.setAppElement('#root'); +// Component for saving the current chat as a new problem. + export function SaveProblem() { const [isModalOpen, setIsModalOpen] = useState(false); const [formData, setFormData] = useState({ diff --git a/app/components/sidebar/SaveSolution.tsx b/app/components/sidebar/SaveSolution.tsx index f41fd679..039f4f66 100644 --- a/app/components/sidebar/SaveSolution.tsx +++ b/app/components/sidebar/SaveSolution.tsx @@ -9,6 +9,9 @@ import { getLastUserSimulationData, getLastChatMessages } from "~/lib/replay/Sim ReactModal.setAppElement('#root'); +// Component for saving input simulation and prompt information for +// the problem the current chat was loaded from. + export function SaveSolution() { const [isModalOpen, setIsModalOpen] = useState(false); const [formData, setFormData] = useState({ @@ -33,12 +36,6 @@ export function SaveSolution() { }; const handleSubmitSolution = async () => { - // Add validation here - if (!formData.evaluator) { - toast.error('Please fill in evaluator field'); - return; - } - const savedProblem = getLastLoadedProblem(); if (!savedProblem) { toast.error('No problem loaded'); @@ -61,17 +58,22 @@ export function SaveSolution() { console.log("SubmitSolution", formData); + // The evaluator is only present when the problem has been solved. + // We still create a "solution" object even if it hasn't been + // solved quite yet, which is used for working on the problem. + const evaluator = formData.evaluator.length ? formData.evaluator : undefined; + const problem: BoltProblemInput = { version: 2, title: savedProblem.title, description: savedProblem.description, username: savedProblem.username, repositoryContents: savedProblem.repositoryContents, - status: BoltProblemStatus.Solved, + status: evaluator ? BoltProblemStatus.Solved : BoltProblemStatus.Unsolved, solution: { simulationData, messages, - evaluator: formData.evaluator, + evaluator, }, }; @@ -109,6 +111,7 @@ export function SaveSolution() { <>
Save solution for loaded problem from last prompt and recording.
Evaluator describes a condition the explanation must satisfy.
+
Leave the evaluator blank if the API explanation is not right and the problem isn't solved yet.
Evaluator:
diff --git a/app/lib/replay/Problems.ts b/app/lib/replay/Problems.ts index a4ea9e2c..88b9dd7a 100644 --- a/app/lib/replay/Problems.ts +++ b/app/lib/replay/Problems.ts @@ -14,7 +14,7 @@ export interface BoltProblemComment { export interface BoltProblemSolution { simulationData: any; messages: ProtocolMessage[]; - evaluator: string; + evaluator?: string; } export enum BoltProblemStatus {