open-webui/backend/open_webui/apps
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
..
audio refac: audio input (audio/ogg support) 2024-09-12 09:18:20 -04:00
images chore: format 2024-09-13 00:49:23 -04:00
ollama fix: separate /embed and /embedding ollama endpoint 2024-09-09 23:02:26 +01:00
openai refac 2024-09-13 14:26:32 -04:00
rag refac 2024-09-17 23:13:51 +02:00
socket refac: remove prints 2024-09-12 09:13:21 -04:00
webui fix: restore __file__ variable for imported toolkits and functions 2024-09-18 01:08:30 -07:00