Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always getting the error: "AssertionError exception: no description" #108

Closed
jondoescoding opened this issue Jan 7, 2025 · 5 comments
Closed

Comments

@jondoescoding
Copy link

jondoescoding commented Jan 7, 2025

No matter what I do to modify the docstring I always get the same error as mentioned in the title.

Here is a tool that I have created.

I would like to know what within my docstrings is causing this.

cg = CoinGeckoAPI(demo_api_key=os.getenv('coingecko_api_key'))

@tool
def get_coins_list(currency: str) -> list:
    """
    This tool makes a query to the CoinGecko API to get a response of ALL of the supported coins with their price, market cap, volume and related market data in USD.

    Args:
        currency: The dollar value which the coin should be represented into
    """
    return cg.get_coins_markets(vs_currency=currency)
@jondoescoding jondoescoding changed the title Exception has occurred: AssertionError exception: no description Always getting the error: "AssertionError exception: no description" Jan 7, 2025
@whoahaow
Copy link

whoahaow commented Jan 7, 2025

does it fix it?

cg = CoinGeckoAPI(api_key=os.getenv('coingecko_api_key'))

class GetCoinsListTool(Tool):
    name = "get_coins_list"
    description = """
    This tool makes a query to the CoinGecko API to get a response of ALL of the supported coins with their price, market cap, volume and related market data in USD.
    """
    inputs = {
        "currency": {
            "type": "string",
            "description": "The currency in which the coin data should be represented (e.g., 'usd', 'eur')."
        }
    }
    output_type = "list"

    def forward(self, currency: str) -> list:
        return cg.get_coins_markets(vs_currency=currency)

@jondoescoding
Copy link
Author

Got the same error.

Exception has occurred: AssertionError
exception: no description

Exception has occurred: AssertionError
exception: no description
  File "...\coingecko_agent\agent.py", line 7, in <module>
    coin_list_tool = GetCoinsListTool()
                     ^^^^^^^^^^^^^^^^^^
AssertionError: 

@whoahaow
Copy link

whoahaow commented Jan 7, 2025

I don't know if this is suitable for you, but here's what I did:

from smolagents import CodeAgent, HfApiModel, Tool
import os
from pycoingecko import CoinGeckoAPI
import json

# Initialize CoinGecko API client
cg = CoinGeckoAPI(api_key=os.getenv('coingecko_api_key'))

# Define the GetCoinsListTool class
class GetCoinsListTool(Tool):
    name = "get_coins_list"
    description = """
    This tool makes a query to the CoinGecko API to get a response of ALL of the supported coins with their price, market cap, volume and related market data in USD.
    You need to import json. The output is a JSON string. You should use the `json` module to parse this string into a Python list.
    """
    inputs = {
        "currency": {
            "type": "string",
            "description": "The currency in which the coin data should be represented (e.g., 'usd', 'eur')."
        }
    }
    output_type = "string"  # Change to 'string'

    def forward(self, currency: str) -> str:
        coins_data = cg.get_coins_markets(vs_currency=currency)
        return json.dumps(coins_data)  # Convert the list to a JSON string

# Initialize the model
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")

# Initialize the agent with the tool
agent = CodeAgent(
    tools=[GetCoinsListTool()],
    model=model,
    add_base_tools=True,
    additional_authorized_imports=["json"]  # Authorize the json module
)

# Run the agent with a task
task = "Get the list of coins in USD and print the first 5 entries. Then present it as usual text."
result = agent.run(task)

# Print the result
print("Agent Output:")
print(result)

@jondoescoding
Copy link
Author

Works like a charm. Thanks! But why does the the @tool decorator not work?

@aymeric-roucher
Copy link
Collaborator

@jondoescoding could you provide your full error trace and package versions? I tried to reproduce but for me your code snippet works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants