Merge pull request #7279 from Luceurre/fix/missing-tool-description
Some checks failed
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
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
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
Deploy to HuggingFace Spaces / check-secret (push) Successful in 7s
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Failing after 1m35s
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Has been cancelled
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Has been cancelled
Create and publish Docker images with specific build args / merge-main-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-cuda-images (push) Has been cancelled
Create and publish Docker images with specific build args / merge-ollama-images (push) Has been cancelled

fix: add missing tool description
This commit is contained in:
Timothy Jaeryang Baek 2024-11-23 10:39:47 -08:00 committed by GitHub
commit 5ed5e532a9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -90,6 +90,32 @@ def get_tools(
return tools_dict 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): def parse_docstring(docstring):
""" """
Parse a function's docstring to extract parameter descriptions in reST format. 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__ docstring = func.__doc__
descriptions = parse_docstring(docstring) descriptions = parse_docstring(docstring)
tool_description = parse_description(docstring)
field_defs = {} field_defs = {}
for name, param in parameters.items(): for name, param in parameters.items():
type_hint = type_hints.get(name, Any) type_hint = type_hints.get(name, Any)
@ -148,7 +176,10 @@ def function_to_pydantic_model(func: Callable) -> type[BaseModel]:
continue continue
field_defs[name] = type_hint, Field(default_value, description=description) 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]: def get_callable_attributes(tool: object) -> list[Callable]: