Skip to content

Commit

Permalink
Feat/bug fix with regex (#4023)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlu1248 authored Jun 16, 2024
2 parents e589ab9 + 559f85d commit 6dc1689
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 35 deletions.
22 changes: 13 additions & 9 deletions sweep_chat/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
pre {
padding-top: 0.5rem;
padding-bottom: 0.5rem;
margin-top: 0.5rem;
margin-bottom: 0.5rem;
/* margin-top: 0.5rem; */
/* margin-bottom: 0.5rem; */
color: salmon;
> code {
padding: 1rem
Expand All @@ -90,13 +90,13 @@
h2 {
font-size: 1.5rem;
margin-top: 1rem;
margin-bottom: 1.5rem;
/* margin-bottom: 1.5rem; */
}

h3 {
font-size: 1.25rem;
margin-top: 1rem;
margin-bottom: 0.75rem;
/* margin-bottom: 0.75rem; */
}

code {
Expand All @@ -116,27 +116,31 @@

ol,ul {
margin-top: 1rem;
margin-bottom: 1rem;
/* margin-bottom: 1rem; */
margin-left: 1.5rem;

ol,ul {
margin-top: 0.5rem;
margin-bottom: 0.5rem;
/* margin-bottom: 0.5rem; */
}

li {
margin-top: 0.25rem;
}
}

a {
color: lightblue;
text-decoration: underline;
}

p:not(:first-child) {
margin-top: 0.75rem;
}

p:not(:last-child) {
/* p:not(:last-child) {
margin-bottom: 0.75rem;
}
} */
}

.hljs-addition {
Expand Down
67 changes: 44 additions & 23 deletions sweep_chat/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,11 @@ const MessageDisplay = ({
${message.role === "assistant" ? "py-1" : ""} ${className || roleToColor[message.role]}`}
>
{message.role === "function" ? (
<Accordion type="single" collapsible className="w-full" defaultValue={((message.content && message.function_call?.function_name === "search_codebase") || (message.function_call?.snippets?.length !== undefined && message.function_call?.snippets?.length > 0)) ? "function" : undefined}>
<Accordion
type="single"
collapsible className="w-full"
defaultValue={((message.content && message.function_call?.function_name === "search_codebase") || (message.function_call?.snippets?.length !== undefined && message.function_call?.snippets?.length > 0)) ? "function" : undefined}
>
<AccordionItem value="function" className="border-none">
<AccordionTrigger className="border-none py-0 text-left">
<div className="text-xs text-gray-400 flex align-center">
Expand Down Expand Up @@ -794,10 +798,15 @@ function App({
var streamedMessages: Message[] = []
var respondedMessages: Message[] = [...newMessages, { content: "", role: "assistant" } as Message]
setMessages(respondedMessages);
let messageLength = newMessages.length;
try {
for await (const patch of streamMessages(reader, isStream)) {
streamedMessages = jsonpatch.applyPatch(streamedMessages, patch).newDocument
setMessages([...newMessages, ...streamedMessages])
if (streamedMessages.length > messageLength) {
save(repoName, newMessages, currentSnippets, suggestedChanges, pullRequest)
messageLength = streamedMessages.length;
}
}
if (!isStream.current) {
reader!.cancel()
Expand Down Expand Up @@ -1071,30 +1080,39 @@ function App({
}))
}), // TODO: casing should be automatically handled
});
const data = await response.json();
console.log(data)
if (data.modify_files_dict) {
setSuggestedChanges(Object.entries(data.modify_files_dict).map(([filePath, { original_contents, contents }]: any) => ({
filePath,
originalCode: original_contents,
newCode: contents,
})))
save(repoName, messages, snippets, suggestedChanges, pullRequest)
setIsProcessingSuggestedChanges(false);
try {
const data = await response.json();
console.log(data)
if (data.modify_files_dict) {
setSuggestedChanges(Object.entries(data.modify_files_dict).map(([filePath, { original_contents, contents }]: any) => ({
filePath,
originalCode: original_contents,
newCode: contents,
})))
save(repoName, messages, snippets, suggestedChanges, pullRequest)
setIsProcessingSuggestedChanges(false);

const prMetadata = await authorizedFetch("/backend/create_pull_metadata", {
body: JSON.stringify({
repo_name: repoName,
modify_files_dict: data.modify_files_dict,
messages: messages,
}),
const prMetadata = await authorizedFetch("/backend/create_pull_metadata", {
body: JSON.stringify({
repo_name: repoName,
modify_files_dict: data.modify_files_dict,
messages: messages,
}),
})

const prData = await prMetadata.json()
const { title, description, branch: featureBranch } = prData
setFeatureBranch(featureBranch || "sweep-chat-suggested-changes-" + new Date().toISOString().slice(0, 19).replace('T', '_').replace(':', '_'))
setPullRequestTitle(title || "Sweep Chat Suggested Changes")
setPullRequestBody(description || "Suggested changes by Sweep Chat.")
}
} catch {
toast({
title: "Failed to auto-fix changes!",
description: "This feature is still under development, so it's not completely reliable yet. We'll fix this for you shortly.",
variant: "destructive",
duration: Infinity,
})

const prData = await prMetadata.json()
const { title, description, branch: featureBranch } = prData
setFeatureBranch(featureBranch || "sweep-chat-suggested-changes-" + new Date().toISOString().slice(0, 19).replace('T', '_').replace(':', '_'))
setPullRequestTitle(title || "Sweep Chat Suggested Changes")
setPullRequestBody(description || "Suggested changes by Sweep Chat.")
}
})();
setTimeout(() => {
Expand Down Expand Up @@ -1237,6 +1255,9 @@ function App({
window.history.pushState({}, '', '/');
setSuggestedChanges([])
setPullRequest(null)
setFeatureBranch(null)
setPullRequestTitle(null)
setPullRequestBody(null)
}}
disabled={isLoading}
>
Expand Down
24 changes: 21 additions & 3 deletions sweep_chat/components/shared/SnippetBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ import { typeNameToColor, codeStyle } from "@/lib/constants";
import { sliceLines } from "@/lib/str_utils";
import { Snippet } from "@/lib/types";
import { HoverCard, HoverCardTrigger, HoverCardContent } from "@/components/ui/hover-card";
import SyntaxHighlighter from "react-syntax-highlighter";
import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { Button } from "../ui/button";

const MutePath = ({ path }: { path: string }) => {
return (
<span>
<span className="text-gray-400">{path.substring(0, path.lastIndexOf('/') + 1)}</span>
<span className="text-white">{path.substring(path.lastIndexOf('/') + 1)}</span>
</span>
);
}

const getLanguage = (filePath: string) => {
return filePath.split('.').pop();
}

const SnippetBadge = ({
snippet,
className,
Expand All @@ -27,7 +40,12 @@ const SnippetBadge = ({
}}>
<span>
{snippet.end > snippet.content.split('\n').length - 3 && snippet.start == 0 ?
snippet.file_path : `${snippet.file_path}:${snippet.start}-${snippet.end}`
<MutePath path={snippet.file_path} /> : (
<>
<MutePath path={snippet.file_path}/>
<span className="text-gray-400">:{snippet.start}-{snippet.end}</span>
</>
)
}
</span>
{
Expand All @@ -41,7 +59,7 @@ const SnippetBadge = ({
<HoverCardContent className="w-[800px] mr-2" style={{ opacity: 1 }}>
<SyntaxHighlighter
PreTag="div"
language="python"
language={getLanguage(snippet.file_path)}
style={codeStyle}
customStyle={{
backgroundColor: 'transparent',
Expand Down
1 change: 1 addition & 0 deletions sweep_chat/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const config = {
'./components/**/*.{ts,tsx}',
'./app/**/*.{ts,tsx}',
'./src/**/*.{ts,tsx}',
'./lib/**/*.{ts,tsx}',
],
prefix: "",
theme: {
Expand Down

0 comments on commit 6dc1689

Please sign in to comment.