From b64c452a66c0e8df893fc20dcf8cf2ae041fa5e7 Mon Sep 17 00:00:00 2001 From: William Bakst Date: Wed, 27 Nov 2024 22:41:14 -0800 Subject: [PATCH 1/2] docs: streaming partial tools with examples --- docs/learn/tools.md | 28 +++++++++++++++ .../anthropic/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../anthropic/base_tool/messages.py | 36 +++++++++++++++++++ .../anthropic/base_tool/shorthand.py | 36 +++++++++++++++++++ .../anthropic/base_tool/string_template.py | 36 +++++++++++++++++++ .../anthropic/function/base_message_param.py | 35 ++++++++++++++++++ .../anthropic/function/messages.py | 35 ++++++++++++++++++ .../anthropic/function/shorthand.py | 35 ++++++++++++++++++ .../anthropic/function/string_template.py | 35 ++++++++++++++++++ .../azure/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../azure/base_tool/messages.py | 36 +++++++++++++++++++ .../azure/base_tool/shorthand.py | 36 +++++++++++++++++++ .../azure/base_tool/string_template.py | 36 +++++++++++++++++++ .../azure/function/base_message_param.py | 35 ++++++++++++++++++ .../azure/function/messages.py | 35 ++++++++++++++++++ .../azure/function/shorthand.py | 35 ++++++++++++++++++ .../azure/function/string_template.py | 35 ++++++++++++++++++ .../bedrock/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../bedrock/base_tool/messages.py | 36 +++++++++++++++++++ .../bedrock/base_tool/shorthand.py | 36 +++++++++++++++++++ .../bedrock/base_tool/string_template.py | 36 +++++++++++++++++++ .../bedrock/function/base_message_param.py | 35 ++++++++++++++++++ .../bedrock/function/messages.py | 35 ++++++++++++++++++ .../bedrock/function/shorthand.py | 35 ++++++++++++++++++ .../bedrock/function/string_template.py | 35 ++++++++++++++++++ .../cohere/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../cohere/base_tool/messages.py | 36 +++++++++++++++++++ .../cohere/base_tool/shorthand.py | 36 +++++++++++++++++++ .../cohere/base_tool/string_template.py | 36 +++++++++++++++++++ .../cohere/function/base_message_param.py | 35 ++++++++++++++++++ .../cohere/function/messages.py | 35 ++++++++++++++++++ .../cohere/function/shorthand.py | 35 ++++++++++++++++++ .../cohere/function/string_template.py | 35 ++++++++++++++++++ .../gemini/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../gemini/base_tool/messages.py | 36 +++++++++++++++++++ .../gemini/base_tool/shorthand.py | 36 +++++++++++++++++++ .../gemini/base_tool/string_template.py | 36 +++++++++++++++++++ .../gemini/function/base_message_param.py | 35 ++++++++++++++++++ .../gemini/function/messages.py | 35 ++++++++++++++++++ .../gemini/function/shorthand.py | 35 ++++++++++++++++++ .../gemini/function/string_template.py | 35 ++++++++++++++++++ .../groq/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../groq/base_tool/messages.py | 36 +++++++++++++++++++ .../groq/base_tool/shorthand.py | 36 +++++++++++++++++++ .../groq/base_tool/string_template.py | 36 +++++++++++++++++++ .../groq/function/base_message_param.py | 35 ++++++++++++++++++ .../groq/function/messages.py | 35 ++++++++++++++++++ .../groq/function/shorthand.py | 35 ++++++++++++++++++ .../groq/function/string_template.py | 35 ++++++++++++++++++ .../litellm/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../litellm/base_tool/messages.py | 36 +++++++++++++++++++ .../litellm/base_tool/shorthand.py | 36 +++++++++++++++++++ .../litellm/base_tool/string_template.py | 36 +++++++++++++++++++ .../litellm/function/base_message_param.py | 35 ++++++++++++++++++ .../litellm/function/messages.py | 35 ++++++++++++++++++ .../litellm/function/shorthand.py | 35 ++++++++++++++++++ .../litellm/function/string_template.py | 35 ++++++++++++++++++ .../mistral/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../mistral/base_tool/messages.py | 36 +++++++++++++++++++ .../mistral/base_tool/shorthand.py | 36 +++++++++++++++++++ .../mistral/base_tool/string_template.py | 36 +++++++++++++++++++ .../mistral/function/base_message_param.py | 35 ++++++++++++++++++ .../mistral/function/messages.py | 35 ++++++++++++++++++ .../mistral/function/shorthand.py | 35 ++++++++++++++++++ .../mistral/function/string_template.py | 35 ++++++++++++++++++ .../openai/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../openai/base_tool/messages.py | 36 +++++++++++++++++++ .../openai/base_tool/shorthand.py | 36 +++++++++++++++++++ .../openai/base_tool/string_template.py | 36 +++++++++++++++++++ .../openai/function/base_message_param.py | 35 ++++++++++++++++++ .../openai/function/messages.py | 35 ++++++++++++++++++ .../openai/function/shorthand.py | 35 ++++++++++++++++++ .../openai/function/string_template.py | 35 ++++++++++++++++++ .../vertex/base_tool/base_message_param.py | 36 +++++++++++++++++++ .../vertex/base_tool/messages.py | 36 +++++++++++++++++++ .../vertex/base_tool/shorthand.py | 36 +++++++++++++++++++ .../vertex/base_tool/string_template.py | 36 +++++++++++++++++++ .../vertex/function/base_message_param.py | 35 ++++++++++++++++++ .../vertex/function/messages.py | 35 ++++++++++++++++++ .../vertex/function/shorthand.py | 35 ++++++++++++++++++ .../vertex/function/string_template.py | 35 ++++++++++++++++++ 81 files changed, 2868 insertions(+) create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/anthropic/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/azure/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/bedrock/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/cohere/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/gemini/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/groq/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/litellm/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/mistral/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/openai/function/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/base_tool/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/base_tool/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/base_tool/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/base_tool/string_template.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/function/base_message_param.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/function/messages.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/function/shorthand.py create mode 100644 examples/learn/tools/partial_tool_streams/vertex/function/string_template.py diff --git a/docs/learn/tools.md b/docs/learn/tools.md index c2c8cb90e..d37b2a878 100644 --- a/docs/learn/tools.md +++ b/docs/learn/tools.md @@ -260,6 +260,34 @@ Mirascope supports streaming responses with tools, which is useful for long-runn If you think we're missing any, let us know! +### Streaming Partial Tools + +You can also stream intermediate partial tools and their deltas (rather than just the fully constructed tool) by setting `stream={"partial_tools": True}`: + +!!! mira "" + + {% for tool_method, tool_method_title in tool_methods %} + === "{{ tool_method_title }}" + + {% for method, method_title in zip(prompt_writing_methods, prompt_writing_method_titles) %} + === "{{ method_title }}" + + {% for provider in supported_llm_providers %} + === "{{ provider }}" + + {% if tool_method == "function" %} + ```python hl_lines="21 30" + {% else %} + ```python hl_lines="22 31" + {% endif %} + --8<-- "examples/learn/tools/partial_tool_streams/{{ provider | provider_dir }}/{{ tool_method }}/{{ method }}.py" + ``` + {% endfor %} + + {% endfor %} + + {% endfor %} + ## Tool Message Parameters !!! mira "" diff --git a/examples/learn/tools/partial_tool_streams/anthropic/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/base_message_param.py new file mode 100644 index 000000000..f28e69981 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, anthropic +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/messages.py new file mode 100644 index 000000000..7eddca99c --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, anthropic +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/shorthand.py new file mode 100644 index 000000000..6e68b1a00 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, anthropic +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/string_template.py new file mode 100644 index 000000000..7e65faef9 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, anthropic, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/anthropic/function/base_message_param.py new file mode 100644 index 000000000..e90bda586 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, anthropic + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/function/messages.py b/examples/learn/tools/partial_tool_streams/anthropic/function/messages.py new file mode 100644 index 000000000..7f00c6cb6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, anthropic + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/function/shorthand.py b/examples/learn/tools/partial_tool_streams/anthropic/function/shorthand.py new file mode 100644 index 000000000..f6654d159 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import anthropic + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/anthropic/function/string_template.py b/examples/learn/tools/partial_tool_streams/anthropic/function/string_template.py new file mode 100644 index 000000000..04232cd34 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/anthropic/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import anthropic, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@anthropic.call( + "claude-3-5-sonnet-20240620", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/azure/base_tool/base_message_param.py new file mode 100644 index 000000000..90a881f76 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, azure +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/azure/base_tool/messages.py new file mode 100644 index 000000000..26f6ea81b --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, azure +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/azure/base_tool/shorthand.py new file mode 100644 index 000000000..4a0f690eb --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, azure +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/azure/base_tool/string_template.py new file mode 100644 index 000000000..a8caa94b6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, azure, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/azure/function/base_message_param.py new file mode 100644 index 000000000..e3833e3be --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, azure + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/function/messages.py b/examples/learn/tools/partial_tool_streams/azure/function/messages.py new file mode 100644 index 000000000..ab55681ea --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, azure + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/function/shorthand.py b/examples/learn/tools/partial_tool_streams/azure/function/shorthand.py new file mode 100644 index 000000000..f356649a2 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import azure + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/azure/function/string_template.py b/examples/learn/tools/partial_tool_streams/azure/function/string_template.py new file mode 100644 index 000000000..b0a3abd1e --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/azure/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import azure, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@azure.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/base_message_param.py new file mode 100644 index 000000000..86a31f02d --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, bedrock +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/messages.py new file mode 100644 index 000000000..9b89193cf --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, bedrock +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/shorthand.py new file mode 100644 index 000000000..c58af9fd8 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, bedrock +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/string_template.py new file mode 100644 index 000000000..60881fc1b --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, bedrock, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/bedrock/function/base_message_param.py new file mode 100644 index 000000000..193e8d97f --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, bedrock + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/function/messages.py b/examples/learn/tools/partial_tool_streams/bedrock/function/messages.py new file mode 100644 index 000000000..92e3eb7bc --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, bedrock + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/function/shorthand.py b/examples/learn/tools/partial_tool_streams/bedrock/function/shorthand.py new file mode 100644 index 000000000..806437a3c --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import bedrock + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/bedrock/function/string_template.py b/examples/learn/tools/partial_tool_streams/bedrock/function/string_template.py new file mode 100644 index 000000000..7d3b22183 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/bedrock/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import bedrock, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@bedrock.call( + "anthropic.claude-3-haiku-20240307-v1:0", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/cohere/base_tool/base_message_param.py new file mode 100644 index 000000000..7290e186f --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, cohere +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/cohere/base_tool/messages.py new file mode 100644 index 000000000..498fc919b --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, cohere +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/cohere/base_tool/shorthand.py new file mode 100644 index 000000000..ef20cf3c3 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, cohere +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/cohere/base_tool/string_template.py new file mode 100644 index 000000000..238accf0d --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, cohere, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/cohere/function/base_message_param.py new file mode 100644 index 000000000..de4cfe1d4 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, cohere + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/function/messages.py b/examples/learn/tools/partial_tool_streams/cohere/function/messages.py new file mode 100644 index 000000000..7cc7106a4 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, cohere + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/function/shorthand.py b/examples/learn/tools/partial_tool_streams/cohere/function/shorthand.py new file mode 100644 index 000000000..748627550 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import cohere + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/cohere/function/string_template.py b/examples/learn/tools/partial_tool_streams/cohere/function/string_template.py new file mode 100644 index 000000000..c16f41674 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/cohere/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import cohere, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@cohere.call( + "command-r-plus", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/gemini/base_tool/base_message_param.py new file mode 100644 index 000000000..fedc58a06 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, gemini +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/gemini/base_tool/messages.py new file mode 100644 index 000000000..13dbf3c9e --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, gemini +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/gemini/base_tool/shorthand.py new file mode 100644 index 000000000..781cef907 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, gemini +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/gemini/base_tool/string_template.py new file mode 100644 index 000000000..bc0ff1e35 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, gemini, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/gemini/function/base_message_param.py new file mode 100644 index 000000000..4ab6865f6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, gemini + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/function/messages.py b/examples/learn/tools/partial_tool_streams/gemini/function/messages.py new file mode 100644 index 000000000..e1205d948 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, gemini + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/function/shorthand.py b/examples/learn/tools/partial_tool_streams/gemini/function/shorthand.py new file mode 100644 index 000000000..5b037a083 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import gemini + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/gemini/function/string_template.py b/examples/learn/tools/partial_tool_streams/gemini/function/string_template.py new file mode 100644 index 000000000..d98721dde --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/gemini/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import gemini, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@gemini.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/groq/base_tool/base_message_param.py new file mode 100644 index 000000000..6a1ae13e5 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, groq +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/groq/base_tool/messages.py new file mode 100644 index 000000000..c2ebe47b7 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, groq +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/groq/base_tool/shorthand.py new file mode 100644 index 000000000..a53d9003e --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, groq +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/groq/base_tool/string_template.py new file mode 100644 index 000000000..66cfa5ed6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, groq, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/groq/function/base_message_param.py new file mode 100644 index 000000000..8a9078af3 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, groq + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/function/messages.py b/examples/learn/tools/partial_tool_streams/groq/function/messages.py new file mode 100644 index 000000000..ee23cf0d5 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, groq + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/function/shorthand.py b/examples/learn/tools/partial_tool_streams/groq/function/shorthand.py new file mode 100644 index 000000000..1a34c7816 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import groq + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/groq/function/string_template.py b/examples/learn/tools/partial_tool_streams/groq/function/string_template.py new file mode 100644 index 000000000..ac3a5d070 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/groq/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import groq, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@groq.call( + "llama-3.1-70b-versatile", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/litellm/base_tool/base_message_param.py new file mode 100644 index 000000000..1ec6f1f30 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, litellm +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/litellm/base_tool/messages.py new file mode 100644 index 000000000..ed937e479 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, litellm +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/litellm/base_tool/shorthand.py new file mode 100644 index 000000000..ed0627388 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, litellm +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/litellm/base_tool/string_template.py new file mode 100644 index 000000000..9a5417fc6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, litellm, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/litellm/function/base_message_param.py new file mode 100644 index 000000000..f81c6cdaf --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, litellm + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/function/messages.py b/examples/learn/tools/partial_tool_streams/litellm/function/messages.py new file mode 100644 index 000000000..08c520598 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, litellm + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/function/shorthand.py b/examples/learn/tools/partial_tool_streams/litellm/function/shorthand.py new file mode 100644 index 000000000..29dfa6f0a --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import litellm + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/litellm/function/string_template.py b/examples/learn/tools/partial_tool_streams/litellm/function/string_template.py new file mode 100644 index 000000000..ed4e2cccb --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/litellm/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import litellm, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@litellm.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/mistral/base_tool/base_message_param.py new file mode 100644 index 000000000..eebeb051e --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, mistral +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/mistral/base_tool/messages.py new file mode 100644 index 000000000..9867dd01b --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, mistral +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/mistral/base_tool/shorthand.py new file mode 100644 index 000000000..f5975a278 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, mistral +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/mistral/base_tool/string_template.py new file mode 100644 index 000000000..03aa68ec1 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, mistral, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/mistral/function/base_message_param.py new file mode 100644 index 000000000..73e31b76b --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, mistral + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/function/messages.py b/examples/learn/tools/partial_tool_streams/mistral/function/messages.py new file mode 100644 index 000000000..72946398a --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, mistral + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/function/shorthand.py b/examples/learn/tools/partial_tool_streams/mistral/function/shorthand.py new file mode 100644 index 000000000..644f310c6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import mistral + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/mistral/function/string_template.py b/examples/learn/tools/partial_tool_streams/mistral/function/string_template.py new file mode 100644 index 000000000..a50faf3a2 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/mistral/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import mistral, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@mistral.call( + "mistral-large-latest", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/openai/base_tool/base_message_param.py new file mode 100644 index 000000000..6a31320de --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, openai +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/openai/base_tool/messages.py new file mode 100644 index 000000000..a8fee8030 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, openai +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/openai/base_tool/shorthand.py new file mode 100644 index 000000000..0fa6e2994 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, openai +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/openai/base_tool/string_template.py new file mode 100644 index 000000000..ed6032fb2 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, openai, prompt_template +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/openai/function/base_message_param.py new file mode 100644 index 000000000..60d404cd2 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, openai + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/function/messages.py b/examples/learn/tools/partial_tool_streams/openai/function/messages.py new file mode 100644 index 000000000..2a7c692b1 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, openai + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/function/shorthand.py b/examples/learn/tools/partial_tool_streams/openai/function/shorthand.py new file mode 100644 index 000000000..aa74e94e0 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import openai + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/openai/function/string_template.py b/examples/learn/tools/partial_tool_streams/openai/function/string_template.py new file mode 100644 index 000000000..d191381e4 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/openai/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import openai, prompt_template + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@openai.call( + "gpt-4o-mini", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/base_tool/base_message_param.py b/examples/learn/tools/partial_tool_streams/vertex/base_tool/base_message_param.py new file mode 100644 index 000000000..b5f15c5cb --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/base_tool/base_message_param.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseMessageParam, BaseTool, vertex +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/base_tool/messages.py b/examples/learn/tools/partial_tool_streams/vertex/base_tool/messages.py new file mode 100644 index 000000000..d38235db6 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/base_tool/messages.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, Messages, vertex +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/base_tool/shorthand.py b/examples/learn/tools/partial_tool_streams/vertex/base_tool/shorthand.py new file mode 100644 index 000000000..f6a3f696c --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/base_tool/shorthand.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, vertex +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/base_tool/string_template.py b/examples/learn/tools/partial_tool_streams/vertex/base_tool/string_template.py new file mode 100644 index 000000000..6a404dbfd --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/base_tool/string_template.py @@ -0,0 +1,36 @@ +from mirascope.core import BaseTool, prompt_template, vertex +from pydantic import Field + + +class GetBookAuthor(BaseTool): + """Returns the author of the book with the given title.""" + + title: str = Field(..., description="The title of the book.") + + def call(self) -> str: + if self.title == "The Name of the Wind": + return "Patrick Rothfuss" + elif self.title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[GetBookAuthor], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/function/base_message_param.py b/examples/learn/tools/partial_tool_streams/vertex/function/base_message_param.py new file mode 100644 index 000000000..0027c9afc --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/function/base_message_param.py @@ -0,0 +1,35 @@ +from mirascope.core import BaseMessageParam, vertex + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> list[BaseMessageParam]: + return [BaseMessageParam(role="user", content=f"Who wrote {books}?")] + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/function/messages.py b/examples/learn/tools/partial_tool_streams/vertex/function/messages.py new file mode 100644 index 000000000..7483731b9 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/function/messages.py @@ -0,0 +1,35 @@ +from mirascope.core import Messages, vertex + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> Messages.Type: + return Messages.User(f"Who wrote {books}?") + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/function/shorthand.py b/examples/learn/tools/partial_tool_streams/vertex/function/shorthand.py new file mode 100644 index 000000000..83fc91a88 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/function/shorthand.py @@ -0,0 +1,35 @@ +from mirascope.core import vertex + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +def identify_authors(books: list[str]) -> str: + return f"Who wrote {books}?" + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) diff --git a/examples/learn/tools/partial_tool_streams/vertex/function/string_template.py b/examples/learn/tools/partial_tool_streams/vertex/function/string_template.py new file mode 100644 index 000000000..b8bc6b3b8 --- /dev/null +++ b/examples/learn/tools/partial_tool_streams/vertex/function/string_template.py @@ -0,0 +1,35 @@ +from mirascope.core import prompt_template, vertex + + +def get_book_author(title: str) -> str: + """Returns the author of the book with the given title + + Args: + title: The title of the book. + """ + if title == "The Name of the Wind": + return "Patrick Rothfuss" + elif title == "Mistborn: The Final Empire": + return "Brandon Sanderson" + else: + return "Unknown" + + +@vertex.call( + "gemini-1.5-flash", + tools=[get_book_author], + stream={"partial_tools": True}, +) +@prompt_template("Who wrote {book}?") +def identify_authors(books: list[str]): ... + + +stream = identify_authors(["The Name of the Wind", "Mistborn: The Final Empire"]) +for chunk, tool in stream: + if tool: # will always be None, not supported at the provider level + if tool.delta is not None: # partial tool + print(tool.delta) + else: + print(tool.call()) + else: + print(chunk.content, end="", flush=True) From d4daee171d75455b93689dd4fc8dba90cd088601 Mon Sep 17 00:00:00 2001 From: William Bakst Date: Wed, 27 Nov 2024 22:55:18 -0800 Subject: [PATCH 2/2] docs: add rss feed plugin --- mkdocs.yml | 6 ++++ pyproject.toml | 1 + uv.lock | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+) diff --git a/mkdocs.yml b/mkdocs.yml index ce7162eaf..34acb4bdb 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -122,6 +122,12 @@ plugins: - Tips & Inspiration - Behind the Scenes - Library Updates + - rss: + match_path: blog/posts/.* + date_from_meta: + as_creation: date + categories: + - categories - macros: module_name: docs/macros - mkdocs-jupyter: diff --git a/pyproject.toml b/pyproject.toml index 272be9b80..ce936bdad 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -119,6 +119,7 @@ dev-dependencies = [ "pillow>=10.4.0", "notebook>=7.2.2", "nbconvert>=7.16.4", + "mkdocs-rss-plugin>=1.16.0", ] [tool.uv.sources] diff --git a/uv.lock b/uv.lock index 4d9f33a8e..9f602fd4e 100644 --- a/uv.lock +++ b/uv.lock @@ -591,6 +591,24 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/84/c2/80633736cd183ee4a62107413def345f7e6e3c01563dbca1417363cf957e/build-1.2.2.post1-py3-none-any.whl", hash = "sha256:1d61c0887fa860c01971625baae8bdd338e517b836a2f70dd1f7aa3a6b2fc5b5", size = 22950 }, ] +[[package]] +name = "cachecontrol" +version = "0.14.1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "msgpack" }, + { name = "requests" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/d2/23/db12e0b6b241e33f77f7cce01a06b4cc6f8071728656cc0ea262d2a14dad/cachecontrol-0.14.1.tar.gz", hash = "sha256:06ef916a1e4eb7dba9948cdfc9c76e749db2e02104a9a1277e8b642591a0f717", size = 28928 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/f1/aa/481eb52af52aae093c61c181f2308779973ffd6f0f5f6c0881b2138f3087/cachecontrol-0.14.1-py3-none-any.whl", hash = "sha256:65e3abd62b06382ce3894df60dde9e0deb92aeb734724f68fa4f3b91e97206b9", size = 22085 }, +] + +[package.optional-dependencies] +filecache = [ + { name = "filelock" }, +] + [[package]] name = "cachetools" version = "5.5.0" @@ -3223,6 +3241,7 @@ dev = [ { name = "mkdocs-jupyter" }, { name = "mkdocs-macros-plugin" }, { name = "mkdocs-material", extra = ["imaging"] }, + { name = "mkdocs-rss-plugin" }, { name = "mkdocstrings" }, { name = "mkdocstrings-python" }, { name = "nbconvert" }, @@ -3293,6 +3312,7 @@ dev = [ { name = "mkdocs-jupyter", specifier = ">=0.25.0" }, { name = "mkdocs-macros-plugin", specifier = ">=1.2.0" }, { name = "mkdocs-material", extras = ["imaging"], specifier = ">=9.5.32" }, + { name = "mkdocs-rss-plugin", specifier = ">=1.16.0" }, { name = "mkdocstrings", specifier = ">=0.25.2" }, { name = "mkdocstrings-python", specifier = ">=1.10.8" }, { name = "nbconvert", specifier = ">=7.16.4" }, @@ -3472,6 +3492,22 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/5b/54/662a4743aa81d9582ee9339d4ffa3c8fd40a4965e033d77b9da9774d3960/mkdocs_material_extensions-1.3.1-py3-none-any.whl", hash = "sha256:adff8b62700b25cb77b53358dad940f3ef973dd6db797907c49e3c2ef3ab4e31", size = 8728 }, ] +[[package]] +name = "mkdocs-rss-plugin" +version = "1.16.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cachecontrol", extra = ["filecache"] }, + { name = "gitpython" }, + { name = "mkdocs" }, + { name = "requests" }, + { name = "tzdata", marker = "sys_platform == 'win32'" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/c2/ac/52972ec3b0ee26253b263741dc65ba5d68c67d28ecfe8ef61555e4d9f985/mkdocs_rss_plugin-1.16.0.tar.gz", hash = "sha256:f0e275c933be69a77ee7af92256d88e2969e10c36c5ee1ecdb663a4ea4aa08ea", size = 32673 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a1/82/c588e0d880431f6e89375aa6994ba12ff4d62972441d3c66c63ae8d940ee/mkdocs_rss_plugin-1.16.0-py2.py3-none-any.whl", hash = "sha256:be66b11300f1e951d3393ce8da60ca6d730108f731434cc256670b3b8e0cffb3", size = 27062 }, +] + [[package]] name = "mkdocstrings" version = "0.25.2" @@ -3681,6 +3717,58 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/2c/69/314d887a01599669fb330da14e5c6ff5f138609e322812a942a74ef9b765/msal_extensions-1.2.0-py3-none-any.whl", hash = "sha256:cf5ba83a2113fa6dc011a254a72f1c223c88d7dfad74cc30617c4679a417704d", size = 19254 }, ] +[[package]] +name = "msgpack" +version = "1.1.0" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/cb/d0/7555686ae7ff5731205df1012ede15dd9d927f6227ea151e901c7406af4f/msgpack-1.1.0.tar.gz", hash = "sha256:dd432ccc2c72b914e4cb77afce64aab761c1137cc698be3984eee260bcb2896e", size = 167260 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/4b/f9/a892a6038c861fa849b11a2bb0502c07bc698ab6ea53359e5771397d883b/msgpack-1.1.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:7ad442d527a7e358a469faf43fda45aaf4ac3249c8310a82f0ccff9164e5dccd", size = 150428 }, + { url = "https://files.pythonhosted.org/packages/df/7a/d174cc6a3b6bb85556e6a046d3193294a92f9a8e583cdbd46dc8a1d7e7f4/msgpack-1.1.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:74bed8f63f8f14d75eec75cf3d04ad581da6b914001b474a5d3cd3372c8cc27d", size = 84131 }, + { url = "https://files.pythonhosted.org/packages/08/52/bf4fbf72f897a23a56b822997a72c16de07d8d56d7bf273242f884055682/msgpack-1.1.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:914571a2a5b4e7606997e169f64ce53a8b1e06f2cf2c3a7273aa106236d43dd5", size = 81215 }, + { url = "https://files.pythonhosted.org/packages/02/95/dc0044b439b518236aaf012da4677c1b8183ce388411ad1b1e63c32d8979/msgpack-1.1.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:c921af52214dcbb75e6bdf6a661b23c3e6417f00c603dd2070bccb5c3ef499f5", size = 371229 }, + { url = "https://files.pythonhosted.org/packages/ff/75/09081792db60470bef19d9c2be89f024d366b1e1973c197bb59e6aabc647/msgpack-1.1.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d8ce0b22b890be5d252de90d0e0d119f363012027cf256185fc3d474c44b1b9e", size = 378034 }, + { url = "https://files.pythonhosted.org/packages/32/d3/c152e0c55fead87dd948d4b29879b0f14feeeec92ef1fd2ec21b107c3f49/msgpack-1.1.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:73322a6cc57fcee3c0c57c4463d828e9428275fb85a27aa2aa1a92fdc42afd7b", size = 363070 }, + { url = "https://files.pythonhosted.org/packages/d9/2c/82e73506dd55f9e43ac8aa007c9dd088c6f0de2aa19e8f7330e6a65879fc/msgpack-1.1.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:e1f3c3d21f7cf67bcf2da8e494d30a75e4cf60041d98b3f79875afb5b96f3a3f", size = 359863 }, + { url = "https://files.pythonhosted.org/packages/cb/a0/3d093b248837094220e1edc9ec4337de3443b1cfeeb6e0896af8ccc4cc7a/msgpack-1.1.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:64fc9068d701233effd61b19efb1485587560b66fe57b3e50d29c5d78e7fef68", size = 368166 }, + { url = "https://files.pythonhosted.org/packages/e4/13/7646f14f06838b406cf5a6ddbb7e8dc78b4996d891ab3b93c33d1ccc8678/msgpack-1.1.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:42f754515e0f683f9c79210a5d1cad631ec3d06cea5172214d2176a42e67e19b", size = 370105 }, + { url = "https://files.pythonhosted.org/packages/67/fa/dbbd2443e4578e165192dabbc6a22c0812cda2649261b1264ff515f19f15/msgpack-1.1.0-cp310-cp310-win32.whl", hash = "sha256:3df7e6b05571b3814361e8464f9304c42d2196808e0119f55d0d3e62cd5ea044", size = 68513 }, + { url = "https://files.pythonhosted.org/packages/24/ce/c2c8fbf0ded750cb63cbcbb61bc1f2dfd69e16dca30a8af8ba80ec182dcd/msgpack-1.1.0-cp310-cp310-win_amd64.whl", hash = "sha256:685ec345eefc757a7c8af44a3032734a739f8c45d1b0ac45efc5d8977aa4720f", size = 74687 }, + { url = "https://files.pythonhosted.org/packages/b7/5e/a4c7154ba65d93be91f2f1e55f90e76c5f91ccadc7efc4341e6f04c8647f/msgpack-1.1.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:3d364a55082fb2a7416f6c63ae383fbd903adb5a6cf78c5b96cc6316dc1cedc7", size = 150803 }, + { url = "https://files.pythonhosted.org/packages/60/c2/687684164698f1d51c41778c838d854965dd284a4b9d3a44beba9265c931/msgpack-1.1.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:79ec007767b9b56860e0372085f8504db5d06bd6a327a335449508bbee9648fa", size = 84343 }, + { url = "https://files.pythonhosted.org/packages/42/ae/d3adea9bb4a1342763556078b5765e666f8fdf242e00f3f6657380920972/msgpack-1.1.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:6ad622bf7756d5a497d5b6836e7fc3752e2dd6f4c648e24b1803f6048596f701", size = 81408 }, + { url = "https://files.pythonhosted.org/packages/dc/17/6313325a6ff40ce9c3207293aee3ba50104aed6c2c1559d20d09e5c1ff54/msgpack-1.1.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8e59bca908d9ca0de3dc8684f21ebf9a690fe47b6be93236eb40b99af28b6ea6", size = 396096 }, + { url = "https://files.pythonhosted.org/packages/a8/a1/ad7b84b91ab5a324e707f4c9761633e357820b011a01e34ce658c1dda7cc/msgpack-1.1.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5e1da8f11a3dd397f0a32c76165cf0c4eb95b31013a94f6ecc0b280c05c91b59", size = 403671 }, + { url = "https://files.pythonhosted.org/packages/bb/0b/fd5b7c0b308bbf1831df0ca04ec76fe2f5bf6319833646b0a4bd5e9dc76d/msgpack-1.1.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:452aff037287acb1d70a804ffd022b21fa2bb7c46bee884dbc864cc9024128a0", size = 387414 }, + { url = "https://files.pythonhosted.org/packages/f0/03/ff8233b7c6e9929a1f5da3c7860eccd847e2523ca2de0d8ef4878d354cfa/msgpack-1.1.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:8da4bf6d54ceed70e8861f833f83ce0814a2b72102e890cbdfe4b34764cdd66e", size = 383759 }, + { url = "https://files.pythonhosted.org/packages/1f/1b/eb82e1fed5a16dddd9bc75f0854b6e2fe86c0259c4353666d7fab37d39f4/msgpack-1.1.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:41c991beebf175faf352fb940bf2af9ad1fb77fd25f38d9142053914947cdbf6", size = 394405 }, + { url = "https://files.pythonhosted.org/packages/90/2e/962c6004e373d54ecf33d695fb1402f99b51832631e37c49273cc564ffc5/msgpack-1.1.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:a52a1f3a5af7ba1c9ace055b659189f6c669cf3657095b50f9602af3a3ba0fe5", size = 396041 }, + { url = "https://files.pythonhosted.org/packages/f8/20/6e03342f629474414860c48aeffcc2f7f50ddaf351d95f20c3f1c67399a8/msgpack-1.1.0-cp311-cp311-win32.whl", hash = "sha256:58638690ebd0a06427c5fe1a227bb6b8b9fdc2bd07701bec13c2335c82131a88", size = 68538 }, + { url = "https://files.pythonhosted.org/packages/aa/c4/5a582fc9a87991a3e6f6800e9bb2f3c82972912235eb9539954f3e9997c7/msgpack-1.1.0-cp311-cp311-win_amd64.whl", hash = "sha256:fd2906780f25c8ed5d7b323379f6138524ba793428db5d0e9d226d3fa6aa1788", size = 74871 }, + { url = "https://files.pythonhosted.org/packages/e1/d6/716b7ca1dbde63290d2973d22bbef1b5032ca634c3ff4384a958ec3f093a/msgpack-1.1.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:d46cf9e3705ea9485687aa4001a76e44748b609d260af21c4ceea7f2212a501d", size = 152421 }, + { url = "https://files.pythonhosted.org/packages/70/da/5312b067f6773429cec2f8f08b021c06af416bba340c912c2ec778539ed6/msgpack-1.1.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:5dbad74103df937e1325cc4bfeaf57713be0b4f15e1c2da43ccdd836393e2ea2", size = 85277 }, + { url = "https://files.pythonhosted.org/packages/28/51/da7f3ae4462e8bb98af0d5bdf2707f1b8c65a0d4f496e46b6afb06cbc286/msgpack-1.1.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:58dfc47f8b102da61e8949708b3eafc3504509a5728f8b4ddef84bd9e16ad420", size = 82222 }, + { url = "https://files.pythonhosted.org/packages/33/af/dc95c4b2a49cff17ce47611ca9ba218198806cad7796c0b01d1e332c86bb/msgpack-1.1.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4676e5be1b472909b2ee6356ff425ebedf5142427842aa06b4dfd5117d1ca8a2", size = 392971 }, + { url = "https://files.pythonhosted.org/packages/f1/54/65af8de681fa8255402c80eda2a501ba467921d5a7a028c9c22a2c2eedb5/msgpack-1.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:17fb65dd0bec285907f68b15734a993ad3fc94332b5bb21b0435846228de1f39", size = 401403 }, + { url = "https://files.pythonhosted.org/packages/97/8c/e333690777bd33919ab7024269dc3c41c76ef5137b211d776fbb404bfead/msgpack-1.1.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:a51abd48c6d8ac89e0cfd4fe177c61481aca2d5e7ba42044fd218cfd8ea9899f", size = 385356 }, + { url = "https://files.pythonhosted.org/packages/57/52/406795ba478dc1c890559dd4e89280fa86506608a28ccf3a72fbf45df9f5/msgpack-1.1.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:2137773500afa5494a61b1208619e3871f75f27b03bcfca7b3a7023284140247", size = 383028 }, + { url = "https://files.pythonhosted.org/packages/e7/69/053b6549bf90a3acadcd8232eae03e2fefc87f066a5b9fbb37e2e608859f/msgpack-1.1.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:398b713459fea610861c8a7b62a6fec1882759f308ae0795b5413ff6a160cf3c", size = 391100 }, + { url = "https://files.pythonhosted.org/packages/23/f0/d4101d4da054f04274995ddc4086c2715d9b93111eb9ed49686c0f7ccc8a/msgpack-1.1.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:06f5fd2f6bb2a7914922d935d3b8bb4a7fff3a9a91cfce6d06c13bc42bec975b", size = 394254 }, + { url = "https://files.pythonhosted.org/packages/1c/12/cf07458f35d0d775ff3a2dc5559fa2e1fcd06c46f1ef510e594ebefdca01/msgpack-1.1.0-cp312-cp312-win32.whl", hash = "sha256:ad33e8400e4ec17ba782f7b9cf868977d867ed784a1f5f2ab46e7ba53b6e1e1b", size = 69085 }, + { url = "https://files.pythonhosted.org/packages/73/80/2708a4641f7d553a63bc934a3eb7214806b5b39d200133ca7f7afb0a53e8/msgpack-1.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:115a7af8ee9e8cddc10f87636767857e7e3717b7a2e97379dc2054712693e90f", size = 75347 }, + { url = "https://files.pythonhosted.org/packages/c8/b0/380f5f639543a4ac413e969109978feb1f3c66e931068f91ab6ab0f8be00/msgpack-1.1.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:071603e2f0771c45ad9bc65719291c568d4edf120b44eb36324dcb02a13bfddf", size = 151142 }, + { url = "https://files.pythonhosted.org/packages/c8/ee/be57e9702400a6cb2606883d55b05784fada898dfc7fd12608ab1fdb054e/msgpack-1.1.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:0f92a83b84e7c0749e3f12821949d79485971f087604178026085f60ce109330", size = 84523 }, + { url = "https://files.pythonhosted.org/packages/7e/3a/2919f63acca3c119565449681ad08a2f84b2171ddfcff1dba6959db2cceb/msgpack-1.1.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:4a1964df7b81285d00a84da4e70cb1383f2e665e0f1f2a7027e683956d04b734", size = 81556 }, + { url = "https://files.pythonhosted.org/packages/7c/43/a11113d9e5c1498c145a8925768ea2d5fce7cbab15c99cda655aa09947ed/msgpack-1.1.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:59caf6a4ed0d164055ccff8fe31eddc0ebc07cf7326a2aaa0dbf7a4001cd823e", size = 392105 }, + { url = "https://files.pythonhosted.org/packages/2d/7b/2c1d74ca6c94f70a1add74a8393a0138172207dc5de6fc6269483519d048/msgpack-1.1.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0907e1a7119b337971a689153665764adc34e89175f9a34793307d9def08e6ca", size = 399979 }, + { url = "https://files.pythonhosted.org/packages/82/8c/cf64ae518c7b8efc763ca1f1348a96f0e37150061e777a8ea5430b413a74/msgpack-1.1.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:65553c9b6da8166e819a6aa90ad15288599b340f91d18f60b2061f402b9a4915", size = 383816 }, + { url = "https://files.pythonhosted.org/packages/69/86/a847ef7a0f5ef3fa94ae20f52a4cacf596a4e4a010197fbcc27744eb9a83/msgpack-1.1.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:7a946a8992941fea80ed4beae6bff74ffd7ee129a90b4dd5cf9c476a30e9708d", size = 380973 }, + { url = "https://files.pythonhosted.org/packages/aa/90/c74cf6e1126faa93185d3b830ee97246ecc4fe12cf9d2d31318ee4246994/msgpack-1.1.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:4b51405e36e075193bc051315dbf29168d6141ae2500ba8cd80a522964e31434", size = 387435 }, + { url = "https://files.pythonhosted.org/packages/7a/40/631c238f1f338eb09f4acb0f34ab5862c4e9d7eda11c1b685471a4c5ea37/msgpack-1.1.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:b4c01941fd2ff87c2a934ee6055bda4ed353a7846b8d4f341c428109e9fcde8c", size = 399082 }, + { url = "https://files.pythonhosted.org/packages/e9/1b/fa8a952be252a1555ed39f97c06778e3aeb9123aa4cccc0fd2acd0b4e315/msgpack-1.1.0-cp313-cp313-win32.whl", hash = "sha256:7c9a35ce2c2573bada929e0b7b3576de647b0defbd25f5139dcdaba0ae35a4cc", size = 69037 }, + { url = "https://files.pythonhosted.org/packages/b6/bc/8bd826dd03e022153bfa1766dcdec4976d6c818865ed54223d71f07862b3/msgpack-1.1.0-cp313-cp313-win_amd64.whl", hash = "sha256:bce7d9e614a04d0883af0b3d4d501171fbfca038f12c77fa838d9f198147a23f", size = 75140 }, +] + [[package]] name = "multidict" version = "6.0.5"