Код: Выделить всё
def run_with_retry(self, tool, prompt):
last_error = None
context = prompt
for attempt in range(self.attempts):
result = tool(context)
if result.get("ok"):
return result
last_error = result.get("error")
context = f"""
Original request: {prompt}
Previous attempt {attempt + 1} failed with error:
{last_error}
Instructions to fix:
- Review the error message carefully
- Ensure the code is syntactically correct
- For Manim: ensure all imports are correct and the Scene class is properly defined
- For Flowchart: ensure Graphviz syntax is valid
- Generate corrected code
Generate the corrected code now:
"""
return {
"ok": False,
"error": f"Failed after {self.attempts} attempts",
"last_error": str(last_error)
if last_error is not None
else "Unknown error",
}
>
Подробнее здесь: https://stackoverflow.com/questions/798 ... g-llm-call
Мобильная версия