mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-08 21:55:00 +00:00
Merge branch 'main' into ask-plan-simple
This commit is contained in:
commit
83662b7470
49 changed files with 1318 additions and 448 deletions
|
@ -18,16 +18,12 @@ from datetime import datetime
|
|||
from json.decoder import JSONDecodeError
|
||||
from pathlib import Path
|
||||
|
||||
from rich.console import Console, Text
|
||||
from rich.markdown import Markdown
|
||||
|
||||
from aider import __version__, models, prompts, urls, utils
|
||||
from aider.commands import Commands
|
||||
from aider.history import ChatSummary
|
||||
from aider.io import ConfirmGroup, InputOutput
|
||||
from aider.linter import Linter
|
||||
from aider.llm import litellm
|
||||
from aider.mdstream import MarkdownStream
|
||||
from aider.repo import ANY_GIT_ERROR, GitRepo
|
||||
from aider.repomap import RepoMap
|
||||
from aider.run_cmd import run_cmd
|
||||
|
@ -241,8 +237,6 @@ class Coder:
|
|||
dry_run=False,
|
||||
map_tokens=1024,
|
||||
verbose=False,
|
||||
assistant_output_color="blue",
|
||||
code_theme="default",
|
||||
stream=True,
|
||||
use_git=True,
|
||||
cur_messages=None,
|
||||
|
@ -315,17 +309,10 @@ class Coder:
|
|||
|
||||
self.auto_commits = auto_commits
|
||||
self.dirty_commits = dirty_commits
|
||||
self.assistant_output_color = assistant_output_color
|
||||
self.code_theme = code_theme
|
||||
|
||||
self.dry_run = dry_run
|
||||
self.pretty = self.io.pretty
|
||||
|
||||
if self.pretty:
|
||||
self.console = Console()
|
||||
else:
|
||||
self.console = Console(force_terminal=False, no_color=True)
|
||||
|
||||
self.main_model = main_model
|
||||
|
||||
if cache_prompts and self.main_model.cache_control:
|
||||
|
@ -923,10 +910,21 @@ class Coder:
|
|||
lazy_prompt = self.gpt_prompts.lazy_prompt if self.main_model.lazy else ""
|
||||
platform_text = self.get_platform_info()
|
||||
|
||||
if self.suggest_shell_commands:
|
||||
shell_cmd_prompt = self.gpt_prompts.shell_cmd_prompt.format(platform=platform_text)
|
||||
shell_cmd_reminder = self.gpt_prompts.shell_cmd_reminder.format(platform=platform_text)
|
||||
else:
|
||||
shell_cmd_prompt = self.gpt_prompts.no_shell_cmd_prompt.format(platform=platform_text)
|
||||
shell_cmd_reminder = self.gpt_prompts.no_shell_cmd_reminder.format(
|
||||
platform=platform_text
|
||||
)
|
||||
|
||||
prompt = prompt.format(
|
||||
fence=self.fence,
|
||||
lazy_prompt=lazy_prompt,
|
||||
platform=platform_text,
|
||||
shell_cmd_prompt=shell_cmd_prompt,
|
||||
shell_cmd_reminder=shell_cmd_reminder,
|
||||
)
|
||||
return prompt
|
||||
|
||||
|
@ -968,9 +966,16 @@ class Coder:
|
|||
|
||||
chunks = ChatChunks()
|
||||
|
||||
chunks.system = [
|
||||
dict(role="system", content=main_sys),
|
||||
]
|
||||
if self.main_model.use_system_prompt:
|
||||
chunks.system = [
|
||||
dict(role="system", content=main_sys),
|
||||
]
|
||||
else:
|
||||
chunks.system = [
|
||||
dict(role="user", content=main_sys),
|
||||
dict(role="assistant", content="Ok."),
|
||||
]
|
||||
|
||||
chunks.examples = example_messages
|
||||
|
||||
self.summarize_end()
|
||||
|
@ -1096,11 +1101,7 @@ class Coder:
|
|||
utils.show_messages(messages, functions=self.functions)
|
||||
|
||||
self.multi_response_content = ""
|
||||
if self.show_pretty() and self.stream:
|
||||
mdargs = dict(style=self.assistant_output_color, code_theme=self.code_theme)
|
||||
self.mdstream = MarkdownStream(mdargs=mdargs)
|
||||
else:
|
||||
self.mdstream = None
|
||||
self.mdstream = self.io.assistant_output("", self.stream)
|
||||
|
||||
retry_delay = 0.125
|
||||
|
||||
|
@ -1380,6 +1381,11 @@ class Coder:
|
|||
|
||||
self.io.log_llm_history("TO LLM", format_messages(messages))
|
||||
|
||||
if self.main_model.use_temperature:
|
||||
temp = self.temperature
|
||||
else:
|
||||
temp = None
|
||||
|
||||
completion = None
|
||||
try:
|
||||
hash_object, completion = send_completion(
|
||||
|
@ -1387,7 +1393,7 @@ class Coder:
|
|||
messages,
|
||||
functions,
|
||||
self.stream,
|
||||
self.temperature,
|
||||
temp,
|
||||
extra_headers=model.extra_headers,
|
||||
max_tokens=model.max_tokens,
|
||||
)
|
||||
|
@ -1452,14 +1458,7 @@ class Coder:
|
|||
raise Exception("No data found in LLM response!")
|
||||
|
||||
show_resp = self.render_incremental_response(True)
|
||||
if self.show_pretty():
|
||||
show_resp = Markdown(
|
||||
show_resp, style=self.assistant_output_color, code_theme=self.code_theme
|
||||
)
|
||||
else:
|
||||
show_resp = Text(show_resp or "<no response>")
|
||||
|
||||
self.io.console.print(show_resp)
|
||||
self.io.assistant_output(show_resp)
|
||||
|
||||
if (
|
||||
hasattr(completion.choices[0], "finish_reason")
|
||||
|
@ -1880,7 +1879,6 @@ class Coder:
|
|||
message=commit_message,
|
||||
)
|
||||
|
||||
self.io.tool_output("No changes made to git tracked files.")
|
||||
return self.gpt_prompts.files_content_gpt_no_edits
|
||||
except ANY_GIT_ERROR as err:
|
||||
self.io.tool_error(f"Unable to commit: {str(err)}")
|
||||
|
@ -1899,6 +1897,8 @@ class Coder:
|
|||
return
|
||||
if self.commit_before_message[-1] != self.repo.get_head_commit_sha():
|
||||
self.io.tool_output("You can use /undo to undo and discard each aider commit.")
|
||||
else:
|
||||
self.io.tool_output("No changes made to git tracked files.")
|
||||
|
||||
def dirty_commit(self):
|
||||
if not self.need_commit_before_edits:
|
||||
|
|
|
@ -43,3 +43,8 @@ If you need to edit any of these files, ask me to *add them to the chat* first.
|
|||
read_only_files_prefix = """Here are some READ ONLY files, provided for your reference.
|
||||
Do not edit these files!
|
||||
"""
|
||||
|
||||
shell_cmd_prompt = ""
|
||||
shell_cmd_reminder = ""
|
||||
no_shell_cmd_prompt = ""
|
||||
no_shell_cmd_reminder = ""
|
||||
|
|
|
@ -31,10 +31,12 @@ class ChatChunks:
|
|||
else:
|
||||
self.add_cache_control(self.system)
|
||||
|
||||
if self.readonly_files:
|
||||
self.add_cache_control(self.readonly_files)
|
||||
else:
|
||||
if self.repo:
|
||||
# this will mark both the readonly_files and repomap chunk as cacheable
|
||||
self.add_cache_control(self.repo)
|
||||
else:
|
||||
# otherwise, just cache readonly_files if there are any
|
||||
self.add_cache_control(self.readonly_files)
|
||||
|
||||
self.add_cache_control(self.chat_files)
|
||||
|
||||
|
|
|
@ -9,8 +9,32 @@ class EditBlockPrompts(CoderPrompts):
|
|||
Describe each change with a *SEARCH/REPLACE block* per the examples below.
|
||||
All changes to files must use this *SEARCH/REPLACE block* format.
|
||||
ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
|
||||
{shell_cmd_prompt}
|
||||
"""
|
||||
|
||||
shell_cmd_prompt = """
|
||||
4. *Concisely* suggest any shell commands the user might want to run in ```bash blocks.
|
||||
|
||||
Just suggest shell commands this way, not example code.
|
||||
Only suggest complete shell commands that area ready to execute, without placeholders.
|
||||
Only suggest at most a few shell commands at a time, not more than 1-3.
|
||||
|
||||
Use the appropriate shell based on the user's system info:
|
||||
{platform}
|
||||
Examples of when to suggest shell commands:
|
||||
|
||||
- If you changed a self-contained html file, suggest an OS-appropriate command to open a browser to view it to see the updated content.
|
||||
- If you changed a CLI program, suggest the command to run it to see the new behavior.
|
||||
- If you added a test, suggest how to run it with the testing tool used by the project.
|
||||
- Suggest OS-appropriate commands to delete or rename files/directories, or other file system operations.
|
||||
- If your code changes add new dependencies, suggest the command to install them.
|
||||
- Etc.
|
||||
"""
|
||||
|
||||
no_shell_cmd_prompt = """
|
||||
Keep in mind these details about the user's platform and environment:
|
||||
{platform}
|
||||
"""
|
||||
example_messages = [
|
||||
dict(
|
||||
role="user",
|
||||
|
@ -127,4 +151,16 @@ To rename files which have been added to the chat, use shell commands at the end
|
|||
|
||||
{lazy_prompt}
|
||||
ONLY EVER RETURN CODE IN A *SEARCH/REPLACE BLOCK*!
|
||||
{shell_cmd_reminder}
|
||||
"""
|
||||
|
||||
shell_cmd_reminder = """
|
||||
Examples of when to suggest shell commands:
|
||||
|
||||
- If you changed a self-contained html file, suggest an OS-appropriate command to open a browser to view it to see the updated content.
|
||||
- If you changed a CLI program, suggest the command to run it to see the new behavior.
|
||||
- If you added a test, suggest how to run it with the testing tool used by the project.
|
||||
- Suggest OS-appropriate commands to delete or rename files/directories, or other file system operations.
|
||||
- If your code changes add new dependencies, suggest the command to install them.
|
||||
- Etc.
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue