From 4a6b964a51bcbb4b5223b629d8ec46eb67e8b514 Mon Sep 17 00:00:00 2001 From: Michael Berna <7750743+therealmichaelberna@users.noreply.github.com> Date: Wed, 30 Apr 2025 14:22:38 -0400 Subject: [PATCH] Fixed convert_function_to_pydantic_model convert_function_to_pydantic_model was returning empty function descriptions. I have renamed the variables more precisely which helps to avoid confusion and also resolved this issue which was caused by a variable naming conflict. --- backend/open_webui/utils/tools.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index b5d916e1d..16dc42985 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -276,8 +276,8 @@ def convert_function_to_pydantic_model(func: Callable) -> type[BaseModel]: docstring = func.__doc__ - description = parse_description(docstring) - function_descriptions = parse_docstring(docstring) + function_description = parse_description(docstring) + function_param_descriptions = parse_docstring(docstring) field_defs = {} for name, param in parameters.items(): @@ -285,15 +285,15 @@ def convert_function_to_pydantic_model(func: Callable) -> type[BaseModel]: type_hint = type_hints.get(name, Any) default_value = param.default if param.default is not param.empty else ... - description = function_descriptions.get(name, None) + param_description = function_param_descriptions.get(name, None) - if description: - field_defs[name] = type_hint, Field(default_value, description=description) + if param_description: + field_defs[name] = type_hint, Field(default_value, description=param_description) else: field_defs[name] = type_hint, default_value model = create_model(func.__name__, **field_defs) - model.__doc__ = description + model.__doc__ = function_description return model