From 722182afe9e24ecdcdcc48efc1e2389d9ce2f26b Mon Sep 17 00:00:00 2001 From: wwzeng1 Date: Fri, 21 Jun 2024 21:56:25 +0000 Subject: [PATCH 1/4] update --- sweep_chat/components/App.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sweep_chat/components/App.tsx b/sweep_chat/components/App.tsx index bc4006c164..ac70468ebe 100644 --- a/sweep_chat/components/App.tsx +++ b/sweep_chat/components/App.tsx @@ -329,9 +329,10 @@ const UserMessageDisplay = ({ e.preventDefault() }} variant="default" - className="ml-2 bg-slate-600 text-white hover:bg-slate-700" + className="ml-2 bg-blue-900 text-white hover:bg-blue-800" > - Send + +   Send )} From 607ef0f57ef4f856d7a7784da17389cc3e0c924c Mon Sep 17 00:00:00 2001 From: wwzeng1 Date: Fri, 21 Jun 2024 23:38:49 +0000 Subject: [PATCH 2/4] git cleanup logic --- sweepai/utils/github_utils.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/sweepai/utils/github_utils.py b/sweepai/utils/github_utils.py index ab091bb7d3..3866dac6e8 100644 --- a/sweepai/utils/github_utils.py +++ b/sweepai/utils/github_utils.py @@ -489,6 +489,7 @@ def clone_url(self): ) def clone(self): + os.environ['GIT_LFS_SKIP_SMUDGE'] = '1' if not os.path.exists(self.cached_dir): logger.info("Cloning repo...") if self.branch: @@ -505,6 +506,7 @@ def clone(self): repo = git.Repo(self.cached_dir) repo.git.remote("set-url", "origin", self.clone_url) repo.git.clean('-fd') + self.handle_checkout_failures(git_repo=repo) repo.git.pull() logger.info("Pull repo succeeded") except Exception as e: @@ -517,6 +519,7 @@ def clone(self): ) else: repo = git.Repo.clone_from(self.clone_url, self.cached_dir) + self.handle_checkout_failures(git_repo=repo) logger.info("Copying repo...") shutil.copytree( self.cached_dir, self.repo_dir, symlinks=True, copy_function=shutil.copy @@ -542,16 +545,15 @@ def __post_init__(self): try: self.git_repo.git.checkout(self.branch) except Exception as e: - self.handle_checkout_failures() - os.environ['GIT_LFS_SKIP_SMUDGE'] = '1' + self.handle_checkout_failures(self.git_repo) self.git_repo.git.checkout(self.branch) - def handle_checkout_failures(self): - untracked_files = self.git_repo.untracked_files + def handle_checkout_failures(self, git_repo): + untracked_files = git_repo.untracked_files if untracked_files: logger.info(f"Untracked files found: {', '.join(untracked_files)}") for file in untracked_files: - file_path = os.path.join(self.git_repo.working_dir, file) + file_path = os.path.join(git_repo.working_dir, file) if os.path.isfile(file_path): logger.info(f"Removing untracked file: {file}") os.remove(file_path) @@ -562,7 +564,7 @@ def handle_checkout_failures(self): logger.info("No untracked files found") logger.info("Cleaning untracked files") - self.git_repo.git.clean('-fd') + git_repo.git.clean('-fd') def __del__(self): @@ -575,6 +577,7 @@ def __del__(self): def pull(self): if self.git_repo: self.git_repo.git.remote("set-url", "origin", self.clone_url) + self.handle_checkout_failures(self.git_repo) self.git_repo.git.pull() def list_directory_tree( From acef4abb29f37f4247ea8ce1f839ed438110c761 Mon Sep 17 00:00:00 2001 From: wwzeng1 Date: Sat, 22 Jun 2024 23:50:21 +0000 Subject: [PATCH 3/4] . --- sweepai/chat/api.py | 17 ++- sweepai/chat/search_prompts.py | 224 ++++++++++++++++++++++++++++++++- sweepai/core/entities.py | 4 + 3 files changed, 233 insertions(+), 12 deletions(-) diff --git a/sweepai/chat/api.py b/sweepai/chat/api.py index 3f47f7cd37..19db20a343 100644 --- a/sweepai/chat/api.py +++ b/sweepai/chat/api.py @@ -533,11 +533,7 @@ def chat_codebase_stream( content=snippets_message, role="user" ), - *messages[:-1], - Message( - content=anthropic_format_message, - role="user", - ) + *messages[:-1] ] def stream_state( @@ -550,7 +546,8 @@ def stream_state( use_openai: bool, k: int = DEFAULT_K ): - user_message = initial_user_message + # this is where the format and query are joined + user_message = initial_user_message + "\n" + anthropic_format_message fetched_snippets = snippets new_messages = [ @@ -857,10 +854,10 @@ async def autofix( access_token: str = Depends(get_token_header) ):# -> dict[str, Any] | StreamingResponse: # for debugging with rerun_chat_modify_direct.py - # from dataclasses import asdict - # data = [asdict(query) for query in code_suggestions] - # with open("code_suggestions.json", "w") as file: - # json.dump(data, file, indent=4) + from dataclasses import asdict + data = [asdict(query) for query in code_suggestions] + with open("code_suggestions.json", "w") as file: + json.dump(data, file, indent=4) with Timer() as timer: g = get_authenticated_github_client(repo_name, access_token) logger.debug(f"Getting authenticated GitHub client took {timer.time_elapsed} seconds") diff --git a/sweepai/chat/search_prompts.py b/sweepai/chat/search_prompts.py index 995cb0ec47..81698db727 100644 --- a/sweepai/chat/search_prompts.py +++ b/sweepai/chat/search_prompts.py @@ -141,8 +141,10 @@ -For example: +Here are some illustrative examples of how to use the tools: + +Example 1: This is a standard change that modifies a single location: src/utils/rectangle.py @@ -167,7 +169,225 @@ def area(self): -""" + anthropic_format_message +Example 2: You may need to change multiple sections of code in the same file that are far apart. Remember that the original_code must match a contiguous section of the file exactly. To make sure this is the case separate the changes like so: + + +task-management-system.ts + + + +// Enum for task priority +enum TaskPriority { + Low, + Medium, + High +} + +// Interface for task +interface Task { + id: number; + title: string; + description: string; + priority: TaskPriority; + completed: boolean; + createdAt: Date; + completedAt?: Date; +} + +// Class to represent a task +class TaskItem implements Task { + id: number; + title: string; + description: string; + priority: TaskPriority; + completed: boolean; + createdAt: Date; + completedAt?: Date; + + constructor(id: number, title: string, description: string, priority: TaskPriority) { + this.id = id; + this.title = title; + this.description = description; + this.priority = priority; + this.completed = false; + this.createdAt = new Date(); + } + + complete(): void { + this.completed = true; + this.completedAt = new Date(); + } + + updatePriority(newPriority: TaskPriority): void { + this.priority = newPriority; + } +} + +// Class to manage tasks +class TaskManager { + private tasks: TaskItem[] = []; + private nextId: number = 1; + + addTask(title: string, description: string, priority: TaskPriority): TaskItem { + const newTask = new TaskItem(this.nextId++, title, description, priority); + this.tasks.push(newTask); + return newTask; + } + + getTaskById(id: number): TaskItem | undefined { + return this.tasks.find(task => task.id === id); + } + + updateTask(id: number, updates: Partial): TaskItem | undefined { + const task = this.getTaskById(id); + if (task) { + Object.assign(task, updates); + return task; + } + return undefined; + } + + deleteTask(id: number): boolean { + const index = this.tasks.findIndex(task => task.id === id); + if (index !== -1) { + this.tasks.splice(index, 1); + return true; + } + return false; + } + + getAllTasks(): TaskItem[] { + return this.tasks; + } + + getCompletedTasks(): TaskItem[] { + return this.tasks.filter(task => task.completed); + } + + getPendingTasks(): TaskItem[] { + return this.tasks.filter(task => !task.completed); + } + + getTasksByPriority(priority: TaskPriority): TaskItem[] { + return this.tasks.filter(task => task.priority === priority); + } +} + +// Function to format date +function formatDate(date: Date): string { + return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; +} + +// Function to print task details +function printTaskDetails(task: TaskItem): void { + console.log(` + Task ID: ${task.id} + Title: ${task.title} + Description: ${task.description} + Priority: ${TaskPriority[task.priority]} + Status: ${task.completed ? 'Completed' : 'Pending'} + Created At: ${formatDate(task.createdAt)} + ${task.completedAt ? `Completed At: ${formatDate(task.completedAt)}` : ''} + `); +} + +// Usage example +const taskManager = new TaskManager(); + +// Adding tasks +const task1 = taskManager.addTask("Complete project proposal", "Write and submit the project proposal by Friday", TaskPriority.High); +const task2 = taskManager.addTask("Buy groceries", "Get milk, eggs, and bread", TaskPriority.Low); +const task3 = taskManager.addTask("Schedule team meeting", "Arrange a team meeting for next week", TaskPriority.Medium); + +// Completing a task +task2.complete(); + +// Updating task priority +taskManager.updateTask(3, { priority: TaskPriority.High }); + +// Deleting a task +taskManager.deleteTask(2); + +// Retrieving tasks +console.log("All tasks:"); +taskManager.getAllTasks().forEach(printTaskDetails); + +console.log("Completed tasks:"); +taskManager.getCompletedTasks().forEach(printTaskDetails); + +console.log("Pending tasks:"); +taskManager.getPendingTasks().forEach(printTaskDetails); + +console.log("High priority tasks:"); +taskManager.getTasksByPriority(TaskPriority.High).forEach(printTaskDetails); + +// Error handling example +try { + const nonExistentTask = taskManager.getTaskById(999); + if (!nonExistentTask) { + throw new Error("Task not found"); + } +} catch (error) { + console.error("An error occurred:", (error as Error).message); +} + +// Example of using generics +function getLast(arr: T[]): T | undefined { + return arr[arr.length - 1]; +} + +const lastTask = getLast(taskManager.getAllTasks()); +if (lastTask) { + console.log("Last added task:"); + printTaskDetails(lastTask); +} + + + +Here we separate the changes into two blocks. We also used existing code as a reference to edit an existing enum and append a new function to the class: + + + +task-management-system.ts + + +enum TaskPriority { + Low, + Medium, + High +} + + +enum TaskPriority { + Low, + Medium, + High, + Urgent +} + + + + + +task-management-system.ts + + + getTasksByPriority(priority: TaskPriority): TaskItem[] { + return this.tasks.filter(task => task.priority === priority); + } + + + getTasksByPriority(priority: TaskPriority): TaskItem[] { + return this.tasks.filter(task => task.priority === priority); + } + + getTasksSortedByPriority(): TaskItem[] { + return [...this.tasks].sort((a, b) => b.priority - a.priority); + } + + + +""" action_items_system_prompt = """You are a tech lead helping to break down a conversation about an issue into subtasks for an intern to solve. Identify every single one of the suggested changes. Be complete. The changes should be atomic. diff --git a/sweepai/core/entities.py b/sweepai/core/entities.py index 457b8baef5..e07d2eafff 100644 --- a/sweepai/core/entities.py +++ b/sweepai/core/entities.py @@ -50,6 +50,10 @@ def to_openai(self) -> str: obj["name"] = self.name return obj + def __repr__(self): + # take the first 100 and last 100 characters of the message if it's too long + truncated_message_content = self.content[:100] + "..." + self.content[-100:] if len(self.content) > 200 else self.content + return f"START OF MESSAGE\n\n{truncated_message_content}\n\nROLE: {self.role} FUNCTION_CALL: {self.function_call} NAME: {self.name} ANNOTATIONS: {self.annotations if self.annotations else ''} KEY: {self.key}\n\nEND OF MESSAGE\n\n" class Function(BaseModel): class Parameters(BaseModel): From eba846676f14585ad3e913a70de616db8c7cf885 Mon Sep 17 00:00:00 2001 From: William Zeng <44910023+wwzeng1@users.noreply.github.com> Date: Sun, 23 Jun 2024 13:56:39 -0700 Subject: [PATCH 4/4] Update search_prompts.py --- sweepai/chat/search_prompts.py | 225 +-------------------------------- 1 file changed, 2 insertions(+), 223 deletions(-) diff --git a/sweepai/chat/search_prompts.py b/sweepai/chat/search_prompts.py index 269083cb3c..366ee2335f 100644 --- a/sweepai/chat/search_prompts.py +++ b/sweepai/chat/search_prompts.py @@ -142,10 +142,8 @@ -Here are some illustrative examples of how to use the tools: +For example: - -Example 1: This is a standard change that modifies a single location: src/utils/rectangle.py @@ -170,225 +168,7 @@ def area(self): -Example 2: You may need to change multiple sections of code in the same file that are far apart. Remember that the original_code must match a contiguous section of the file exactly. To make sure this is the case separate the changes like so: - - -task-management-system.ts - - - -// Enum for task priority -enum TaskPriority { - Low, - Medium, - High -} - -// Interface for task -interface Task { - id: number; - title: string; - description: string; - priority: TaskPriority; - completed: boolean; - createdAt: Date; - completedAt?: Date; -} - -// Class to represent a task -class TaskItem implements Task { - id: number; - title: string; - description: string; - priority: TaskPriority; - completed: boolean; - createdAt: Date; - completedAt?: Date; - - constructor(id: number, title: string, description: string, priority: TaskPriority) { - this.id = id; - this.title = title; - this.description = description; - this.priority = priority; - this.completed = false; - this.createdAt = new Date(); - } - - complete(): void { - this.completed = true; - this.completedAt = new Date(); - } - - updatePriority(newPriority: TaskPriority): void { - this.priority = newPriority; - } -} - -// Class to manage tasks -class TaskManager { - private tasks: TaskItem[] = []; - private nextId: number = 1; - - addTask(title: string, description: string, priority: TaskPriority): TaskItem { - const newTask = new TaskItem(this.nextId++, title, description, priority); - this.tasks.push(newTask); - return newTask; - } - - getTaskById(id: number): TaskItem | undefined { - return this.tasks.find(task => task.id === id); - } - - updateTask(id: number, updates: Partial): TaskItem | undefined { - const task = this.getTaskById(id); - if (task) { - Object.assign(task, updates); - return task; - } - return undefined; - } - - deleteTask(id: number): boolean { - const index = this.tasks.findIndex(task => task.id === id); - if (index !== -1) { - this.tasks.splice(index, 1); - return true; - } - return false; - } - - getAllTasks(): TaskItem[] { - return this.tasks; - } - - getCompletedTasks(): TaskItem[] { - return this.tasks.filter(task => task.completed); - } - - getPendingTasks(): TaskItem[] { - return this.tasks.filter(task => !task.completed); - } - - getTasksByPriority(priority: TaskPriority): TaskItem[] { - return this.tasks.filter(task => task.priority === priority); - } -} - -// Function to format date -function formatDate(date: Date): string { - return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; -} - -// Function to print task details -function printTaskDetails(task: TaskItem): void { - console.log(` - Task ID: ${task.id} - Title: ${task.title} - Description: ${task.description} - Priority: ${TaskPriority[task.priority]} - Status: ${task.completed ? 'Completed' : 'Pending'} - Created At: ${formatDate(task.createdAt)} - ${task.completedAt ? `Completed At: ${formatDate(task.completedAt)}` : ''} - `); -} - -// Usage example -const taskManager = new TaskManager(); - -// Adding tasks -const task1 = taskManager.addTask("Complete project proposal", "Write and submit the project proposal by Friday", TaskPriority.High); -const task2 = taskManager.addTask("Buy groceries", "Get milk, eggs, and bread", TaskPriority.Low); -const task3 = taskManager.addTask("Schedule team meeting", "Arrange a team meeting for next week", TaskPriority.Medium); - -// Completing a task -task2.complete(); - -// Updating task priority -taskManager.updateTask(3, { priority: TaskPriority.High }); - -// Deleting a task -taskManager.deleteTask(2); - -// Retrieving tasks -console.log("All tasks:"); -taskManager.getAllTasks().forEach(printTaskDetails); - -console.log("Completed tasks:"); -taskManager.getCompletedTasks().forEach(printTaskDetails); - -console.log("Pending tasks:"); -taskManager.getPendingTasks().forEach(printTaskDetails); - -console.log("High priority tasks:"); -taskManager.getTasksByPriority(TaskPriority.High).forEach(printTaskDetails); - -// Error handling example -try { - const nonExistentTask = taskManager.getTaskById(999); - if (!nonExistentTask) { - throw new Error("Task not found"); - } -} catch (error) { - console.error("An error occurred:", (error as Error).message); -} - -// Example of using generics -function getLast(arr: T[]): T | undefined { - return arr[arr.length - 1]; -} - -const lastTask = getLast(taskManager.getAllTasks()); -if (lastTask) { - console.log("Last added task:"); - printTaskDetails(lastTask); -} - - - -Here we separate the changes into two blocks. We also used existing code as a reference to edit an existing enum and append a new function to the class: - - - -task-management-system.ts - - -enum TaskPriority { - Low, - Medium, - High -} - - -enum TaskPriority { - Low, - Medium, - High, - Urgent -} - - - - - -task-management-system.ts - - - getTasksByPriority(priority: TaskPriority): TaskItem[] { - return this.tasks.filter(task => task.priority === priority); - } - - - getTasksByPriority(priority: TaskPriority): TaskItem[] { - return this.tasks.filter(task => task.priority === priority); - } - - getTasksSortedByPriority(): TaskItem[] { - return [...this.tasks].sort((a, b) => b.priority - a.priority); - } - - - -""" +""" + anthropic_format_message action_items_system_prompt = """You are a tech lead helping to break down a conversation about an issue into subtasks for an intern to solve. Identify every single one of the suggested changes. Be complete. The changes should be atomic. @@ -551,4 +331,3 @@ def area(self): Just respond with the search query, nothing else.""" query_optimizer_user_prompt = """Question: {query}""" -