mirror of
https://github.com/open-webui/open-webui.git
synced 2026-03-22 22:21:27 -05:00
[PR #5511] [MERGED] fix: restore __file__ variable for imported toolkits and functions
#8493
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/5511
Author: @EtiennePerot
Created: 9/19/2024
Status: ✅ Merged
Merged: 9/19/2024
Merged by: @tjbck
Base:
dev← Head:import-file📝 Commits (1)
6477bf3fix: restore__file__variable for imported toolkits and functions📊 Changes
1 file changed (+18 additions, -2 deletions)
View changed files
📝
backend/open_webui/apps/webui/utils.py(+18 -2)📄 Description
Commit
cf86ba7786changed the way toolkits and functions were imported to useexec, whereas they previously were written to files andimported. The use ofexecmeans that module-global variables such as__file__are no longer defined.This change breaks this code execution tool for Open WebUI (issue: https://github.com/EtiennePerot/open-webui-code-execution/issues/11), 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 theexeccontext. This restores the ability for the toolkit or function being imported to rely on__file__.Pull Request Checklist
Before submitting, make sure you've checked the following:
devbranch.fix.Changelog Entry
Fixed
__file__variable to refer to their own code.Screenshots or Videos
Without this fix, tools and functions do not have the

__file__variable defined.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.