File size: 668 Bytes
02f3a7c 835b371 02f3a7c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# logic/fixer.py
from logic.generator import tokenizer, model
import torch
def fix_code(code):
try:
prompt = f"# Corrija o seguinte c贸digo Python com erros:\n{code}\n# C贸digo corrigido:\n"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
do_sample=True,
temperature=0.3,
top_k=50,
top_p=0.95
)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
return result.strip()
except Exception as e:
return f"Erro ao tentar corrigir o c贸digo: {str(e)}"
|