From df893881472e6e617faba1f843acc92c37eb91a1 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Thu, 26 Dec 2024 12:32:23 +0100 Subject: [PATCH] Fix tool forward args with defaults but no type hint --- docs/source/conceptual_guides/intro_agents.md | 2 +- docs/source/examples/text_to_sql.md | 6 +++--- pyproject.toml | 1 + src/smolagents/tools.py | 4 ++++ 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/source/conceptual_guides/intro_agents.md b/docs/source/conceptual_guides/intro_agents.md index cf066de..0a1434f 100644 --- a/docs/source/conceptual_guides/intro_agents.md +++ b/docs/source/conceptual_guides/intro_agents.md @@ -112,4 +112,4 @@ This is illustrated on the figure below, taken from [Executable Code Actions Eli -This is why we put emphasis on proposing code agents, in this case python agents, which meant putting higher effort on building secure python interpreters. \ No newline at end of file +This is why we put emphasis on proposing code agents, in this case python agents, which meant building secure python interpreters. \ No newline at end of file diff --git a/docs/source/examples/text_to_sql.md b/docs/source/examples/text_to_sql.md index b71cc6c..fd3290f 100644 --- a/docs/source/examples/text_to_sql.md +++ b/docs/source/examples/text_to_sql.md @@ -19,7 +19,7 @@ rendered properly in your Markdown viewer. In this tutorial, we’ll see how to implement an agent that leverages SQL using `smolagents`. -> Let's start with the goldnen question: why not keep it simple and use a standard text-to-SQL pipeline? +> Let's start with the golden question: why not keep it simple and use a standard text-to-SQL pipeline? A standard text-to-sql pipeline is brittle, since the generated SQL query can be incorrect. Even worse, the query could be incorrect, but not raise an error, instead giving some incorrect/useless outputs without raising an alarm. @@ -27,7 +27,7 @@ A standard text-to-sql pipeline is brittle, since the generated SQL query can be Let’s build this agent! 💪 -### Setup text to SQL +First, we setup the SQL environment: ```py from sqlalchemy import ( create_engine, @@ -73,7 +73,7 @@ for row in rows: Now let’s make our SQL table retrievable by a tool. -The tool’s description attribute will be embedded in the LLM’s prompt by the agent system: it gives the LLM information about how to use the tool. So that is where we want to describe the SQL table. +The tool’s description attribute will be embedded in the LLM’s prompt by the agent system: it gives the LLM information about how to use the tool. This is where we want to describe the SQL table. ```py inspector = inspect(engine) diff --git a/pyproject.toml b/pyproject.toml index 2ffb4ef..6b50bbc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ dependencies = [ "pandas>=2.2.3", "jinja2>=3.1.4", "pillow>=11.0.0", + "llama-cpp-python>=0.3.4", "markdownify>=0.14.1", "gradio>=5.8.0", "duckduckgo-search>=6.3.7", diff --git a/src/smolagents/tools.py b/src/smolagents/tools.py index ad633ef..fd39933 100644 --- a/src/smolagents/tools.py +++ b/src/smolagents/tools.py @@ -117,6 +117,10 @@ def _convert_type_hints_to_json_schema(func: Callable) -> Dict: properties[param_name] = _parse_type_hint(param_type) if signature.parameters[param_name].default != inspect.Parameter.empty: properties[param_name]["nullable"] = True + for param_name in signature.parameters.keys(): + if signature.parameters[param_name].default != inspect.Parameter.empty: + if param_name not in properties: # this can happen if the param has no type hint but a default value + properties[param_name] = {"nullable": True} return properties AUTHORIZED_TYPES = [