Skip to content

Commit 43b7128

Browse files
committed
package install on error
1 parent c205933 commit 43b7128

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

codeinterpreterapi/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ async def arun_handler(self, code: str):
109109
return f"Image {filename} got send to the user."
110110

111111
elif output.type == "error":
112-
# TODO: check if package install is required
112+
if "ModuleNotFoundError" in output.content:
113+
if package := re.search(r"ModuleNotFoundError: No module named '(.*)'", output.content):
114+
await self.codebox.ainstall(package.group(1))
115+
return f"{package.group(1)} was missing but got installed now. Please try again."
113116
# TODO: preanalyze error to optimize next code generation
114117
print("Error:", output.content)
115118

0 commit comments

Comments
 (0)