Closed EtiennePerot closed 2 months ago
That's right, I want to create a function that can generate a file and then download it directly from the web UI. Thank you for your attention, I will wait for further developments.
From some preliminary research, it seems tools and functions can append messages to Open WebUI, but they are limited to either text (markdown) an images. So something like a spreadsheet file (.xlsx
) would not be able to be displayed, unless perhaps the tool also had code to convert the spreadsheet to a Markdown table.
Alternatively, it may be possible to show links to download files that aren't markdown/images (as you suggest). Need to look if Open WebUI has some passthrough endpoints that would allow this, or if they could be linked using data
URIs (for small files like spreadsheets this might work too).
Are there any alternative libraries that allow for that besides Web UI?
Not really. At the end of the day, the output generated by the tool need to be displayed on Open WebUI (that's simply the nature of this tool). We have no control over what functionality Open WebUI will display, but it may be possible to send them PRs to expand this.
Anyway, first feature to implement here is to detect the presence of files at the end of a code execution run and to copy them somewhere outside of the sandbox before the sandbox disappears.
/app/backend/data/cache/tools/run_code
e.g. /app/backend/data/cache/tools/run_code/hello.txt
http://webui_url/cache/tools/run_code/hello.txt
{
"type": "message",
"data": {"content": "[Download File](http://webui_url/cache/tools/run_code/hello.txt)"},
}
ChatGPT generates code like this, where it outputs the generated filepath to stdout:
import uuid
# Generate a list of 1000 UUIDs
uuid_list = [str(uuid.uuid4()) for _ in range(1000)]
# Save to a text file
file_path = '/mnt/data/uuids.txt'
with open(file_path, 'w') as f:
for uid in uuid_list:
f.write(uid + '\n')
file_path
Excellent. With all these in place, I think this is all feasible now.
To prevent abuse, the tool probably needs a few more valves:
Another related idea: Letting the sandboxed code have a persistent per-chat "session" directory, in which files created in one session are available in future executions of the tool within the same chat. I'm not sure the current crop of models are really smart enough to think about persistence in this way, but good to think about in advance.
This is now implemented as of 44b33e38cd9ed43306697a4b22047ea9293ff112. Enjoy!
I have tried it and succeeded, thank you all.
Right now, if code writes files inside the sandbox, they are simply lost forever. It would be very cool to be able to run code that generates files and then have these files be downloadable from the chat UI.
This idea came from a comment by @sultanjulyan in this issue.