Spaces:
Running
Running
Update agents/error_fixer.py
Browse files- agents/error_fixer.py +8 -15
agents/error_fixer.py
CHANGED
@@ -1,21 +1,14 @@
|
|
1 |
-
from transformers import AutoTokenizer,
|
2 |
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
code_fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
|
7 |
|
8 |
def fix_code(code: str) -> str:
|
9 |
-
prompt = f"""
|
10 |
-
Below is a Python code snippet that contains bugs. Your job is to fix the code and output the corrected version.
|
11 |
-
|
12 |
-
[BUGGY CODE]
|
13 |
-
{code}
|
14 |
-
|
15 |
-
[FIXED CODE]
|
16 |
-
"""
|
17 |
try:
|
18 |
-
result =
|
19 |
-
|
|
|
20 |
except Exception as e:
|
21 |
return f"Error during fixing: {e}"
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
2 |
|
3 |
+
tokenizer = AutoTokenizer.from_pretrained("bigcode/santacoder")
|
4 |
+
model = AutoModelForCausalLM.from_pretrained("bigcode/santacoder")
|
5 |
+
fix_pipeline = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
|
|
6 |
|
7 |
def fix_code(code: str) -> str:
|
8 |
+
prompt = f"""# The following Python code has bugs. Fix the code and output only the corrected version.\n\n# Buggy Code:\n{code}\n\n# Fixed Code:\n"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
try:
|
10 |
+
result = fix_pipeline(prompt, max_length=256, do_sample=True)[0]["generated_text"]
|
11 |
+
# Post-process to strip out everything before "# Fixed Code"
|
12 |
+
return result.split("# Fixed Code:")[-1].strip()
|
13 |
except Exception as e:
|
14 |
return f"Error during fixing: {e}"
|