The description of the tool, which the llm uses to decide if it needs to call it, it's currently the second line of the docstring. It's not very intuitive nor it's documented anywhere. Moreover, if the tool is a bit complex is cumbersome to put everything in a single line.
With this change, the description is considered to be everything before the first :param, or the whole docstring if there is none.
Before submitting, make sure you've checked the following:
Target branch: Please verify that the pull request targets the dev branch.
Description: Provide a concise description of the changes made in this pull request.
Changelog: Ensure a changelog entry following the format of Keep a Changelog is added at the bottom of the PR description.
Documentation: Have you updated relevant documentation Open WebUI Docs, or other documentation sources?
Dependencies: Are there any new dependencies? Have you updated the dependency versions in the documentation?
Testing: Have you written and run sufficient tests for validating the changes?
Code review: Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
Prefix: To cleary categorize this pull request, prefix the pull request title, using one of the following:
BREAKING CHANGE: Significant changes that may affect compatibility
build: Changes that affect the build system or external dependencies
ci: Changes to our continuous integration processes or workflows
chore: Refactor, cleanup, or other non-functional code changes
docs: Documentation update or addition
feat: Introduces a new feature or enhancement to the codebase
fix: Bug fix or error correction
i18n: Internationalization or localization changes
perf: Performance improvement
refactor: Code restructuring for better maintainability, readability, or scalability
style: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
test: Adding missing tests or correcting existing tests
WIP: Work in progress, a temporary label for incomplete or ongoing work
Changelog Entry
Description
N/A
Added
N/A
Changed
backend/open_webui/utils/tools.py
Deprecated
N/A
Removed
N/A
Fixed
Tools descriptions can be no be multiline.
Security
N/A
Breaking Changes
N/A
Additional Information
Some quick tests, llm generated.
defdoc_to_dict(docstring):lines=docstring.split("\n")param_idx=docstring.find(":param")ifparam_idx==-1:description=docstringelse:description=docstring[0:param_idx]param_dict={}forlineinlines:if":param"inline:line=line.replace(":param","").strip()param,desc=line.split(":",1)param_dict[param.strip()]=desc.strip()ret_dict={"description":description.strip(),"params":param_dict}returnret_dict# Pruebasdeftest_no_params():docstring="This is a simple function."expected={"description":"This is a simple function.","params":{}}assertdoc_to_dict(docstring)==expecteddeftest_one_param():docstring="""This function adds two numbers.
:param a: The first number."""expected={"description":"This function adds two numbers.","params":{"a":"The first number."}}assertdoc_to_dict(docstring)==expecteddeftest_multiple_params():docstring="""This function adds two numbers.
:param a: The first number.
:param b: The second number."""expected={"description":"This function adds two numbers.","params":{"a":"The first number.","b":"The second number."}}assertdoc_to_dict(docstring)==expecteddeftest_return_with_params():docstring="""This function adds two numbers.
:param a: The first number.
:param b: The second number.
:returns: The sum of a and b."""expected={"description":"This function adds two numbers.","params":{"a":"The first number.","b":"The second number."}}assertdoc_to_dict(docstring)==expecteddeftest_no_description():docstring=""":param a: The first number.
:param b: The second number."""expected={"description":"","params":{"a":"The first number.","b":"The second number."}}assertdoc_to_dict(docstring)==expecteddeftest_invalid_param_format():docstring="""This function adds two numbers.
:param a The first number.
:param b - The second number."""try:doc_to_dict(docstring)assertFalse,"Expected ValueError"exceptValueError:passdeftest_whitespace_in_docstring():docstring="""This function adds two numbers.
:param a: The first number.
:param b: The second number."""expected={"description":"This function adds two numbers.","params":{"a":"The first number.","b":"The second number."}}assertdoc_to_dict(docstring)==expecteddeftest_param_without_description():docstring="""This function adds two numbers.
:param a: """expected={"description":"This function adds two numbers.","params":{"a":""}}assertdoc_to_dict(docstring)==expecteddeftest_special_characters_in_description():docstring="""This function adds two numbers!
:param a: The first number @@@.
:param b: The second number ###."""expected={"description":"This function adds two numbers!","params":{"a":"The first number @@@.","b":"The second number ###."}}assertdoc_to_dict(docstring)==expecteddeftest_long_param_names():docstring="""This function processes data.
:param data_input_1: The first dataset.
:param data_input_2: The second dataset."""expected={"description":"This function processes data.","params":{"data_input_1":"The first dataset.","data_input_2":"The second dataset."}}assertdoc_to_dict(docstring)==expected# Para ejecutar las pruebas manualmente si no usas pytest:if__name__=="__main__":test_no_params()test_one_param()test_multiple_params()test_return_with_params()test_no_description()test_invalid_param_format()test_whitespace_in_docstring()test_param_without_description()test_special_characters_in_description()test_long_param_names()print("Todas las pruebas pasaron correctamente.")
Screenshots or Videos
N/A
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/5779
**Author:** [@smonux](https://github.com/smonux)
**Created:** 9/28/2024
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `dev`
---
### 📝 Commits (2)
- [`6bc1528`](https://github.com/open-webui/open-webui/commit/6bc15289a7633102523831c0fcc2c792c02035ac) fix: tool description can now be multiline
- [`1a658dd`](https://github.com/open-webui/open-webui/commit/1a658ddf4c7611647ccfec200b75d05a2dd9c2ab) formatting
### 📊 Changes
**1 file changed** (+6 additions, -1 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/utils/tools.py` (+6 -1)
</details>
### 📄 Description
# Pull Request Checklist
The description of the tool, which the llm uses to decide if it needs to call it, it's currently the **second** line of the docstring. It's not very intuitive nor it's documented anywhere. Moreover, if the tool is a bit complex is cumbersome to put everything in a single line.
With this change, the description is considered to be everything before the first :param, or the whole docstring if there is none.
**Before submitting, make sure you've checked the following:**
- [x] **Target branch:** Please verify that the pull request targets the `dev` branch.
- [x] **Description:** Provide a concise description of the changes made in this pull request.
- [ ] **Changelog:** Ensure a changelog entry following the format of [Keep a Changelog](https://keepachangelog.com/) is added at the bottom of the PR description.
- [ ] **Documentation:** Have you updated relevant documentation [Open WebUI Docs](https://github.com/open-webui/docs), or other documentation sources?
- [ ] **Dependencies:** Are there any new dependencies? Have you updated the dependency versions in the documentation?
- [x] **Testing:** Have you written and run sufficient tests for validating the changes?
- [x] **Code review:** Have you performed a self-review of your code, addressing any coding standard issues and ensuring adherence to the project's coding standards?
- [x] **Prefix:** To cleary categorize this pull request, prefix the pull request title, using one of the following:
- **BREAKING CHANGE**: Significant changes that may affect compatibility
- **build**: Changes that affect the build system or external dependencies
- **ci**: Changes to our continuous integration processes or workflows
- **chore**: Refactor, cleanup, or other non-functional code changes
- **docs**: Documentation update or addition
- **feat**: Introduces a new feature or enhancement to the codebase
- **fix**: Bug fix or error correction
- **i18n**: Internationalization or localization changes
- **perf**: Performance improvement
- **refactor**: Code restructuring for better maintainability, readability, or scalability
- **style**: Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc.)
- **test**: Adding missing tests or correcting existing tests
- **WIP**: Work in progress, a temporary label for incomplete or ongoing work
# Changelog Entry
### Description
N/A
### Added
N/A
### Changed
backend/open_webui/utils/tools.py
### Deprecated
N/A
### Removed
N/A
### Fixed
Tools descriptions can be no be multiline.
### Security
N/A
### Breaking Changes
N/A
### Additional Information
Some quick tests, llm generated.
```python
def doc_to_dict(docstring):
lines = docstring.split("\n")
param_idx = docstring.find(":param")
if param_idx == -1:
description = docstring
else:
description = docstring[0:param_idx]
param_dict = {}
for line in lines:
if ":param" in line:
line = line.replace(":param", "").strip()
param, desc = line.split(":", 1)
param_dict[param.strip()] = desc.strip()
ret_dict = {"description": description.strip(), "params": param_dict}
return ret_dict
# Pruebas
def test_no_params():
docstring = "This is a simple function."
expected = {
"description": "This is a simple function.",
"params": {}
}
assert doc_to_dict(docstring) == expected
def test_one_param():
docstring = """This function adds two numbers.
:param a: The first number."""
expected = {
"description": "This function adds two numbers.",
"params": {"a": "The first number."}
}
assert doc_to_dict(docstring) == expected
def test_multiple_params():
docstring = """This function adds two numbers.
:param a: The first number.
:param b: The second number."""
expected = {
"description": "This function adds two numbers.",
"params": {"a": "The first number.", "b": "The second number."}
}
assert doc_to_dict(docstring) == expected
def test_return_with_params():
docstring = """This function adds two numbers.
:param a: The first number.
:param b: The second number.
:returns: The sum of a and b."""
expected = {
"description": "This function adds two numbers.",
"params": {"a": "The first number.", "b": "The second number."}
}
assert doc_to_dict(docstring) == expected
def test_no_description():
docstring = """:param a: The first number.
:param b: The second number."""
expected = {
"description": "",
"params": {"a": "The first number.", "b": "The second number."}
}
assert doc_to_dict(docstring) == expected
def test_invalid_param_format():
docstring = """This function adds two numbers.
:param a The first number.
:param b - The second number."""
try:
doc_to_dict(docstring)
assert False, "Expected ValueError"
except ValueError:
pass
def test_whitespace_in_docstring():
docstring = """This function adds two numbers.
:param a: The first number.
:param b: The second number."""
expected = {
"description": "This function adds two numbers.",
"params": {"a": "The first number.", "b": "The second number."}
}
assert doc_to_dict(docstring) == expected
def test_param_without_description():
docstring = """This function adds two numbers.
:param a: """
expected = {
"description": "This function adds two numbers.",
"params": {"a": ""}
}
assert doc_to_dict(docstring) == expected
def test_special_characters_in_description():
docstring = """This function adds two numbers!
:param a: The first number @@@.
:param b: The second number ###."""
expected = {
"description": "This function adds two numbers!",
"params": {"a": "The first number @@@.", "b": "The second number ###."}
}
assert doc_to_dict(docstring) == expected
def test_long_param_names():
docstring = """This function processes data.
:param data_input_1: The first dataset.
:param data_input_2: The second dataset."""
expected = {
"description": "This function processes data.",
"params": {"data_input_1": "The first dataset.", "data_input_2": "The second dataset."}
}
assert doc_to_dict(docstring) == expected
# Para ejecutar las pruebas manualmente si no usas pytest:
if __name__ == "__main__":
test_no_params()
test_one_param()
test_multiple_params()
test_return_with_params()
test_no_description()
test_invalid_param_format()
test_whitespace_in_docstring()
test_param_without_description()
test_special_characters_in_description()
test_long_param_names()
print("Todas las pruebas pasaron correctamente.")
```
### Screenshots or Videos
N/A
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/5779
Author: @smonux
Created: 9/28/2024
Status: ❌ Closed
Base:
dev← Head:dev📝 Commits (2)
6bc1528fix: tool description can now be multiline1a658ddformatting📊 Changes
1 file changed (+6 additions, -1 deletions)
View changed files
📝
backend/open_webui/utils/tools.py(+6 -1)📄 Description
Pull Request Checklist
The description of the tool, which the llm uses to decide if it needs to call it, it's currently the second line of the docstring. It's not very intuitive nor it's documented anywhere. Moreover, if the tool is a bit complex is cumbersome to put everything in a single line.
With this change, the description is considered to be everything before the first :param, or the whole docstring if there is none.
Before submitting, make sure you've checked the following:
devbranch.Changelog Entry
Description
N/A
Added
N/A
Changed
backend/open_webui/utils/tools.py
Deprecated
N/A
Removed
N/A
Fixed
Tools descriptions can be no be multiline.
Security
N/A
Breaking Changes
N/A
Additional Information
Some quick tests, llm generated.
Screenshots or Videos
N/A
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.