Skip to content

utils: fix description of tool parameters named args - #766

Open
RaphaelFakhri wants to merge 1 commit into
ollama:mainfrom
RaphaelFakhri:fix/docstring-args-param-description
Open

RaphaelFakhri wants to merge 1 commit into
ollama:mainfrom
RaphaelFakhri:fix/docstring-args-param-description

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

convert_function_to_tool gives an undocumented parameter named args the whole raw Args: section of the docstring as its description.

_parse_docstring stores the raw Args: section under the args key of its result dictionary. convert_function_to_tool looks up each parameter's description by name in that same dictionary, so a parameter named args reads the section text instead of its own entry. The Returns:, Yields: and Raises: text collides the same way with a parameter named _.

def run_command(command: str, args: list) -> str:
  """
  Run a shell command.

  Args:
    command: The executable to run
  """

Before this change, the args property is sent to the model with the description 'command: The executable to run\n\n'. After this change, it is '', the same as any other undocumented parameter.

Changes

  • Collect the Args: lines in a local list instead of in the result dictionary, and stop storing the Returns:/Yields:/Raises: text, which nothing reads.
  • Add test_function_with_parameter_named_args to tests/test_utils.py.

Testing

  • pytest tests/test_utils.py::test_function_with_parameter_named_args fails without the fix and passes with it.
  • pytest ollama tests: 123 passed.
  • hatch fmt --check -f and hatch fmt --check -l pass.

Fixes #765

This touches the same loop in _parse_docstring as #747, which fixes a different bug (continuation lines with colons). Whichever merges second needs a small rebase.

convert_function_to_tool stored the raw Args section of a docstring under the 'args' key of the parsed result, the same key used to look up a parameter named args. An undocumented args parameter received the whole Args section as its description.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

convert_function_to_tool: undocumented parameter named args gets the whole Args section as its description

1 participant