Ai Agents course error in running the Smolagent example

Hello, following unit 1, in the AI agent course, running the given application built in smolagent below. The question is time in EST now?

Any ideas? what am I missing here.

Final answer:
Error in generating final LLM output:
422 Client Error: Unprocessable Entity for url: https://api-inference.huggingface.co/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Zji2Dy1jhRHQ_jjXJLqQx)

Input validation error: inputs tokens + max_new_tokens must be <= 32768. Given: 89942 inputs tokens and 2096 max_new_tokens
Make sure ‘text-generation’ task is supported by the model.

1 Like

Input validation error: inputs tokens + max_new_tokens must be <= 32768. Given: 89942 inputs tokens and 2096 max_new_tokens

The error message says that the input tokens are too large and exceed 32768 (-2096), so it can’t be processed, but if this is the result of following the course, then it’s a bug in the course in a broad sense…
If possible, why not try changing the model?
Or raising issue?

I am having issues while running the agents using HfApiModel(). Following is the syntax and the error:
from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel

Initialize the search tool

search_tool = DuckDuckGoSearchTool()

Initialize the model

model = HfApiModel(hf_model)

agent = CodeAgent(
model = model,
tools=[search_tool]
)

Example usage

response = agent.run(
“Search for luxury superhero-themed party ideas, including decorations, entertainment, and catering.”
)
print(response)

Error in generating model output:
402 Client Error: Payment Required for url:
https://router.huggingface.co/hf-inference/models/Qwen/QwQ-32B/v1/chat/completions (Request ID:
Root=1-67eb90ed-4dceeaaf55ae88031ef4b296;dc2390e1-cf09-4f27-b530-c55bff8d2db7)

You have exceeded your monthly included credits for Inference Providers. Subscribe to PRO to get 20x more monthly
included credits.

I know that it is asking for upgrading HF subscription, but is there any way I can use it for free? I am a beginner at HF

1 Like

That’s just a simple case of exceeding the usage limit, so it’s a bit difficult, but I think you could get around it by using a local model or using another company’s API.

The only way I got around this was upgrading my HF account. I know that’s not the ideal solution, and not something that should be the easiest path forward, but I guess you can downgrade your account after the course is completed.

1 Like

Yes, most of the errors disappeared once I upgraded my account. Looks like a capacity issue ( Token counts aren’t being properly returned from the model API).

Although, I did make some changes to the Gradio_UI.py file to resolve some Type issues - similar to the below

Before

total_input_tokens += agent.model.last_input_token_count

After (add safety check)

token_count = agent.model.last_input_token_count or 0
total_input_tokens += token_count


Original line (line 115)

f" | Input-tokens:{step_log.input_token_count:,} | Output-tokens:{step_log.output_token_count:,}"

Fixed version - add None handling

f" | Input-tokens:{step_log.input_token_count or 0:,} | Output-tokens:{step_log.output_token_count or 0:,}"

1 Like

"Error in generating model output:
401 Client Error: Unauthorized for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Root=1-680a7e9b-5c2059aa6ca44bed59bec0bc;6c8ff9c7-6358-4d3f-bf84-f596010c2321)

Invalid username or password. Error generating answer"

How to fix this error ?

1 Like

updated the requirements file with smolagents


still same error

1 Like

Fixed the previous problem,
Now

"Error in generating model output:
401 Client Error: Unauthorized for url: https://router.huggingface.co/hf-inference/models/Qwen/Qwen2.5-Coder-32B-Instruct/v1/chat/completions (Request ID: Root=1-680a7e9b-5c2059aa6ca44bed59bec0bc;6c8ff9c7-6358-4d3f-bf84-f596010c2321)

Invalid username or password."

How to fix this error ?

1 Like

Invalid username or password."

Based on this error message, it is possible that the token content is incorrect or that the token you are passing is different from the token that is actually being passed.

The most reliable method is to use login(), but in many cases, the issue can be resolved by configuring the HF_TOKEN environment variable (Secrets).