From fd68a48c8a86c0f35ab3dacb67201842c5a07032 Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Fri, 10 May 2024 20:21:16 +0000 Subject: [PATCH 01/11] feat: Updated 1 files --- sweepai/handlers/on_comment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sweepai/handlers/on_comment.py b/sweepai/handlers/on_comment.py index f150ddd326..7e245be56d 100644 --- a/sweepai/handlers/on_comment.py +++ b/sweepai/handlers/on_comment.py @@ -367,7 +367,7 @@ def edit_comment(new_comment: str) -> None: sweep_bot.comment_pr_diff_str = pr_diff_string sweep_bot.comment_pr_files_modified = pr_files_modified - modify_files_dict, changes_made, _ = handle_file_change_requests( + modify_files_dict, changes_made, _, file_change_requests = handle_file_change_requests( file_change_requests=file_change_requests, request=file_comment, branch_name=branch_name, From a6f93bbda260523a1e4eaa70a8cf03f0328a0464 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Fri, 10 May 2024 21:01:40 +0000 Subject: [PATCH 02/11] Fixed file name parsing --- sweepai/core/sweep_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sweepai/core/sweep_bot.py b/sweepai/core/sweep_bot.py index 4d7d6bdb0f..509f61c8cf 100644 --- a/sweepai/core/sweep_bot.py +++ b/sweepai/core/sweep_bot.py @@ -149,7 +149,7 @@ def remove_line_numbers(s: str) -> str: def parse_filenames(text): # Regular expression pattern to match file names - pattern = r'\b(?:\w+/)*\w+(?:\.\w+)+\b|\b(?:\w+/)+\w+\b' + pattern = r'\b(?:[\w-]+/)*[\w-]+(?:[.:]\w+)+\b|\b(?:[\w-]+/)+[\w-]+\b' # Find all occurrences of file names in the text filenames = re.findall(pattern, text) From 1a382664ada0790ffbc0e399786d738b162e035c Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Fri, 10 May 2024 22:14:58 +0000 Subject: [PATCH 03/11] Fix posthog value --- sweep_chat/components/App.tsx | 2 ++ sweep_chat/package-lock.json | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 40f743d126..dae57d9592 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -327,6 +327,7 @@ function App() {
setRepoName(e.target.value)} @@ -409,6 +410,7 @@ function App() { Restart { if (e.key === "Enter") { (async () => { diff --git a/sweep_chat/package-lock.json b/sweep_chat/package-lock.json index 8f63bacd57..325303167d 100644 --- a/sweep_chat/package-lock.json +++ b/sweep_chat/package-lock.json @@ -5583,9 +5583,9 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==" }, "node_modules/posthog-js": { - "version": "1.131.3", - "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.131.3.tgz", - "integrity": "sha512-ds/TADDS+rT/WgUyeW4cJ+X+fX+O1KdkOyssNI/tP90PrFf0IJsck5B42YOLhfz87U2vgTyBaKHkdlMgWuOFog==", + "version": "1.131.4", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.131.4.tgz", + "integrity": "sha512-pKa1p6Q9jRU6s+xSluqGifODMncWTXRaeQw7yVet5U+0U56P0srdMO8NpzllIgDjYL9WLgUjDInucOBw5Cl/tA==", "dependencies": { "fflate": "^0.4.8", "preact": "^10.19.3" From e528fe5795ec21eb46afd76b3d18b5b314bcd270 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 18:49:54 +0000 Subject: [PATCH 04/11] Prompt improvements --- sweepai/chat/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sweepai/chat/api.py b/sweepai/chat/api.py index b3fc69c00a..e2cf8c878e 100644 --- a/sweepai/chat/api.py +++ b/sweepai/chat/api.py @@ -130,7 +130,7 @@ def search_codebase_endpoint( ## Updated answer Determine if you have sufficient information to answer the user's question. If not, determine the information you need to answer the question completely by making `search_codebase` tool calls. -If so, rewrite your previous response with the new information and any invalidated beliefs or assumptions. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When suggesting code changes, write out all the code changes required in the unified diff format. +If so, rewrite your previous response with the new information and any invalidated beliefs or assumptions. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When explaining how to add new code, always write out the new code. When suggesting code changes, write out all the code changes required in the unified diff format. # 2. Self-Critique @@ -163,7 +163,7 @@ def search_codebase_endpoint( ## Answer Determine if you have sufficient information to answer the user's question. If not, determine the information you need to answer the question completely by making `search_codebase` tool calls. -If so, write a complete helpful response to the user's question oin detail. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When suggesting code changes, write out all the code changes required in the unified diff format. +If so, write a complete helpful response to the user's question in full detail. Make sure this answer is complete and helpful. Provide code examples, explanations and excerpts wherever possible to provide concrete explanations. When explaining how to add new code, always write out the new code. When suggesting code changes, write out all the code changes required in the unified diff format. # 2. Self-Critique From f42ed34fb573702b5b30e912e58a91e42aec3609 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 18:52:02 +0000 Subject: [PATCH 05/11] Minor bug fix --- sweep_chat/components/App.tsx | 12 +++++++----- sweep_chat/components/Survey.tsx | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index dae57d9592..4846f11960 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -299,12 +299,14 @@ function App() { {showSurvey && process.env.NEXT_PUBLIC_SURVEY_ID && ( { + onClose={(didSubmit) => { setShowSurvey(false) - toast({ - title: "Thanks for your feedback!", - description: "We'll reach back out shortly.", - }) + if (didSubmit) { + toast({ + title: "Thanks for your feedback!", + description: "We'll reach back out shortly.", + }) + } }} /> )} diff --git a/sweep_chat/components/Survey.tsx b/sweep_chat/components/Survey.tsx index fb9e2eca9b..f0878e15fd 100644 --- a/sweep_chat/components/Survey.tsx +++ b/sweep_chat/components/Survey.tsx @@ -10,7 +10,7 @@ import { useEffect, useState } from 'react'; export default function Feedback({ onClose }: { - onClose: () => void + onClose: (didSubmit: boolean) => void }) { const posthog = usePostHog(); const [feedback, setFeedback] = useState("") @@ -29,7 +29,7 @@ export default function Feedback({ $survey_id: surveyID, }); localStorage.setItem(`hasInteractedWithSurvey_${surveyID}`, 'true'); - onClose(); + onClose(false); } const handleFeedbackSubmit = (e: any) => { @@ -40,7 +40,7 @@ export default function Feedback({ $survey_response: feedback }); localStorage.setItem(`hasInteractedWithSurvey_${surveyID}`, 'true'); - onClose(); + onClose(true); } return ( From e99f7644d54abae2ec0de64c1d5b51fc39189f48 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 19:06:35 +0000 Subject: [PATCH 06/11] Added posthog captures --- sweep_chat/components/App.tsx | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 4846f11960..d8fd8eda9a 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -415,6 +415,12 @@ function App() { data-ph-capture-attribute-current-message={currentMessage} onKeyUp={(e) => { if (e.key === "Enter") { + posthog.capture("chat submitted", { + repoName, + snippets, + messages, + currentMessage, + }); (async () => { if (currentMessage !== "") { const newMessages: Message[] = [...messages, { content: currentMessage, role: "user" }]; @@ -441,6 +447,13 @@ function App() { variant: "destructive" }); setIsLoading(false); + posthog.capture("chat errored", { + repoName, + snippets, + messages, + currentMessage, + error: e.message + }); throw e; } } @@ -470,6 +483,7 @@ function App() { if (value) { const decodedValue = new TextDecoder().decode(value); chat += decodedValue; + console.log(chat) const lastLine = getLastLine(chat); if (lastLine !== "") { try { @@ -490,6 +504,13 @@ function App() { }); console.log(chat) setIsLoading(false); + posthog.capture("chat errored", { + repoName, + snippets, + messages, + currentMessage, + error: e.message + }); throw e; } @@ -498,6 +519,12 @@ function App() { setShowSurvey(true); } setIsLoading(false); + posthog.capture("chat succeeded", { + repoName, + snippets, + messages, + currentMessage, + }); } })() } From ef4b262b079efaf85f75586c24624d94c1279bf6 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 19:33:12 +0000 Subject: [PATCH 07/11] Streaming fixes --- sweep_chat/components/App.tsx | 21 +++++++++++++++++---- sweep_chat/components/Survey.tsx | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index d8fd8eda9a..80a061f682 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -238,6 +238,16 @@ const getLastLine = (content: string) => { return splitContent[splitContent.length - 1]; } +const getLastLineEndingWithBracket = (content: string) => { + const splitContent = content.trim().split("\n"); + for (let i = splitContent.length - 1; i >= 0; i--) { + if (splitContent[i].trim().endsWith("]")) { + return splitContent[i]; + } + } + return null; +} + const defaultMessage = `I'm Sweep and I'm here to help you answer questions about your codebase!`; function App() { @@ -483,14 +493,17 @@ function App() { if (value) { const decodedValue = new TextDecoder().decode(value); chat += decodedValue; - console.log(chat) + chat = chat.replace("}][{", "}]\n[{") + const lastLineEndingWithBracket = getLastLineEndingWithBracket(chat); const lastLine = getLastLine(chat); - if (lastLine !== "") { + if (lastLineEndingWithBracket !== null) { try { - const addedMessages = JSON.parse(lastLine); + const addedMessages = JSON.parse(lastLineEndingWithBracket); respondedMessages = [...newMessages, ...addedMessages] setMessages(respondedMessages); - } catch (e: any) { } + } catch (e: any) { + console.log(lastLineEndingWithBracket) + } chat = lastLine } } diff --git a/sweep_chat/components/Survey.tsx b/sweep_chat/components/Survey.tsx index f0878e15fd..02719f5f5b 100644 --- a/sweep_chat/components/Survey.tsx +++ b/sweep_chat/components/Survey.tsx @@ -44,7 +44,7 @@ export default function Feedback({ } return ( - + Give us Feedback Sweep Chat is new so we're actively trying to improve it for developers like you. From 9d67520ade915767509c1a53f4eb60a70a6c5259 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 20:29:54 +0000 Subject: [PATCH 08/11] Diff patch streaming done --- sweep_chat/components/App.tsx | 41 +++++++++++++++++++++++------------ sweep_chat/package-lock.json | 6 +++++ sweep_chat/package.json | 1 + sweepai/chat/api.py | 21 ++++++++++++++---- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 80a061f682..797c4b6650 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -23,6 +23,8 @@ import { Session } from "next-auth"; import { PostHogProvider, usePostHog } from "posthog-js/react"; import posthog from "posthog-js"; import Survey from "./Survey"; +import * as jsonpatch from 'fast-json-patch'; + if (typeof window !== 'undefined') { posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY!) @@ -478,13 +480,15 @@ function App() { repo_name: repoName, messages: newMessages, snippets: currentSnippets, + use_patch: true }) }); // Stream const reader = chatResponse.body?.getReader(); let done = false; - let chat = ""; + let buffer = ""; + var streamedMessages: Message[] = [] var respondedMessages: Message[] = [...newMessages, { content: "", role: "assistant" }] setMessages(respondedMessages); try { @@ -492,20 +496,29 @@ function App() { const { value, done: done_ } = await reader!.read(); if (value) { const decodedValue = new TextDecoder().decode(value); - chat += decodedValue; - chat = chat.replace("}][{", "}]\n[{") - const lastLineEndingWithBracket = getLastLineEndingWithBracket(chat); - const lastLine = getLastLine(chat); - if (lastLineEndingWithBracket !== null) { - try { - const addedMessages = JSON.parse(lastLineEndingWithBracket); - respondedMessages = [...newMessages, ...addedMessages] - setMessages(respondedMessages); - } catch (e: any) { - console.log(lastLineEndingWithBracket) + buffer += decodedValue; + buffer = buffer.replace("][{", "]\n[{") + var newBuffer = ""; + const bufferLines = buffer.trim().split("\n") + + for (var i = 0; i < bufferLines.length; i += 1) { + const line = bufferLines[i]; + if (line !== "") { + try { + const patch = JSON.parse(line) + streamedMessages = jsonpatch.applyPatch(streamedMessages, patch).newDocument + setMessages([...newMessages, ...streamedMessages]) + } catch (e: any) { + console.log(e.message) + console.log(decodedValue) + if (i == bufferLines.length - 1) { + newBuffer = line + } + } } - chat = lastLine } + + buffer = newBuffer } done = done_; } @@ -515,7 +528,7 @@ function App() { description: e.message, variant: "destructive" }); - console.log(chat) + console.log(buffer) setIsLoading(false); posthog.capture("chat errored", { repoName, diff --git a/sweep_chat/package-lock.json b/sweep_chat/package-lock.json index 325303167d..46d469081c 100644 --- a/sweep_chat/package-lock.json +++ b/sweep_chat/package-lock.json @@ -16,6 +16,7 @@ "@radix-ui/react-toast": "^1.1.5", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "fast-json-patch": "^3.1.1", "lucide-react": "^0.378.0", "next": "14.2.3", "next-auth": "^4.24.7", @@ -2769,6 +2770,11 @@ "node": ">= 6" } }, + "node_modules/fast-json-patch": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-3.1.1.tgz", + "integrity": "sha512-vf6IHUX2SBcA+5/+4883dsIjpBTqmfBjmYiWK1savxQmFk4JfBMLa7ynTYOs1Rolp/T1betJxHiGD3g1Mn8lUQ==" + }, "node_modules/fast-json-stable-stringify": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", diff --git a/sweep_chat/package.json b/sweep_chat/package.json index 348064534e..b16c634f28 100644 --- a/sweep_chat/package.json +++ b/sweep_chat/package.json @@ -17,6 +17,7 @@ "@radix-ui/react-toast": "^1.1.5", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "fast-json-patch": "^3.1.1", "lucide-react": "^0.378.0", "next": "14.2.3", "next-auth": "^4.24.7", diff --git a/sweepai/chat/api.py b/sweepai/chat/api.py index e2cf8c878e..9567c37ef3 100644 --- a/sweepai/chat/api.py +++ b/sweepai/chat/api.py @@ -1,3 +1,4 @@ +import jsonpatch from copy import deepcopy import json import os @@ -260,6 +261,7 @@ def chat_codebase( repo_name: str = Body(...), messages: list[Message] = Body(...), snippets: list[Snippet] = Body(...), + use_patch: bool = False ): if len(messages) == 0: raise ValueError("At least one message is required.") @@ -427,14 +429,25 @@ def stream_state(initial_user_message: str, snippets: list[Snippet], messages: l break yield new_messages - def postprocessed_stream(*args, **kwargs): + def postprocessed_stream(*args, use_patch=False, **kwargs): + previous_state = [] for messages in stream_state(*args, **kwargs): - yield json.dumps([ + # if not use_patch: + # yield json.dumps([ + # message.model_dump() + # for message in messages + # ]) + "\n" + # else: + current_state = [ message.model_dump() for message in messages - ]) + "\n" + ] + patch = jsonpatch.JsonPatch.from_diff(previous_state, current_state) + if patch: + yield patch.to_string() + "\n" + previous_state = current_state - return StreamingResponse(postprocessed_stream(messages[-1].content + "\n\n" + format_message, snippets, messages)) + return StreamingResponse(postprocessed_stream(messages[-1].content + "\n\n" + format_message, snippets, messages, use_patch=use_patch)) def handle_function_call(function_call: AnthropicFunctionCall, repo_name: str, snippets: list[Snippet]): NUM_SNIPPETS = 5 From b9c596236d2f87c856517a98c0115bf50ec24126 Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 20:43:28 +0000 Subject: [PATCH 09/11] Streaming complete --- sweep_chat/components/App.tsx | 7 ++++--- sweepai/chat/api.py | 30 +++++++++++++++--------------- 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index 797c4b6650..55d0fa4642 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -507,16 +507,17 @@ function App() { try { const patch = JSON.parse(line) streamedMessages = jsonpatch.applyPatch(streamedMessages, patch).newDocument - setMessages([...newMessages, ...streamedMessages]) } catch (e: any) { - console.log(e.message) - console.log(decodedValue) if (i == bufferLines.length - 1) { newBuffer = line + } else { + console.log(e.message) + console.log(buffer) } } } } + setMessages([...newMessages, ...streamedMessages]) buffer = newBuffer } diff --git a/sweepai/chat/api.py b/sweepai/chat/api.py index 9567c37ef3..34c8279b38 100644 --- a/sweepai/chat/api.py +++ b/sweepai/chat/api.py @@ -261,7 +261,7 @@ def chat_codebase( repo_name: str = Body(...), messages: list[Message] = Body(...), snippets: list[Snippet] = Body(...), - use_patch: bool = False + use_patch: bool = Body(False) ): if len(messages) == 0: raise ValueError("At least one message is required.") @@ -432,20 +432,20 @@ def stream_state(initial_user_message: str, snippets: list[Snippet], messages: l def postprocessed_stream(*args, use_patch=False, **kwargs): previous_state = [] for messages in stream_state(*args, **kwargs): - # if not use_patch: - # yield json.dumps([ - # message.model_dump() - # for message in messages - # ]) + "\n" - # else: - current_state = [ - message.model_dump() - for message in messages - ] - patch = jsonpatch.JsonPatch.from_diff(previous_state, current_state) - if patch: - yield patch.to_string() + "\n" - previous_state = current_state + if not use_patch: + yield json.dumps([ + message.model_dump() + for message in messages + ]) + "\n" + else: + current_state = [ + message.model_dump() + for message in messages + ] + patch = jsonpatch.JsonPatch.from_diff(previous_state, current_state) + if patch: + yield patch.to_string() + "\n" + previous_state = current_state return StreamingResponse(postprocessed_stream(messages[-1].content + "\n\n" + format_message, snippets, messages, use_patch=use_patch)) From 3da42cd34636ee0dad54c965386b5bff64ad08ce Mon Sep 17 00:00:00 2001 From: "sweep-nightly[bot]" <131841235+sweep-nightly[bot]@users.noreply.github.com> Date: Sat, 11 May 2024 20:44:31 +0000 Subject: [PATCH 10/11] feat: Updated 1 files --- sweepai/handlers/on_ticket.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sweepai/handlers/on_ticket.py b/sweepai/handlers/on_ticket.py index e88356a6d9..a998a0d478 100644 --- a/sweepai/handlers/on_ticket.py +++ b/sweepai/handlers/on_ticket.py @@ -394,7 +394,7 @@ def edit_sweep_comment( logger.warning(f"Validation error: {error_message}") edit_sweep_comment( ( - f"The issue was rejected with the following response:\n\n{blockquote(error_message)}" + f"The issue was rejected with the following response:\n\n**{error_message}**" ), -1, ) From e91f4067be6998d2f25541121055ceef674a2a4a Mon Sep 17 00:00:00 2001 From: Kevin Lu Date: Sat, 11 May 2024 20:48:45 +0000 Subject: [PATCH 11/11] Added json patch --- pyproject.toml | 1 + requirements.txt | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8de24621cb..f6e4c18802 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -79,6 +79,7 @@ dependencies = [ "scipy==1.12.0", "jira==3.8.0", "slack-sdk==3.27.1", + "jsonpatch==1.33", ] [tool.isort] diff --git a/requirements.txt b/requirements.txt index 4c24e61121..a3957167ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # This file was autogenerated by uv via the following command: -# uv pip compile pyproject.toml -o requirements.txt +# uv pip compile --output-file requirements.txt pyproject.toml aiohttp==3.9.3 # via voyageai aiolimiter==1.1.0 @@ -218,8 +218,11 @@ jmespath==1.0.1 # botocore json5==0.9.24 # via jupyterlab-server +jsonpatch==1.33 jsonpointer==2.4 - # via jsonschema + # via + # jsonpatch + # jsonschema jsonschema==4.21.1 # via # jupyter-events