Porównaj commity

...

6 Commity

Autor SHA1 Wiadomość Data
BioBootloader a1fb03ea81 don't show diff twice, show explanations before diff 2023-04-22 17:41:13 -07:00
biobootloader 472e8b5a87
Merge pull request #9 from juleshenry/main
Address Examples Initiative
2023-04-22 17:29:07 -07:00
BioBootloader bb8c6f8e3e switch singleton example to have a bug in singleton implementation 2023-04-22 17:24:47 -07:00
BioBootloader 459a9c5ef2 Merge branch 'main' into juleshenry/main 2023-04-22 16:44:37 -07:00
Julian Henry f46701623f
Update buggy_script_2.py
@biobootloader, now fails due to singleton modification of attributes
2023-04-20 07:01:59 -05:00
juleshenry 31319dd273 Address Examples Initiative 2023-04-11 21:02:39 -05:00
4 zmienionych plików z 43 dodań i 23 usunięć

Wyświetl plik

@ -23,7 +23,7 @@ _warning!_ By default wolverine uses GPT-4 and may make many repeated calls to t
To run with gpt-4 (the default, tested option):
python wolverine.py buggy_script.py "subtract" 20 3
python wolverine.py examples/buggy_script.py "subtract" 20 3
You can also run with other models, but be warned they may not adhere to the edit format as well:

Wyświetl plik

@ -1,5 +1,9 @@
import sys
import fire
"""
Run With: `wolverine examples/buggy_script.py "subtract" 20 3`
Purpose: Show self-regenerating fixing of subtraction operator
"""
def add_numbers(a, b):
return a + b

Wyświetl plik

@ -0,0 +1,27 @@
#!/usr/bin/env python3
import fire
"""
Run With: with `python wolverine.py examples/buggy_script_2.py`
Purpose: Fix singleton code bug in Python
"""
class SingletonClass(object):
def __new__(cls):
cls.instance = super(SingletonClass, cls).__new__(cls)
return cls.instance
def check_singleton_works():
"""
check that singleton pattern is working
"""
singleton = SingletonClass()
new_singleton = SingletonClass()
singleton.a = 1
new_singleton.a = 2
should_be_4 = (singleton.a + new_singleton.a)
assert should_be_4 == 4
if __name__=="__main__":
fire.Fire(check_singleton_works)

Wyświetl plik

@ -70,7 +70,10 @@ def json_validated_response(model, messages):
messages.append(
{
"role": "user",
"content": "Your response could not be parsed by json.loads. Please restate your last message as pure JSON.",
"content": (
"Your response could not be parsed by json.loads. "
"Please restate your last message as pure JSON."
),
}
)
# rerun the api call
@ -146,9 +149,13 @@ def apply_changes(file_path, changes: list, confirm=False):
elif operation == "InsertAfter":
file_lines.insert(line, content + "\n")
# Ask for user confirmation before writing changes
print("\nChanges to be made:")
# Print explanations
cprint("Explanations:", "blue")
for explanation in explanations:
cprint(f"- {explanation}", "blue")
# Display changes diff
print("\nChanges to be made:")
diff = difflib.unified_diff(original_file_lines, file_lines, lineterm="")
for line in diff:
if line.startswith("+"):
@ -158,8 +165,8 @@ def apply_changes(file_path, changes: list, confirm=False):
else:
print(line, end="")
# Checking if user used confirm flag
if confirm:
# check if user wants to apply changes or exit
confirmation = input("Do you want to apply these changes? (y/n): ")
if confirmation.lower() != "y":
print("Changes not applied")
@ -167,24 +174,6 @@ def apply_changes(file_path, changes: list, confirm=False):
with open(file_path, "w") as f:
f.writelines(file_lines)
# Print explanations
cprint("Explanations:", "blue")
for explanation in explanations:
cprint(f"- {explanation}", "blue")
# Show the diff
print("\nChanges:")
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="")
print("Changes applied.")