Porównaj commity

...

30 Commity

Autor SHA1 Wiadomość Data
biobootloader 2f5a026ff9
Merge pull request #16 from prayagnshah/main
adding flag for user confirmation
2023-04-15 11:20:20 -07:00
biobootloader c20b79ea28
Update wolverine.py 2023-04-15 11:20:12 -07:00
biobootloader 10fd162ce3
Merge pull request #22 from AlessandroAnnini/main
feat:  can debug javascript files
2023-04-15 11:10:21 -07:00
Alessandro Annini 0f538fecae chore: update buggy js script file 2023-04-15 10:10:59 +02:00
Alessandro Annini 8abc8893bb refactor: better implementation fr py/js files execution 2023-04-15 10:10:34 +02:00
Alessandro Annini 05803e8592 Merge remote-tracking branch 'upstream/main' 2023-04-15 10:01:19 +02:00
Prayag Shah c12575af38
Merge branch 'main' into main 2023-04-15 02:32:58 -03:00
Prayag Shah fdbaaa3e84 updated the flag --confirm as required
- Updated the flag --confirm=True which will allow user to say yes or no before making changes to the file.
- If flag is not used then it will right away make changes to the file.
- Updated the readme with an example.
2023-04-15 02:28:13 -03:00
Prayag Shah 946e15ff20 Squashed commit of the following:
commit 742aaaf9d1
Merge: f2d21e7 fe87faa
Author: biobootloader <128252497+biobootloader@users.noreply.github.com>
Date:   Fri Apr 14 15:44:12 2023 -0700

    Merge pull request #13 from fsboehme/main

    more robust parsing of JSON (+ indentation)

commit fe87faa2fb
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 17:49:48 2023 -0400

    cleanup

commit 4db9d1bf43
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 17:49:09 2023 -0400

    more cleanup

commit e1d0a790f8
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 17:46:18 2023 -0400

    cleanup

commit b044882dc3
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 17:37:27 2023 -0400

    remove duplicate code from rebase

commit dd174cf30e
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 17:15:07 2023 -0400

    add DEFAULT_MODEL to .env.sample

    + fix typo

commit 2497fb816b
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Fri Apr 14 16:29:45 2023 -0400

    move json_validated_response to standalone function

commit 923f7057e3
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Thu Apr 13 11:35:24 2023 -0400

    update readme

    - updated readme to mention .env
    - added model arg back

commit 0656a83da7
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Thu Apr 13 11:29:06 2023 -0400

    recursive calls if not json parsable

    - makes recursive calls to API (with a comment about it not being parsable) if response was not parsable
    - pass prompt.txt as system prompt
    - use env var for `DEFAULT_MODEL`
    - use env var for OPENAI_API_KEY

commit 7c072fba2a
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Thu Apr 13 11:24:41 2023 -0400

    update prompt to make it pay attention to indentation

commit c62f91eaee
Author: Felix Boehme <fsboehme@gmail.com>
Date:   Thu Apr 13 11:23:44 2023 -0400

    Update .gitignore

commit f2d21e7b93
Merge: 0420860 6343f6f
Author: biobootloader <128252497+biobootloader@users.noreply.github.com>
Date:   Fri Apr 14 13:59:44 2023 -0700

    Merge pull request #12 from chriscarrollsmith/main

    Implemented .env file API key storage

commit 6343f6f50b
Author: biobootloader <128252497+biobootloader@users.noreply.github.com>
Date:   Fri Apr 14 13:59:31 2023 -0700

    Apply suggestions from code review

commit d87ebfa46f
Merge: 9af5480 75f08e2
Author: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com>
Date:   Fri Apr 14 16:53:25 2023 -0400

    Merge branch 'main' of https://github.com/chriscarrollsmith/wolverine

commit 9af5480b89
Author: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com>
Date:   Fri Apr 14 16:53:02 2023 -0400

    Added python-dotenv to requirements.txt

commit 75f08e2852
Merge: e8a8931 0420860
Author: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com>
Date:   Fri Apr 14 16:50:29 2023 -0400

    Merge pull request #1 from biobootloader/main

    Reconcile with master branch

commit 04208605fe
Merge: d547822 6afb4db
Author: biobootloader <128252497+biobootloader@users.noreply.github.com>
Date:   Fri Apr 14 13:22:53 2023 -0700

    Merge pull request #20 from eltociear/patch-1

    fix typo in README.md

commit d54782230c
Merge: 1b9649e 4863df6
Author: biobootloader <128252497+biobootloader@users.noreply.github.com>
Date:   Fri Apr 14 13:19:43 2023 -0700

    Merge pull request #17 from hemangjoshi37a/main

    added `star-history` 

commit 6afb4db2ff
Author: Ikko Eltociear Ashimine <eltociear@gmail.com>
Date:   Fri Apr 14 16:37:05 2023 +0900

    fix typo in README.md

    reliablity -> reliability

commit 4863df6898
Author: Hemang Joshi <hemangjoshi37a@gmail.com>
Date:   Fri Apr 14 10:27:32 2023 +0530

    added `star-history`

    added `star-history`

commit e8a893156e
Author: Christopher Carroll Smith <75859865+chriscarrollsmith@users.noreply.github.com>
Date:   Wed Apr 12 13:45:54 2023 -0400

    Implemented .env file API key storage
2023-04-15 02:22:57 -03:00
Prayag Shah e1c413fae2 updated the flag --confirm as required
- Updated the flag --confirm=True which will allow user to say yes or no before making changes to the file.
- If flag is not used then it will right away make changes to the file.
- Updated the readme with an example.
2023-04-15 02:10:25 -03:00
biobootloader 742aaaf9d1
Merge pull request #13 from fsboehme/main
more robust parsing of JSON (+ indentation)
2023-04-14 15:44:12 -07:00
Felix Boehme fe87faa2fb cleanup 2023-04-14 17:49:48 -04:00
Felix Boehme 4db9d1bf43 more cleanup 2023-04-14 17:49:09 -04:00
Felix Boehme e1d0a790f8 cleanup 2023-04-14 17:46:18 -04:00
Felix Boehme b044882dc3 remove duplicate code from rebase 2023-04-14 17:37:27 -04:00
Felix Boehme dd174cf30e add DEFAULT_MODEL to .env.sample
+ fix typo
2023-04-14 17:15:07 -04:00
Felix Boehme 2497fb816b move json_validated_response to standalone function 2023-04-14 17:12:00 -04:00
Felix Boehme 923f7057e3 update readme
- updated readme to mention .env
- added model arg back
2023-04-14 17:10:37 -04:00
Felix Boehme 0656a83da7 recursive calls if not json parsable
- makes recursive calls to API (with a comment about it not being parsable) if response was not parsable
- pass prompt.txt as system prompt
- use env var for `DEFAULT_MODEL`
- use env var for OPENAI_API_KEY
2023-04-14 17:09:36 -04:00
Felix Boehme 7c072fba2a update prompt to make it pay attention to indentation 2023-04-14 17:08:18 -04:00
Felix Boehme c62f91eaee Update .gitignore 2023-04-14 17:08:18 -04:00
biobootloader f2d21e7b93
Merge pull request #12 from chriscarrollsmith/main
Implemented .env file API key storage
2023-04-14 13:59:44 -07:00
biobootloader 6343f6f50b
Apply suggestions from code review 2023-04-14 13:59:31 -07:00
Christopher Carroll Smith d87ebfa46f Merge branch 'main' of https://github.com/chriscarrollsmith/wolverine 2023-04-14 16:53:25 -04:00
Christopher Carroll Smith 9af5480b89 Added python-dotenv to requirements.txt 2023-04-14 16:53:02 -04:00
Christopher Carroll Smith 75f08e2852
Merge pull request #1 from biobootloader/main
Reconcile with master branch
2023-04-14 16:50:29 -04:00
Alessandro Annini 49c6173c9b chore: add buggy javascript file to test new feature 2023-04-14 14:43:32 +02:00
Alessandro Annini 3d14f31511 feat: can debug javascript files 2023-04-14 14:42:56 +02:00
Prayag Shah e65a4d080a adding flag for user confirmation
- Modified the code to ask for changes to be applied. If they say yes then it will make the change or else code will stop running.
2023-04-14 00:10:36 -03:00
Christopher Carroll Smith e8a893156e Implemented .env file API key storage 2023-04-12 13:45:54 -04:00
7 zmienionych plików z 163 dodań i 37 usunięć

2
.env.sample 100644
Wyświetl plik

@ -0,0 +1,2 @@
OPENAI_API_KEY=your_api_key
#DEFAULT_MODEL=gpt-3.5-turbo

5
.gitignore vendored
Wyświetl plik

@ -1,2 +1,5 @@
venv
openai_key.txt
.venv
.env
env/
.vscode/

Wyświetl plik

@ -13,8 +13,11 @@ For a quick demonstration see my [demo video on twitter](https://twitter.com/bio
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
cp .env.sample .env
Add your openAI api key to `openai_key.txt` - _warning!_ by default this uses GPT-4 and may make many repeated calls to the api.
Add your openAI api key to `.env`
_warning!_ By default wolverine uses GPT-4 and may make many repeated calls to the api.
## Example Usage
@ -26,6 +29,14 @@ You can also run with other models, but be warned they may not adhere to the edi
python wolverine.py --model=gpt-3.5-turbo buggy_script.py "subtract" 20 3
If you want to use GPT-3.5 by default instead of GPT-4 uncomment the default model line in `.env`:
DEFAULT_MODEL=gpt-3.5-turbo
You can also use flag `--confirm=True` which will ask you `yes or no` before making changes to the file. If flag is not used then it will apply the changes to the file
python wolverine.py buggy_script.py "subtract" 20 3 --confirm=True
## Future Plans
This is just a quick prototype I threw together in a few hours. There are many possible extensions and contributions are welcome:

31
buggy_script.js 100644
Wyświetl plik

@ -0,0 +1,31 @@
const subtractNumbers = (a, b) => {
return a - b;
};
const multiplyNumbers = (a, b) => {
return a * b;
};
const divideNumbers = (a, b) => {
return a / b;
};
function calculate(operation, num1, num2) {
let result = '';
if (operation == 'add') {
result = addNumbers(num1, num2);
} else if (operation == 'subtract') {
result = subtractNumbers(num1, num2);
} else if (operation == 'multiply') {
result = multiplyNumbers(num1, num2);
} else if (operation == 'divide') {
result = divideNumbers(num1, num2);
} else {
console.log('Invalid operation');
}
return res;
}
const [, , operation, num1, num2] = process.argv;
calculate(operation, num1, num2);

Wyświetl plik

@ -4,10 +4,13 @@ Because you are part of an automated system, the format you respond in is very s
In addition to the changes, please also provide short explanations of the what went wrong. A single explanation is required, but if you think it's helpful, feel free to provide more explanations for groups of more complicated changes. Be careful to use proper indentation and spacing in your changes. An example response could be:
Be ABSOLUTELY SURE to include the CORRECT INDENTATION when making replacements.
example response:
[
{"explanation": "this is just an example, this would usually be a brief explanation of what went wrong"},
{"operation": "InsertAfter", "line": 10, "content": "x = 1\ny = 2\nz = x * y"},
{"operation": "Delete", "line": 15, "content": ""},
{"operation": "Replace", "line": 18, "content": "x += 1"},
{"operation": "Replace", "line": 18, "content": " x += 1"},
{"operation": "Delete", "line": 20, "content": ""}
]

Wyświetl plik

@ -13,6 +13,7 @@ multidict==6.0.4
openai==0.27.2
pycodestyle==2.10.0
pyflakes==3.0.1
python-dotenv==1.0.0
requests==2.28.2
six==1.16.0
termcolor==2.2.0

Wyświetl plik

@ -5,27 +5,84 @@ import os
import shutil
import subprocess
import sys
import openai
from termcolor import cprint
from dotenv import load_dotenv
# Set up the OpenAI API
with open("openai_key.txt") as f:
openai.api_key = f.read().strip()
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
DEFAULT_MODEL = os.environ.get("DEFAULT_MODEL", "gpt-4")
with open("prompt.txt") as f:
SYSTEM_PROMPT = f.read()
def run_script(script_name, script_args):
script_args = [str(arg) for arg in script_args]
"""
If script_name.endswith(".py") then run with python
else run with node
"""
subprocess_args = (
[sys.executable, script_name, *script_args]
if script_name.endswith(".py")
else ["node", script_name, *script_args]
)
try:
result = subprocess.check_output(
[sys.executable, script_name, *script_args], stderr=subprocess.STDOUT
)
result = subprocess.check_output(subprocess_args, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
return e.output.decode("utf-8"), e.returncode
return result.decode("utf-8"), 0
def send_error_to_gpt(file_path, args, error_message, model):
def json_validated_response(model, messages):
"""
This function is needed because the API can return a non-json response.
This will run recursively until a valid json response is returned.
todo: might want to stop after a certain number of retries
"""
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0.5,
)
messages.append(response.choices[0].message)
content = response.choices[0].message.content
# see if json can be parsed
try:
json_start_index = content.index(
"["
) # find the starting position of the JSON data
json_data = content[
json_start_index:
] # extract the JSON data from the response string
json_response = json.loads(json_data)
except (json.decoder.JSONDecodeError, ValueError) as e:
cprint(f"{e}. Re-running the query.", "red")
# debug
cprint(f"\nGPT RESPONSE:\n\n{content}\n\n", "yellow")
# append a user message that says the json is invalid
messages.append(
{
"role": "user",
"content": "Your response could not be parsed by json.loads. Please restate your last message as pure JSON.",
}
)
# rerun the api call
return json_validated_response(model, messages)
except Exception as e:
cprint(f"Unknown error: {e}", "red")
cprint(f"\nGPT RESPONSE:\n\n{content}\n\n", "yellow")
raise e
return json_response
def send_error_to_gpt(file_path, args, error_message, model=DEFAULT_MODEL):
with open(file_path, "r") as f:
file_lines = f.readlines()
@ -34,12 +91,7 @@ def send_error_to_gpt(file_path, args, error_message, model):
file_with_lines.append(str(i + 1) + ": " + line)
file_with_lines = "".join(file_with_lines)
with open("prompt.txt") as f:
initial_prompt_text = f.read()
prompt = (
initial_prompt_text +
"\n\n"
"Here is the script that needs fixing:\n\n"
f"{file_with_lines}\n\n"
"Here are the arguments it was provided:\n\n"
@ -51,27 +103,27 @@ def send_error_to_gpt(file_path, args, error_message, model):
)
# print(prompt)
messages = [
{
"role": "system",
"content": SYSTEM_PROMPT,
},
{
"role": "user",
"content": prompt,
},
]
response = openai.ChatCompletion.create(
model=model,
messages=[
{
"role": "user",
"content": prompt,
}
],
temperature=1.0,
)
return response.choices[0].message.content.strip()
return json_validated_response(model, messages)
def apply_changes(file_path, changes_json):
def apply_changes(file_path, changes: list, confirm=False):
"""
Pass changes as loaded json (list of dicts)
"""
with open(file_path, "r") as f:
original_file_lines = f.readlines()
changes = json.loads(changes_json)
# Filter out explanation elements
operation_changes = [change for change in changes if "operation" in change]
explanations = [
@ -94,6 +146,25 @@ def apply_changes(file_path, changes_json):
elif operation == "InsertAfter":
file_lines.insert(line, content + "\n")
# Ask for user confirmation before writing changes
print("\nChanges to be made:")
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
for line in diff:
if line.startswith("+"):
cprint(line, "green", end="")
elif line.startswith("-"):
cprint(line, "red", end="")
else:
print(line, end="")
# Checking if user used confirm flag
if confirm:
confirmation = input("Do you want to apply these changes? (y/n): ")
if confirmation.lower() != "y":
print("Changes not applied")
sys.exit(0)
with open(file_path, "w") as f:
f.writelines(file_lines)
@ -104,7 +175,8 @@ def apply_changes(file_path, changes_json):
# Show the diff
print("\nChanges:")
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
diff = difflib.unified_diff(
original_file_lines, file_lines, lineterm="")
for line in diff:
if line.startswith("+"):
cprint(line, "green", end="")
@ -113,8 +185,10 @@ def apply_changes(file_path, changes_json):
else:
print(line, end="")
print("Changes applied.")
def main(script_name, *script_args, revert=False, model="gpt-4"):
def main(script_name, *script_args, revert=False, model=DEFAULT_MODEL, confirm=False):
if revert:
backup_file = script_name + ".bak"
if os.path.exists(backup_file):
@ -140,12 +214,13 @@ def main(script_name, *script_args, revert=False, model="gpt-4"):
print("Output:", output)
json_response = send_error_to_gpt(
file_path=script_name,
args=script_args,
error_message=output,
model=model,
file_path=script_name,
args=script_args,
error_message=output,
model=model,
)
apply_changes(script_name, json_response)
apply_changes(script_name, json_response, confirm=confirm)
cprint("Changes applied. Rerunning...", "blue")