-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support uploading file to e2b code interpreter tool #113
base: main
Are you sure you want to change the base?
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
@@ -14,14 +14,15 @@ | |||
|
|||
class InterpreterExtraResult(BaseModel): | |||
type: str | |||
filename: str | |||
url: str | |||
content: Optional[str] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The e2b result is not only a file but also a raw text, html markdown text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leehuwuj is that not independant of using files?
@@ -108,9 +125,15 @@ def interpret(self, code: str) -> E2BToolOutput: | |||
return output | |||
|
|||
|
|||
def code_interpret(code: str) -> Dict: | |||
def code_interpret(code: str, local_file_path: str) -> Dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- code: the code to be executed.
- local_file_path: the uploaded file location for transfer to the e2b sandbox.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is for the case that the user doesn't upload a file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also thought about that, we can use local_file_path as optional argument for the case the code does not use any data, but that doesn't seem practical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by "not practical"?
2. Execute python code in a Jupyter notebook cell to analyze the uploaded file in the sandbox. | ||
3. Get the result from the code in stdout, stderr, display_data, and error. | ||
You must to provide the code and the provided file path to run this tool. | ||
Your code should read the file from the sandbox path /home/user/{filename}. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An additional note for AI to use the path in the sandbox environment
with CodeInterpreter(api_key=self.api_key) as interpreter: | ||
# Upload file to E2B sandbox |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always upload the file for each code interpreter calling. We can improve this by introducing a chat session feature, then each session can use its own sandbox environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. I think this is a general concept we have to add later, e.g. we also need to store the agent's memory in that session store
as we generate demo code - for now we just have to add an explanation to the user
localFilePath: { | ||
type: "string", | ||
description: "The local file path to upload to the sandbox.", | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add nullable: true
to this optional parameter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public async codeInterpret(code: string): Promise<InterpreterToolOutput> { | ||
public async codeInterpret( | ||
code: string, | ||
localFilePath: string, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be localFilePath? string,
and don't save file if user don't upload file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes i also had that question for python, see https://github.com/run-llama/create-llama/pull/113/files#r1627342305
@@ -119,18 +142,26 @@ export class InterpreterTool implements BaseTool<InterpreterParameter> { | |||
try { | |||
const formats = res.formats(); // formats available for the result. Eg: ['png', ...] | |||
const base64DataArr = formats.map((f) => res[f as keyof Result]); // get base64 data for each format | |||
console.log("data", base64DataArr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no output
No description provided.