From a4ec34a386b56108a00b400d81e4aeba11bc5506 Mon Sep 17 00:00:00 2001 From: ParthSareen Date: Tue, 19 Nov 2024 09:50:03 -0800 Subject: [PATCH] Add better messaging for chat --- ollama/_client.py | 48 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/ollama/_client.py b/ollama/_client.py index f085793..8b3002b 100644 --- a/ollama/_client.py +++ b/ollama/_client.py @@ -298,12 +298,28 @@ class Client(BaseClient): Create a chat response using the requested model. Args: - tools (Sequence[Union[Mapping[str, Any], Tool, Callable]]): + tools: A JSON schema as a dict, an Ollama Tool or a Python Function. Python functions need to follow Google style docstrings to be converted to an Ollama Tool. - For more information, see: https://google.github.io/styleguide/pyguide.html#38-Docstrings - stream (bool): Whether to stream the response. - format (Optional[Literal['', 'json']]): The format of the response. + For more information, see: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings + stream: Whether to stream the response. + format: The format of the response. + + Example: + def add_two_numbers(a: int, b: int) -> int: + \""" + Add two numbers together. + + Args: + a: First number to add + b: Second number to add + + Returns: + int: The sum of a and b + \""" + return a + b + + client.chat(model='llama3.1:8b', tools=[add_two_numbers], messages=[...]) Raises `RequestError` if a model is not provided. @@ -783,6 +799,30 @@ class AsyncClient(BaseClient): """ Create a chat response using the requested model. + Args: + tools: + A JSON schema as a dict, an Ollama Tool or a Python Function. + Python functions need to follow Google style docstrings to be converted to an Ollama Tool. + For more information, see: https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings + stream: Whether to stream the response. + format: The format of the response. + + Example: + def add_two_numbers(a: int, b: int) -> int: + \""" + Add two numbers together. + + Args: + a: First number to add + b: Second number to add + + Returns: + int: The sum of a and b + \""" + return a + b + + client.chat(model='llama3.1:8b', tools=[add_two_numbers], messages=[...]) + Raises `RequestError` if a model is not provided. Raises `ResponseError` if the request could not be fulfilled.