mirror of
https://github.com/open-webui/open-webui.git
synced 2024-11-25 16:33:05 +08:00
Merge pull request #7279 from Luceurre/fix/missing-tool-description
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run
Integration Test / Run Cypress Integration Tests (push) Waiting to run
Integration Test / Run Migration Tests (push) Waiting to run
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run
Integration Test / Run Cypress Integration Tests (push) Waiting to run
Integration Test / Run Migration Tests (push) Waiting to run
fix: add missing tool description
This commit is contained in:
commit
5ed5e532a9
@ -90,6 +90,32 @@ def get_tools(
|
||||
return tools_dict
|
||||
|
||||
|
||||
def parse_description(docstring: str | None) -> str:
|
||||
"""
|
||||
Parse a function's docstring to extract the description.
|
||||
|
||||
Args:
|
||||
docstring (str): The docstring to parse.
|
||||
|
||||
Returns:
|
||||
str: The description.
|
||||
"""
|
||||
|
||||
if not docstring:
|
||||
return ""
|
||||
|
||||
lines = [line.strip() for line in docstring.strip().split("\n")]
|
||||
description_lines: list[str] = []
|
||||
|
||||
for line in lines:
|
||||
if re.match(r":param", line) or re.match(r":return", line):
|
||||
break
|
||||
|
||||
description_lines.append(line)
|
||||
|
||||
return "\n".join(description_lines)
|
||||
|
||||
|
||||
def parse_docstring(docstring):
|
||||
"""
|
||||
Parse a function's docstring to extract parameter descriptions in reST format.
|
||||
@ -138,6 +164,8 @@ def function_to_pydantic_model(func: Callable) -> type[BaseModel]:
|
||||
docstring = func.__doc__
|
||||
descriptions = parse_docstring(docstring)
|
||||
|
||||
tool_description = parse_description(docstring)
|
||||
|
||||
field_defs = {}
|
||||
for name, param in parameters.items():
|
||||
type_hint = type_hints.get(name, Any)
|
||||
@ -148,7 +176,10 @@ def function_to_pydantic_model(func: Callable) -> type[BaseModel]:
|
||||
continue
|
||||
field_defs[name] = type_hint, Field(default_value, description=description)
|
||||
|
||||
return create_model(func.__name__, **field_defs)
|
||||
model = create_model(func.__name__, **field_defs)
|
||||
model.__doc__ = tool_description
|
||||
|
||||
return model
|
||||
|
||||
|
||||
def get_callable_attributes(tool: object) -> list[Callable]:
|
||||
|
Loading…
Reference in New Issue
Block a user