open-webui/backend
Etienne Perot 6477bf37fe
fix: restore __file__ variable for imported toolkits and functions
Commit cf86ba7786 changed the way toolkits
and functions were imported to use `exec`, whereas they previously were
written to files and `import`ed. The use of `exec` means that
module-global variables such as `__file__` are no longer defined.

This breaks https://github.com/EtiennePerot/open-webui-code-execution
(code execution tool for Open WebUI), as the module needs to re-execute
its own code in a subprocess in order to properly sandbox itself. This
is done using `__file__` in order to know where the module's code is
located.

This PR creates a temporary in-memory file that contains the imported
toolkit or function's code and exists only during the import process.
Then it injects the path to this in-memory file as the `__file__`
variable in the `exec` context. This restores the ability for the
toolkit or function being imported to rely on `__file__`.
2024-09-18 01:08:30 -07:00
..
data refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
open_webui fix: restore __file__ variable for imported toolkits and functions 2024-09-18 01:08:30 -07:00
.dockerignore
.gitignore refac 2024-09-06 04:59:20 +02:00
dev.sh refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
requirements.txt chore: colbert-ai requirement 2024-09-16 16:19:40 +02:00
start_windows.bat fix scripts to point to correct path 2024-09-04 20:27:30 +02:00
start.sh refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00