This commit is contained in:
Timothy J. Baek 2024-09-04 19:57:41 +02:00
parent cf86ba7786
commit f2f713023d
3 changed files with 8 additions and 9 deletions

View File

@ -56,11 +56,11 @@ async def create_new_function(
function = Functions.get_function_by_id(form_data.id) function = Functions.get_function_by_id(form_data.id)
if function is None: if function is None:
try: try:
form_data.content = replace_imports(form_data.content)
function_module, function_type, frontmatter = load_function_module_by_id( function_module, function_type, frontmatter = load_function_module_by_id(
form_data.id, form_data.id,
content=form_data.content, content=form_data.content,
) )
form_data.content = replace_imports(form_data.content)
form_data.meta.manifest = frontmatter form_data.meta.manifest = frontmatter
FUNCTIONS = request.app.state.FUNCTIONS FUNCTIONS = request.app.state.FUNCTIONS
@ -173,10 +173,10 @@ async def update_function_by_id(
request: Request, id: str, form_data: FunctionForm, user=Depends(get_admin_user) request: Request, id: str, form_data: FunctionForm, user=Depends(get_admin_user)
): ):
try: try:
form_data.content = replace_imports(form_data.content)
function_module, function_type, frontmatter = load_function_module_by_id( function_module, function_type, frontmatter = load_function_module_by_id(
id, content=form_data.content id, content=form_data.content
) )
form_data.content = replace_imports(form_data.content)
form_data.meta.manifest = frontmatter form_data.meta.manifest = frontmatter
FUNCTIONS = request.app.state.FUNCTIONS FUNCTIONS = request.app.state.FUNCTIONS

View File

@ -60,10 +60,10 @@ async def create_new_toolkit(
toolkit = Tools.get_tool_by_id(form_data.id) toolkit = Tools.get_tool_by_id(form_data.id)
if toolkit is None: if toolkit is None:
try: try:
form_data.content = replace_imports(form_data.content)
toolkit_module, frontmatter = load_toolkit_module_by_id( toolkit_module, frontmatter = load_toolkit_module_by_id(
form_data.id, content=form_data.content form_data.id, content=form_data.content
) )
form_data.content = replace_imports(form_data.content)
form_data.meta.manifest = frontmatter form_data.meta.manifest = frontmatter
TOOLS = request.app.state.TOOLS TOOLS = request.app.state.TOOLS
@ -126,10 +126,10 @@ async def update_toolkit_by_id(
user=Depends(get_admin_user), user=Depends(get_admin_user),
): ):
try: try:
form_data.content = replace_imports(form_data.content)
toolkit_module, frontmatter = load_toolkit_module_by_id( toolkit_module, frontmatter = load_toolkit_module_by_id(
id, content=form_data.content id, content=form_data.content
) )
form_data.content = replace_imports(form_data.content)
form_data.meta.manifest = frontmatter form_data.meta.manifest = frontmatter
TOOLS = request.app.state.TOOLS TOOLS = request.app.state.TOOLS

View File

@ -76,8 +76,8 @@ def load_toolkit_module_by_id(toolkit_id, content=None):
content = tool.content content = tool.content
content = replace_imports(content) content = replace_imports(content)
Tools.update_tool_by_id(toolkit_id, {"content": content}) Tools.update_tool_by_id(toolkit_id, {"content": content})
module_name = f"{toolkit_id}" module_name = f"{toolkit_id}"
module = types.ModuleType(module_name) module = types.ModuleType(module_name)
@ -114,9 +114,8 @@ def load_function_module_by_id(function_id, content=None):
raise Exception(f"Function not found: {function_id}") raise Exception(f"Function not found: {function_id}")
content = function.content content = function.content
# Replace the module paths in the function content content = replace_imports(content)
content = replace_imports(content) Functions.update_function_by_id(function_id, {"content": content})
Functions.update_function_by_id(function_id, {"content": content})
module_name = f"{function_id}" module_name = f"{function_id}"
module = types.ModuleType(module_name) module = types.ModuleType(module_name)