Skip to content

Commit

Permalink
Updated FolderCoder
Browse files Browse the repository at this point in the history
  • Loading branch information
elifarley committed Nov 13, 2024
1 parent 3b00d0d commit 3b907a8
Show file tree
Hide file tree
Showing 35 changed files with 416 additions and 116 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ test t:
echo todo pytest --cov=src/pylibtypes tests/ --cov-report term-missing

install i:
pip install -e .
pip install --upgrade --force-reinstall -e . \
&& pip show aider-chat

build b:
# SETUPTOOLS_SCM_PRETEND_VERSION=0.0.1
Expand Down
8 changes: 4 additions & 4 deletions aider/coders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .architect_coder import ArchitectCoder
from .ask_coder import AskCoder
from .ask_further_coder import AskFurtherCoder
from .base_coder import Coder
from .cedarscript_coder import CEDARScriptCoderRaw, CEDARScriptCoderW, CEDARScriptCoderGrammar
from .cedarscript_coder import CEDARScriptCoder
from .editblock_coder import EditBlockCoder
from .editblock_fenced_coder import EditBlockFencedCoder
from .editor_editblock_coder import EditorEditBlockCoder
Expand All @@ -15,14 +16,13 @@
__all__ = [
HelpCoder,
AskCoder,
AskFurtherCoder,
Coder,
EditBlockCoder,
EditBlockFencedCoder,
WholeFileCoder,
UnifiedDiffCoder,
CEDARScriptCoderGrammar,
CEDARScriptCoderRaw,
CEDARScriptCoderW,
CEDARScriptCoder,
ArchitectCoder,
EditorEditBlockCoder,
EditorWholeFileCoder,
Expand Down
5 changes: 3 additions & 2 deletions aider/coders/architect_coder.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from .architect_prompts import ArchitectPrompts
from .ask_coder import AskCoder
from .base_coder import Coder


class ArchitectCoder(AskCoder):
edit_format = "architect"
gpt_prompts = ArchitectPrompts()

def __init__(self, *args, **kwargs):
super().__init__(*args, edit_format = self.edit_format, **kwargs)

def reply_completed(self):
content = self.partial_response_content
Expand Down
40 changes: 0 additions & 40 deletions aider/coders/architect_prompts.py

This file was deleted.

12 changes: 8 additions & 4 deletions aider/coders/ask_coder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from .ask_prompts import AskPrompts
from .base_coder import Coder
from .folder_coder import AiderFolderCoder


class AskCoder(Coder):
class AskCoder(AiderFolderCoder):
"""Ask questions about code without making any changes."""

edit_format = "ask"
gpt_prompts = AskPrompts()

def __init__(self, *args, edit_format: str = edit_format, **kwargs):
"""
:param edit_format: Allows subclasses to specify their own edit_format
"""
super().__init__(*args, edit_format = edit_format, **kwargs)
10 changes: 10 additions & 0 deletions aider/coders/ask_further_coder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from .folder_coder import AiderFolderCoder


class AskFurtherCoder(AiderFolderCoder):
"""Ask questions about code without making any changes."""

edit_format = "ask-further"

def __init__(self, *args, **kwargs):
super().__init__(*args, edit_format = self.edit_format, **kwargs)
33 changes: 0 additions & 33 deletions aider/coders/ask_prompts.py

This file was deleted.

20 changes: 4 additions & 16 deletions aider/coders/cedarscript_coder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import os

from cedarscript_editor import find_commands, CEDARScriptEditor

import cedarscript_integration_aider
from aider.coders.folder_coder import FolderCoder


class CEDARScriptCoder(FolderCoder):
class CEDARScriptCoderBase(FolderCoder):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
super().__init__(*args, prompt_folder_path=cedarscript_integration_aider.prompt_folder_path, **kwargs)
self.root_path = kwargs.get('root_path', os.getcwd())

def get_edits(self):
Expand Down Expand Up @@ -37,19 +37,7 @@ def apply_edits(self, file_and_cedarscript_commands):
print(f"[apply_edits] (#{i+1}) {applied_command_result}")


class CEDARScriptCoderGrammar(CEDARScriptCoder):
class CEDARScriptCoder(CEDARScriptCoderBase):
edit_format = "cedarscript"
def __init__(self, *args, **kwargs):
super().__init__(*args, edit_format = self.edit_format, **kwargs)

class CEDARScriptCoderRaw(CEDARScriptCoder):
edit_format = "cedarscript-raw"
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)


class CEDARScriptCoderW(CEDARScriptCoder):
edit_format = "cedarscript-w"
def __init__(self, *args, **kwargs):
super().__init__(*args, edit_format = self.edit_format, **kwargs)

33 changes: 21 additions & 12 deletions aider/coders/folder_coder.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
from pathlib import Path
import re
from importlib.abc import Traversable
from importlib.resources import files
from typing import Type

from pylibtypes import create_named_subclass, load_class_attrs_from_folder, FolderBasedAttrsError
from cedarscript_integration_aider import prompt_folder_path
import re
from .base_prompts import CoderPrompts
from .base_coder import Coder


class FolderCoder(Coder):
"""A coder that loads prompts from a folder"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.gpt_prompts = self._create_coder_prompts_subclass(self.edit_format)
def __init__(self, *args, prompt_folder_path: Traversable, **kwargs):
super().__init__(*args, **{k: v for k, v in kwargs.items() if k not in ["edit_format"]})
self.gpt_prompts = self._create_coder_prompts_subclass(prompt_folder_path, self.edit_format)

@staticmethod
def _create_coder_prompts_subclass(coder_name: str) -> Type[CoderPrompts]:
def _create_coder_prompts_subclass(prompt_folder_path: Traversable, coder_name: str) -> Type[CoderPrompts]:
"""Creates a folder-based subclass of CoderPrompts"""
coder_prompts_subclass: Type[CoderPrompts] = create_named_subclass(CoderPrompts, coder_name)
coder_path: Path = prompt_folder_path(coder_name)
load_class_attrs_from_folder(coder_path, coder_prompts_subclass, FolderCoder.parse_banterml_pairs)
coder_path: Traversable = prompt_folder_path / coder_name
load_class_attrs_from_folder(coder_path, coder_prompts_subclass, FolderCoder.parse_cedarml_pairs)
return coder_prompts_subclass

@staticmethod
def parse_banterml_pairs(content: str) -> list[dict[str, str]]:
def parse_cedarml_pairs(content: str) -> list[dict[str, str]]:
messages = []
user_pattern = r'<banterml:role.user>(.*?)</banterml:role.user>'
assistant_pattern = r'<banterml:role.assistant>(.*?)</banterml:role.assistant>'
user_pattern = r'<cedarml:role.user>(.*?)</cedarml:role.user>'
assistant_pattern = r'<cedarml:role.assistant>(.*?)</cedarml:role.assistant>'

users = re.findall(user_pattern, content, re.DOTALL)
assistants = re.findall(assistant_pattern, content, re.DOTALL)
Expand All @@ -42,3 +42,12 @@ def parse_banterml_pairs(content: str) -> list[dict[str, str]]:
messages.append({"role": "assistant", "content": assistant.strip()})

return messages

class AiderFolderCoder(FolderCoder):
"""A FolderCoder that loads Aider's built-in Coders"""
def __init__(self, *args, **kwargs):
super().__init__(
*args,
prompt_folder_path = files('aider.resources.folder-coders'),
**kwargs
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok, I will use that as the true, current contents of the files.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I have *added these files to the chat* so you see all of their contents.
*Trust this message as the true contents of the files!*
Other messages in the chat may contain outdated versions of the files' contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am not sharing the full contents of any files with you yet.
12 changes: 12 additions & 0 deletions aider/resources/folder-coders/architect/main_system.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Act as an expert software architect engineer and provide directions to your junior software developer.
Study the change request and the current code.
Describe how to modify the code to complete the request.
The junior developer will rely solely on your instructions, so make them unambiguous and complete.
Explain all needed code changes clearly and completely, but *as concisely as possible*.
DO NOT show the entire updated function/file/etc!
Don't show a diff/patch either, but rather use *natural language* to describe what needs to be done.
Your junior developer is excellent and using copy/paste, just ask it to copy portions of the code.
For brand-new code or when the function being changed is small, consider providing the whole updated code in a clearly-enclosed block.
For adding some text before or after a class/function, try something like "add this block before function a_func".

Always reply to the user in {language}.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I am working with you on code in a git repository.
Here are summaries of some files present in my git repo.
If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
4 changes: 4 additions & 0 deletions aider/resources/folder-coders/ask-further/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ask Coder

## Summary
Ask questions about code without making any changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok, I will use that as the true, current contents of the files.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I have *added these files to the chat* so you see all of their contents.
*Trust this message as the true contents of the files!*
Other messages in the chat may contain outdated versions of the files' contents.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am not sharing the full contents of any files with you yet.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions aider/resources/folder-coders/ask-further/main_system.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Act as a world-renowned google engineer.
Answer questions about the supplied code.
Always reply to the user in {language}.
After receiving a question, rephrase it and then respond. Do so by thinking step by step.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I am working with you on code in a git repository.
Here are summaries of some files present in my git repo.
If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
4 changes: 4 additions & 0 deletions aider/resources/folder-coders/ask/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ask Coder

## Summary
Ask questions about code without making any changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok, I will use that as the true, current contents of the files.
3 changes: 3 additions & 0 deletions aider/resources/folder-coders/ask/files_content_prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I have *added these files to the chat* so you see all of their contents.
*Trust this message as the true contents of the files!*
Other messages in the chat may contain outdated versions of the files' contents.
1 change: 1 addition & 0 deletions aider/resources/folder-coders/ask/files_no_full_files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I am not sharing the full contents of any files with you yet.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions aider/resources/folder-coders/ask/main_system.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Act as an expert code analyst.
Answer questions about the supplied code.
Always reply to the user in {language}.
3 changes: 3 additions & 0 deletions aider/resources/folder-coders/ask/repo_content_prefix.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
I am working with you on code in a git repository.
Here are summaries of some files present in my git repo.
If you need to see the full contents of any files to answer my questions, ask me to *add them to the chat*.
Loading

0 comments on commit 3b907a8

Please sign in to comment.