Skip to content

Commit

Permalink
fix: make checkpoints optional & hiding revert changes button if ther…
Browse files Browse the repository at this point in the history
…e are no checkpoints
  • Loading branch information
alashchev17 committed Jan 27, 2025
1 parent b1d0ce6 commit bf03568
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 32 deletions.
21 changes: 8 additions & 13 deletions src/__fixtures__/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const MARS_ROVER_CHAT: ChatHistoryItem = {
// "system",
// "Use backquotes for code blocks. Pay close attention to indent when editing code blocks: indent must be exactly the same as in the original code block.",
// ],
{ role: "user", content: "mars rover kata", checkpoints: [] },
{ role: "user", content: "mars rover kata" },
{
role: "context_file",
content: [
Expand All @@ -31,15 +31,15 @@ export const MARS_ROVER_CHAT: ChatHistoryItem = {
content:
"The Mars Rover Kata is a coding exercise that simulates the movement of a rover on the surface of Mars. The goal is to write a program that takes in a series of commands and outputs the final position of the rover.\n\nHere is a link to the official Mars Rover Kata documentation: https://kata-log.rocks/mars-rover-kata\n\nYou can find various implementations and solutions to the Mars Rover Kata on platforms like GitHub or coding challenge websites.",
},
{ role: "user", content: "solve in ocaml", checkpoints: [] },
{ role: "user", content: "solve in ocaml" },
{
role: "assistant",
content:
"Certainly! Here's an example solution to the Mars Rover Kata in OCaml:\n\n```ocaml\ntype direction = North | East | South | West\n\ntype rover = {\n x : int;\n y : int;\n dir : direction;\n}\n\nlet move_forward rover =\n match rover.dir with\n | North -> { rover with y = rover.y + 1 }\n | East -> { rover with x = rover.x + 1 }\n | South -> { rover with y = rover.y - 1 }\n | West -> { rover with x = rover.x - 1 }\n\nlet turn_left rover =\n match rover.dir with\n | North -> { rover with dir = West }\n | East -> { rover with dir = North }\n | South -> { rover with dir = East }\n | West -> { rover with dir = South }\n\nlet turn_right rover =\n match rover.dir with\n | North -> { rover with dir = East }\n | East -> { rover with dir = South }\n | South -> { rover with dir = West }\n | West -> { rover with dir = North }\n\nlet execute_command rover command =\n match command with\n | 'F' -> move_forward rover\n | 'L' -> turn_left rover\n | 'R' -> turn_right rover\n | _ -> rover (* Ignore unknown commands *)\n\nlet rec execute_commands rover commands =\n match commands with\n | [] -> rover\n | command :: rest ->\n let new_rover = execute_command rover command in\n execute_commands new_rover rest\n\nlet initial_rover = { x = 0; y = 0; dir = North }\n\nlet final_rover = execute_commands initial_rover ['F'; 'R'; 'F'; 'F'; 'L'; 'F']\n\nlet () =\n Printf.printf \"Final position: (%d, %d), facing %s\\n\"\n final_rover.x final_rover.y\n (match final_rover.dir with\n | North -> \"North\"\n | East -> \"East\"\n | South -> \"South\"\n | West -> \"West\")\n```\n\nThis solution defines the necessary types, functions, and commands to simulate the movement of the rover. The `execute_commands` function takes in a rover and a list of commands and iteratively executes each command to update the rover's position and direction. Finally, the `final_rover` is printed to the console.\n\nYou can run this code in an OCaml environment or compile it using an OCaml compiler.",
},

// remark rehype-katex works with this
{ role: "user", content: "the quadratic formula.", checkpoints: [] },
{ role: "user", content: "the quadratic formula." },
{
role: "assistant",

Expand All @@ -48,15 +48,15 @@ export const MARS_ROVER_CHAT: ChatHistoryItem = {
content:
"The quadratic formula is given by:$$[ x = \\frac{{-b \\pm \\sqrt{{b^2 - 4ac}}}}{{2a}} ] $$You can find more information about the quadratic formula in the following link: [Quadratic Formula - Wikipedia](https://en.wikipedia.org/wiki/Quadratic_formula)",
},
{ role: "user", content: "formalla with new lines", checkpoints: [] },
{ role: "user", content: "formalla with new lines" },
{
role: "assistant",
content:
// "$$ \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a} $$",
// "The quadratic formula is given by:\n\n\\[ x = \\frac{{-b \\pm \\sqrt{{b^2 - 4ac}}}}{{2a}} \\]\n\nYou can find more information about the quadratic formula in the following link: [Quadratic Formula - Wikipedia](https://en.wikipedia.org/wiki/Quadratic_formula)",
"The quadratic formula is given by:\n$$\nx = \\frac{{-b \\pm \\sqrt{{b^2 - 4ac}}}}{{2a}}\n$$\nYou can find more information about the quadratic formula in the following link: [Quadratic Formula - Wikipedia](https://en.wikipedia.org/wiki/Quadratic_formula)",
},
{ role: "user", content: "other math", checkpoints: [] },
{ role: "user", content: "other math" },
{
role: "assistant",
// "$$ \\frac{-b \\pm \\sqrt{b^2-4ac}}{2a} $$",
Expand All @@ -66,7 +66,6 @@ export const MARS_ROVER_CHAT: ChatHistoryItem = {
{
role: "user",
content: "long message\n" + "a".repeat(10000),
checkpoints: [],
},
],
title: "mars rover kata",
Expand All @@ -83,7 +82,7 @@ export const CHAT_FUNCTIONS_MESSAGES: ChatMessages = [
content:
'\nYou are a search agent. You need to actively search for the answer yourself, don\'t ask the user to do anything. The answer is most likely in the files and databases accessible using tool calls, not on the internet.\n\nWhen responding to a query, first provide a very brief explanation of your plan to use tools in parallel to answer the question, and then make several tool calls to gather more details.\n\nMinimize the number of steps, call up to 15 tools in parallel when exploring.\n\nIT IS FORBIDDEN TO JUST CALL TOOLS WITHOUT EXPLAINING. EXPLAIN FIRST!\n\nWhen user corrects you, acknowledge the correction, write "I will make a note to remember this" and use note_to_self call.\n\n\nExample 1\n\nUser: "What is the weather like today in Paris and London?"\nAssistant: "Must be sunny in Paris and foggy in London."\nUser: "don\'t hallucinate, use the tools"\nAssistant: "Sorry for the confusion, you are right, weather is real-time, and my best shot is to use the weather tool. I will make a note to remember this. My original instruction was to fetch weather for Paris and London. I will use 2 calls in parallel."\n[Call note_to_self "Weather" "For weather, use tools to get real-time information"]\n[Call weather "London"]\n[Call weather "Paris"]\n\n\nExample 2\n\nUser: "What is MyClass"\nAssistant: "Let me find it first."\n[Call ls "."]\nTool: subdir1, subdir2, subdir3\nAssistant: "I see 3 subdirs, will make 3 calls in parallel to check what\'s inside."\n[Call ls "subdir1"]\n[Call ls "subdir2"]\n[Call ls "subdir3"]\nTool: ...\nTool: ...\nTool: ...\nAssistant: "I give up, I can\'t find a file relevant for MyClass 😕"\nUser: "Look, it\'s my_class.cpp"\nAssistant: "Sorry for the confusion, there is in fact a file named `my_class.cpp` in `subdir2` that must be relevant for MyClass. I will make a note to remember this. My original instruction was to describe MyClass."\n[Call note_to_self "searching, browsing filesystem, MyClass" "Try to lowercase the name user asked about, convert to snake case, and guess the right file this way."]\n[Call cat "subdir2/my_class.cpp"]\nTool: ...\nAssistant: "MyClass does this and this"\n\n\n',
},
{ role: "user", content: "Explain what Frog is", checkpoints: [] },
{ role: "user", content: "Explain what Frog is" },
{
role: "assistant",
content:
Expand Down Expand Up @@ -150,7 +149,6 @@ export const CHAT_FUNCTIONS_MESSAGES: ChatMessages = [
{
role: "user",
content: "continue searching for the Frog in tests",
checkpoints: [],
},
{
role: "tool",
Expand Down Expand Up @@ -202,7 +200,7 @@ export const CHAT_FUNCTIONS_MESSAGES: ChatMessages = [
content:
"I couldn't retrieve specific information about Frog in the tests directory. If there are any other locations or specific files you suspect might contain details about Frog, please let me know.",
},
{ role: "user", content: "use ls, don't be stupid", checkpoints: [] },
{ role: "user", content: "use ls, don't be stupid" },
{
role: "tool",
content: {
Expand Down Expand Up @@ -256,7 +254,6 @@ export const FROG_CHAT: ChatThread = {
{
role: "user",
content: "\nWhat is the difference between a frog and a toad?\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down Expand Up @@ -450,7 +447,7 @@ export const CHAT_WITH_DIFFS: ChatMessages = [
],
tool_call_id: "test_tool_call_id",
},
{ role: "user", content: "A longer diff", checkpoints: [] },
{ role: "user", content: "A longer diff" },
{ role: "assistant", content: "here you go" },
{
role: "diff",
Expand All @@ -474,7 +471,6 @@ export const CHAT_WITH_DIFF_ACTIONS: ChatThread = {
{
role: "user",
content: "In the project add an edible property to the frog class\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down Expand Up @@ -592,7 +588,6 @@ export const LARGE_DIFF: ChatThread = {
{
role: "user",
content: "rename the frog class to bird.",
checkpoints: [],
},
{
role: "assistant",
Expand Down
1 change: 0 additions & 1 deletion src/__fixtures__/chat_config_thread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export const CHAT_CONFIG_THREAD: Chat = {
role: "user",
content:
"🔧 The postgres tool should be visible now. To test the tool, list the tables available, briefly desctibe the tables and express\nsatisfaction and relief if it works, and change nothing. If it doesn't work or the tool isn't available, go through the usual plan in the system prompt.\nThe current config file is .\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down
1 change: 0 additions & 1 deletion src/__fixtures__/chat_links_response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export const STUB_LINKS_FOR_CHAT_RESPONSE: LinksForChatResponse = {
role: "user",
content:
"Make recommended_integrations an empty list, follow the system prompt.",
checkpoints: [],
},
],
},
Expand Down
4 changes: 1 addition & 3 deletions src/__fixtures__/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ export const HISTORY: ChatHistoryItem[] = [
role: "user",
content:
"Write a program that solves word-chain puzzles.\n\nThere’s a type of puzzle where the challenge is to build a chain of words, starting with one particular word and ending with another. Successive entries in the chain must all be real words, and each can differ from the previous word by just one letter. For example, you can get from “cat” to “dog” using the following chain.\n\nThe objective of this kata is to write a program that accepts start and end words and, using words from the dictionary, builds a word chain between them. For added programming fun, return the shortest word chain that solves each puzzle. For example, you can turn “lead” into “gold” in four steps (lead, load, goad, gold), and “ruby” into “code” in six steps (ruby, rubs, robs, rods, rode, code).\n\nOnce your code works, try timing it. Does it take less than a second for the above examples given a decent-sized word list? And is the timing the same forwards and backwards (so “lead” into “gold” takes the same time as “gold” into “lead”)?",
checkpoints: [],
},
{
role: "assistant",
content:
"To solve word-chain puzzles, we can use a breadth-first search algorithm to find the shortest path between the start and end words, where each word in the path differs by only one letter from the previous word.\n\nHere is a high-level plan to implement the program:\n1. Load a dictionary of words.\n2. Implement a function to find all valid words that differ by one letter from a given word.\n3. Implement a function to find the shortest word chain between the start and end words using breadth-first search.\n4. Test the program with the provided examples and measure the execution time.\n\nLet's start by searching for relevant resources and definitions to help us implement the necessary functions for the word-chain puzzle program. I will search for algorithms for finding word chains and data structures for efficient word manipulation. Let's proceed with the search.",
tool_calls: null,
},
{ role: "user", content: "solve in scala\n", checkpoints: [] },
{ role: "user", content: "solve in scala\n" },
{
role: "assistant",
content:
Expand All @@ -40,7 +39,6 @@ export const HISTORY: ChatHistoryItem[] = [
role: "user",
content:
"In this project, what is the difference between a toad and a frog?\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down
3 changes: 0 additions & 3 deletions src/__fixtures__/some_chrome_screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const CHAT_WITH_MULTI_MODAL: ChatThread = {
{
role: "user",
content: "make a desktop and mobile screenshots of the index.html\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down Expand Up @@ -79,7 +78,6 @@ export const CHAT_WITH_MULTI_MODAL: ChatThread = {
role: "user",
content:
"fantastic, now call two chrome() in parallel each running its own tab\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down Expand Up @@ -142,7 +140,6 @@ export const CHAT_WITH_MULTI_MODAL: ChatThread = {
{
role: "user",
content: "you forgot the screenshots\n",
checkpoints: [],
},
{
role: "assistant",
Expand Down
4 changes: 3 additions & 1 deletion src/components/ChatContent/UserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ export const UserInput: React.FC<UserInputProps> = ({
transition: "opacity 0.15s, visibility 0.15s",
}}
>
<CheckpointButton checkpoints={checkpointsFromMessage} />
{checkpointsFromMessage && checkpointsFromMessage.length > 0 && (
<CheckpointButton checkpoints={checkpointsFromMessage} />
)}
<IconButton
title="Edit message"
variant="soft"
Expand Down
8 changes: 2 additions & 6 deletions src/features/Chat/Thread/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ describe("formatChatResponse", () => {
id: "test",
content: " what is this for?\n",
role: "user",
checkpoints: [],
};

const messages: ChatMessages = [
{ role: "user", content: "Hello", checkpoints: [] },
{ role: "user", content: "Hello" },
{
role: "assistant",
content: "Hi",
Expand Down Expand Up @@ -63,7 +62,6 @@ describe("formatChatResponse", () => {
role: "user",
content:
"@file /Users/marc/Projects/refact-chat-js/src/__fixtures__/chat_diff.ts what is this for?\n",
checkpoints: [],
},
{
role: "context_file",
Expand All @@ -84,7 +82,7 @@ describe("formatChatResponse", () => {
const expected = [
...messages.slice(0, 5),
...messages.slice(6),
{ role: message.role, content: message.content, checkpoints: [] },
{ role: message.role, content: message.content },
];

expect(result).toEqual(expected);
Expand All @@ -94,15 +92,13 @@ describe("formatChatResponse", () => {
const userMessage: UserMessage = {
role: "user",
content: "Hello",
checkpoints: [],
};

const sentMessages = [userMessage];

const updatedUserMessage: UserMessage = {
role: "user",
content: "hi",
checkpoints: [],
};

const userMessageResponse: UserMessageResponse = {
Expand Down
2 changes: 1 addition & 1 deletion src/services/refact/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function isLspChatMessage(json: unknown): json is LspChatMessage {
export function isLspUserMessage(
message: LspChatMessage,
): message is UserMessage {
return message.role === "user" && "checkpoints" in message;
return message.role === "user";
}

type StreamArgs =
Expand Down
6 changes: 3 additions & 3 deletions src/services/refact/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export interface UserMessage extends BaseMessage {
content:
| string
| (UserMessageContentWithImage | ProcessedUserMessageContentWithImages)[];
checkpoints: Checkpoint[];
checkpoints?: Checkpoint[];
}

export type ProcessedUserMessageContentWithImages = {
Expand Down Expand Up @@ -339,7 +339,7 @@ export type ChatUserMessageResponse =
id: string;
role: "user" | "context_file" | "context_memory";
content: string;
checkpoints: Checkpoint[];
checkpoints?: Checkpoint[];
}
| {
id: string;
Expand All @@ -350,7 +350,7 @@ export type ChatUserMessageResponse =
| UserMessageContentWithImage
| ProcessedUserMessageContentWithImages
)[];
checkpoints: Checkpoint[];
checkpoints?: Checkpoint[];
};

export type ToolResponse = {
Expand Down

0 comments on commit bf03568

Please sign in to comment.