open-webui/backend/open_webui/apps/webui
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
..
internal refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
models refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
routers refac 2024-09-16 07:14:17 +02:00
main.py refac 2024-09-07 03:09:57 +01:00
utils.py fix: restore __file__ variable for imported toolkits and functions 2024-09-18 01:08:30 -07:00