This commit is contained in:
Timothy Jaeryang Baek
2024-12-12 20:22:17 -08:00
parent 403262d764
commit 4311bb7b99
10 changed files with 1102 additions and 966 deletions

View File

@@ -4,11 +4,15 @@ import re
from typing import Any, Awaitable, Callable, get_type_hints
from functools import update_wrapper, partial
from fastapi import Request
from pydantic import BaseModel, Field, create_model
from langchain_core.utils.function_calling import convert_to_openai_function
from open_webui.models.tools import Tools
from open_webui.models.users import UserModel
from open_webui.utils.plugin import load_tools_module_by_id
from pydantic import BaseModel, Field, create_model
log = logging.getLogger(__name__)
@@ -32,7 +36,7 @@ def apply_extra_params_to_tool_function(
# Mutation on extra_params
def get_tools(
webui_app, tool_ids: list[str], user: UserModel, extra_params: dict
request: Request, tool_ids: list[str], user: UserModel, extra_params: dict
) -> dict[str, dict]:
tools_dict = {}
@@ -41,10 +45,10 @@ def get_tools(
if tools is None:
continue
module = webui_app.state.TOOLS.get(tool_id, None)
module = request.app.state.TOOLS.get(tool_id, None)
if module is None:
module, _ = load_tools_module_by_id(tool_id)
webui_app.state.TOOLS[tool_id] = module
request.app.state.TOOLS[tool_id] = module
extra_params["__id__"] = tool_id
if hasattr(module, "valves") and hasattr(module, "Valves"):