CodeFixPro / agents /error_fixer.py
ParthBhuptani's picture
Update agents/error_fixer.py
2934c74 verified
raw
history blame contribute delete
620 Bytes
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-small")
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-small")
fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
def fix_code(code: str) -> str:
prompt = f"""The following Python code has some bugs. Fix the code:\n\n{code}\n\nCorrected version:"""
try:
result = fix_pipeline(prompt, max_length=256)[0]["generated_text"]
return result.strip()
except Exception as e:
return f"Error during fixing: {e}"