Skip to content

Commit 33566fc

Browse files
committed
Add debugging advice to AICodeBot
🤖 Add debugging advice to AICodeBot Usage: aicodebot debug $command_that_fails
1 parent 429421f commit 33566fc

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
AICodeBot is a coding assistant designed to make your coding life easier. With capabilities to perform code reviews, manage dependencies, and even suggest improvements, think of it as your AI version of a pair programmer.
66

7-
⚠️ Status: This project is in its infancy with very limited features. Sometimes it does dumb things.
7+
⚠️ Status: This project is in its infancy with very limited features. Sometimes it does dumb things.
88

99
Right now, it only generates commit messages for you, but you can look at the Features list below to get an idea of where it is going. Give the project a star and follow along while we build out more of the foundation.
1010

@@ -27,6 +27,7 @@ Options:
2727
Commands:
2828
alignment Get a message about Heart-Centered AI Alignment ❤ + 🤖.
2929
commit Generate a git commit message and commit changes after you...
30+
debug Run a command and get debugging advice if it fails.
3031
fun-fact Tell me something interesting about programming or AI.
3132
version Print the version number.
3233
```
@@ -36,9 +37,9 @@ Commands:
3637
### Code Workflow Improvements
3738
3839
- [X] **Assisted Git Commit**: Automatically generate a commit message.
40+
- [X] **Assisted Debugging**: Run a command with aicodebot and it captures the log message and tries to figure out what's going on from the error message. Eventually, it could also suggest fixes for the error and make the changes for you. Try it out with `aicodebot debug $command`
3941
- [ ] **Code Review**: Provides feedback on potential issues in code, such as style violations, potential bugs, and performance issues. It could also suggest best practices for code improvement. Eventually: FIX the code automatically and notify the team.
4042
- [ ] **Dependency Management**: Updating dependencies to their latest versions with pull requests that run tests.
41-
- [ ] **Assisted Debugging**: Run a command with aicodebot and it captures the log message and tries to figure out what's going on from the error message. Eventually, it could also suggest fixes for the error and make the changes for you.
4243
- [ ] **Documentation Generation**: Generates comprehensive documentation for code, including docstrings, README files, and wiki pages.
4344
- [ ] **Performance Optimization Suggestions**: Suggests potential performance optimizations for code.
4445
- [ ] **Code Formatting**: Automatically formats code according to a specified style guide.

aicodebot/cli.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# Create a Console object
1414
console = Console()
1515
bot_style = Style(color="#30D5C8")
16+
DEFAULT_MAX_TOKENS = 1024
1617

1718

1819
def setup_environment():
@@ -69,7 +70,7 @@ def alignment(verbose):
6970
prompt = load_prompt(Path(__file__).parent / "prompts" / "alignment.yaml")
7071

7172
# Set up the language model
72-
llm = OpenAI(temperature=1, max_tokens=1024)
73+
llm = OpenAI(temperature=1, max_tokens=DEFAULT_MAX_TOKENS)
7374

7475
# Set up the chain
7576
chain = LLMChain(llm=llm, prompt=prompt, verbose=verbose)
@@ -142,6 +143,45 @@ def commit(verbose, max_tokens, yes):
142143
Path.unlink(temp_file_name)
143144

144145

146+
@cli.command(context_settings={"ignore_unknown_options": True})
147+
@click.argument("command", nargs=-1)
148+
@click.option("-v", "--verbose", count=True)
149+
def debug(command, verbose):
150+
"""Run a command and get debugging advice if it fails."""
151+
setup_environment()
152+
153+
# Load the prompt
154+
prompt = load_prompt(Path(__file__).parent / "prompts" / "debug.yaml")
155+
156+
# Set up the language model
157+
llm = OpenAI(temperature=0.1, max_tokens=DEFAULT_MAX_TOKENS)
158+
159+
# Set up the chain
160+
chat_chain = LLMChain(llm=llm, prompt=prompt, verbose=verbose)
161+
command_str = " ".join(command)
162+
163+
# Run the command and capture its output
164+
console.print(f"Running:\n{command_str}")
165+
process = subprocess.run(command_str, shell=True, capture_output=True, text=True) # noqa: S602
166+
167+
# Print the output of the command
168+
output = f"Standard Output:\n{process.stdout}\nStandard Error:\n{process.stderr}"
169+
console.print(f"Output:\n{output}")
170+
171+
# Print a message about the exit status
172+
if process.returncode == 0:
173+
console.print("The command completed successfully.")
174+
else:
175+
console.print(f"The command exited with status {process.returncode}.")
176+
177+
# If the command failed, send its output to ChatGPT for analysis
178+
if process.returncode != 0:
179+
error_output = process.stderr
180+
with console.status("Thinking", spinner="point"):
181+
response = chat_chain.run(error_output)
182+
console.print(response, style=bot_style)
183+
184+
145185
@cli.command()
146186
@click.option("-v", "--verbose", count=True)
147187
def fun_fact(verbose):
@@ -152,7 +192,7 @@ def fun_fact(verbose):
152192
prompt = load_prompt(Path(__file__).parent / "prompts" / "fun_fact.yaml")
153193

154194
# Set up the language model
155-
llm = ChatOpenAI(temperature=1, max_tokens=1024)
195+
llm = ChatOpenAI(temperature=1, max_tokens=DEFAULT_MAX_TOKENS)
156196

157197
# Set up the chain
158198
chat_chain = LLMChain(llm=llm, prompt=prompt, verbose=verbose)

aicodebot/prompts/debug.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
_type: prompt
2+
template_format: f-string
3+
input_variables: ["command_output"]
4+
template: |
5+
I ran a command my terminal, and it failed.
6+
7+
Here's the output:
8+
9+
BEGIN OUTPUT
10+
{command_output}
11+
END OUTPUT
12+
13+
Help me understand what happened and how might I be able to fix it.

0 commit comments

Comments
 (0)