open-webui/backend/open_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
..
apps fix: restore __file__ variable for imported toolkits and functions 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
migrations refac 2024-09-06 05:30:16 +02:00
static refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
test refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
utils update comment block 2024-09-16 22:02:55 -03:00
__init__.py pep8 2024-09-13 17:18:44 +02:00
alembic.ini dev5 2024-09-04 17:33:39 +02:00
config.py chore: format 2024-09-13 00:49:23 -04:00
constants.py refac: mv backend files to /open_webui dir 2024-09-04 16:54:48 +02:00
env.py pep8 2024-09-13 17:18:44 +02:00
main.py feat: security response headers 2024-09-16 21:53:30 -03:00