CodeFixPro / agents /error_fixer.py
ParthBhuptani's picture
Update agents/error_fixer.py
3326c2a verified
raw
history blame
765 Bytes
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
# Load CodeT5 model (public and free)
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codet5-base")
model = AutoModelForSeq2SeqLM.from_pretrained("Salesforce/codet5-base")
code_fix_pipeline = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
def fix_code(code: str) -> str:
prompt = f"""You are a code-fixing AI assistant.
Below is a Python code snippet that contains bugs. Your job is to fix the code and output the corrected version.
[BUGGY CODE]
{code}
[FIXED CODE]
"""
try:
result = code_fix_pipeline(prompt, max_length=256)[0]["generated_text"]
return result.strip()
except Exception as e:
return f"Error during fixing: {e}"