ParthBhuptani commited on
Commit
b5b33c5
·
verified ·
1 Parent(s): 18a1145

Update agents/error_fixer.py

Browse files
Files changed (1) hide show
  1. agents/error_fixer.py +8 -9
agents/error_fixer.py CHANGED
@@ -1,14 +1,13 @@
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}"
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
2
 
3
+ tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small")
4
+ model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small")
5
+ fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
6
 
7
  def fix_code(code: str) -> str:
8
+ prompt = f"""The following Python code has some bugs. Fix the code:\n\n{code}\n\nCorrected version:"""
9
  try:
10
+ result = fix_pipeline(prompt, max_length=256)[0]["generated_text"]
11
+ return result.strip()
 
12
  except Exception as e:
13
+ return f"Error during fixing: {e}"