mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-01 02:05:00 +00:00
![]() # Context: USER: `Coder.get_commit_message()` uses gpt-3.5-turbo to summarize the diffs into a sensible commit message. If the diff is large, it exceeds the 4K context window. A simple fix would be: 1. Check if the diff is close to or larger than 4 kbytes (4k tokens * 4 bytes/token) and don't even bother sending the messages to gpt. Just return. 2. Catch the `openai.error.InvalidRequestError` and just return. Maybe print a nice tool_error() message for each of these. ASSISTANT: To implement the suggested changes, we will modify the `get_commit_message()` method in the `aider/coder.py` file. Here are the step-by-step changes: 1. Check if the length of `diffs` is close to or larger than 4 kbytes (4k tokens * 4 bytes/token). If it is, print an error message and return. 2. Catch the `openai.error.InvalidRequestError` exception when calling `self.send()` and print an error message, then return. Here are the code changes: ```python aider/coder.py <<<<<<< ORIGINAL def get_commit_message(self, diffs, context): diffs = "# Diffs:\n" + diffs messages = [ dict(role="system", content=prompts.commit_system), dict(role="user", content=context + diffs), ] commit_message, interrupted = self.send( messages, model="gpt-3.5-turbo", silent=True, ) ======= def get_commit_message(self, diffs, context): if len(diffs) >= 4 * 1024 * 4: self.io.tool_error("Diff is too large for gpt-3.5-turbo to generate a commit message.") return diffs = "# Diffs:\n" + diffs messages = [ dict(role="system", content=prompts.commit_system), dict(role="user", content=context + diffs), ] try: commit_message, interrupted = self.send( messages, model="gpt-3.5-turbo", silent=True, ) except openai.error.InvalidRequestError: self.io.tool_error("Failed to generate commit message using gpt-3.5-turbo due to an invalid request.") return >>>>>>> UPDATED ``` |
||
---|---|---|
.. | ||
__init__.py | ||
coder.py | ||
commands.py | ||
ctags.py | ||
dump.py | ||
io.py | ||
main.py | ||
prompts.py | ||
utils.py |