mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-16 11:57:51 +01:00
refac
This commit is contained in:
@@ -64,7 +64,6 @@ class FunctionResponse(BaseModel):
|
||||
class FunctionForm(BaseModel):
|
||||
id: str
|
||||
name: str
|
||||
type: str
|
||||
content: str
|
||||
meta: FunctionMeta
|
||||
|
||||
@@ -75,12 +74,13 @@ class FunctionsTable:
|
||||
self.db.create_tables([Function])
|
||||
|
||||
def insert_new_function(
|
||||
self, user_id: str, form_data: FunctionForm
|
||||
self, user_id: str, type: str, form_data: FunctionForm
|
||||
) -> Optional[FunctionModel]:
|
||||
function = FunctionModel(
|
||||
**{
|
||||
**form_data.model_dump(),
|
||||
"user_id": user_id,
|
||||
"type": type,
|
||||
"updated_at": int(time.time()),
|
||||
"created_at": int(time.time()),
|
||||
}
|
||||
|
||||
@@ -69,12 +69,12 @@ async def create_new_function(
|
||||
with open(function_path, "w") as function_file:
|
||||
function_file.write(form_data.content)
|
||||
|
||||
function_module = load_function_module_by_id(form_data.id)
|
||||
function_module, function_type = load_function_module_by_id(form_data.id)
|
||||
|
||||
FUNCTIONS = request.app.state.FUNCTIONS
|
||||
FUNCTIONS[form_data.id] = function_module
|
||||
|
||||
function = Functions.insert_new_function(user.id, form_data)
|
||||
function = Functions.insert_new_function(user.id, function_type, form_data)
|
||||
|
||||
function_cache_dir = Path(CACHE_DIR) / "functions" / form_data.id
|
||||
function_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
@@ -132,12 +132,12 @@ async def update_toolkit_by_id(
|
||||
with open(function_path, "w") as function_file:
|
||||
function_file.write(form_data.content)
|
||||
|
||||
function_module = load_function_module_by_id(id)
|
||||
function_module, function_type = load_function_module_by_id(id)
|
||||
|
||||
FUNCTIONS = request.app.state.FUNCTIONS
|
||||
FUNCTIONS[id] = function_module
|
||||
|
||||
updated = {**form_data.model_dump(exclude={"id"})}
|
||||
updated = {**form_data.model_dump(exclude={"id"}), "type": function_type}
|
||||
print(updated)
|
||||
|
||||
function = Functions.update_function_by_id(id, updated)
|
||||
|
||||
@@ -33,9 +33,9 @@ def load_function_module_by_id(function_id):
|
||||
spec.loader.exec_module(module)
|
||||
print(f"Loaded module: {module.__name__}")
|
||||
if hasattr(module, "Pipe"):
|
||||
return module.Pipe()
|
||||
return module.Pipe(), "pipe"
|
||||
elif hasattr(module, "Filter"):
|
||||
return module.Filter()
|
||||
return module.Filter(), "filter"
|
||||
else:
|
||||
raise Exception("No Function class found")
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user