Skip to content

Commit

Permalink
Improve prompt for intermediate variable reuse. (#393)
Browse files Browse the repository at this point in the history
* Fix syncfs by populating first

* Fix native ==> browser

* Fix Module

* add variable re-use prompt
  • Loading branch information
oeway authored May 17, 2024
1 parent aaf7783 commit c7498ef
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
3 changes: 2 additions & 1 deletion public/chat/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,8 @@ <h3 class="text-center">Welcome to BioImage.IO Chatbot</h3>
The environment has access to remote servers, so you can fetch remote data by using python modules "requests" or "imjoy_rpc.hypha" for connect to the Hypha/BioEngine server.
User data will be mounted to the \`/mnt\` directory. Use "os.listdir('/mnt')" to explore available files before processing.
The code interpreter can produce outputs such as stdout or stderr, matplotlib plots, and image/audio displays which is rendered in the user interface. For key results (e.g. result images), display them in the final response to the user.
Global variables, functions and results will be maintained across multiple code interpreter executions, so you can reuse them in the next steps.
Global variables, functions and results will be maintained across multiple code interpreter executions, so try to save the intermediate results into global variables that can be subsequently reused.
**Image Processing and Visualization**:
- For image analysis tasks, you should first inspect the files loaded by the user, then load the image analyse the image type and shape, and process or run the model on the image.
Expand Down
13 changes: 5 additions & 8 deletions public/chat/pyodide-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,12 @@ self.onmessage = async (event) => {
self.pyodide.globals.set("source", source)
self.pyodide.globals.set("io_context", io_context && self.pyodide.toPy(io_context))
outputs = []
// copy mounted files into pyodide
for(const mountPoint of Object.keys(mountedFs)){
await mountedFs[mountPoint].syncfs(true)
}
// see https://github.com/pyodide/pyodide/blob/b177dba277350751f1890279f5d1a9096a87ed13/src/js/api.ts#L546
// sync native ==> browser
await new Promise((resolve, _) => self.pyodide.FS.syncfs(true, resolve));
await self.pyodide.runPythonAsync("await run(source, io_context)")
// copy files back to the native fs
for(const mountPoint of Object.keys(mountedFs)){
await mountedFs[mountPoint].syncfs()
}
// sync browser ==> native
await new Promise((resolve, _) => self.pyodide.FS.syncfs(false, resolve)),
console.log("Execution done", outputs)
self.postMessage({ executionDone: true, outputs })
outputs = []
Expand Down

0 comments on commit c7498ef

Please sign in to comment.