rom smolagents import HfApiModel, CodeAgent
from helper import get_huggingface_token
model = HfApiModel(
"HuggingFaceTB/SmolLM-135M-Instruct",
provider="novita", # Choose a specific inference provider
max_tokens=4096,
temperature=0.1
)
After setting the above up I am getting the following error:
AgentGenerationError: Error in generating model output:
Model HuggingFaceTB/SmolLM-135M-Instruct is not supported by provider novita.
How do I correct it?
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Based on the error message, it seems that the Hugging Face model "HuggingFaceTB/SmolLM-135M-Instruct" is not supported by the Novita inference provider. Here are a few potential solutions:
Check Provider Compatibility:
Verify which models are actually supported by the Novita provider
You may need to choose a different model that is compatible with Novita
Alternative Providers:
Try using a different inference provider that supports this specific model
Common providers include OpenAI, Anthropic, HuggingFace's own inference API, etc.
Direct Troubleshooting Steps:
python
# Option 1: Verify the exact model name
model = HfApiModel(
"HuggingFaceTB/SmolLM-135M-Instruct", # Double-check this exact model name
provider="huggingface", # Try the default HuggingFace provider
max_tokens=4096,
temperature=0.1
)
# Option 2: Use a more generic provider setting
model = HfApiModel(
"HuggingFaceTB/SmolLM-135M-Instruct",
provider=None, # Let the system auto-select
max_tokens=4096,
temperature=0.1
)
Debugging Recommendations:
Confirm the exact model name with the Hugging Face model repository
Check the documentation for the SmolAgents library and Novita provider
Verify your Hugging Face token is correctly configured
Would you like me to help you investigate further? Could you provide more context about the SmolAgents library and the specific setup you're using?
User
I tried "huggingface" as provider and got this:
AgentGenerationError: Error in generating model output:
Provider 'huggingface' not supported. Available providers: ['black-forest-labs', 'cerebras', 'cohere', 'fal-ai', 'fireworks-ai', 'hf-inference', 'hyperbolic', 'nebius', 'novita', 'openai', 'replicate', 'sambanova', 'together']
Assistant
Based on the error message, it looks like "huggingface" is not a valid provider. Instead, you should use "hf-inference" from the list of available providers. Here's the corrected code:
python
from smolagents import HfApiModel, CodeAgent
from helper import get_huggingface_token
model = HfApiModel(
"HuggingFaceTB/SmolLM-135M-Instruct",
provider="hf-inference", # Use "hf-inference" from the list
max_tokens=4096,
temperature=0.1
)
The key changes:
Replace "huggingface" with "hf-inference"
This matches the provider name from the list of supported providers
Make sure you have:
A valid Hugging Face token configured
The correct model name
The latest version of the SmolAgents library
If you continue to have issues, could you confirm:
The exact version of SmolAgents you're using
That the model "HuggingFaceTB/SmolLM-135M-Instruct" exists on Hugging Face
Potential configuration problem with the inference endpoint
Here are some troubleshooting steps:
Verify Hugging Face Token:
python
# Ensure your token has read and inference permissions
token = get_huggingface_token()
# Double-check the token is correctly retrieved and has proper scope
The exact model name "HuggingFaceTB/SmolLM-135M-Instruct" exists
The model is publicly accessible
The model supports chat/inference endpoints
Alternative Model Selection:
python
# Try a known, widely accessible model
model = HfApiModel(
"meta-llama/Llama-2-7b-chat-hf", # Or another well-known model
provider="hf-inference",
max_tokens=4096,
temperature=0.1
)
data_description = """Suppliers have an additional tasting fee: that is a fixed fee applied to each order to taste the ice cream."""
suppliers_df = pd.DataFrame(suppliers_data)
suppliers_df
@tool
def calculate_transport_cost(distance_km: float, order_volume: float) -> float:
"""
Calculate transportation cost based on distance and order size.
Refrigerated transport costs $1.2 per kilometer and has a capacity of 300 liters.
code
Args:
distance_km: the distance in kilometers
order_volume: the order volume in liters
"""
trucks_needed = np.ceil(order_volume / 300)
cost_per_km = 1.20
return distance_km * cost_per_km * trucks_needed
Assistant
I'll help you recreate this agentic task locally. Here's a step-by-step implementation:
@tool
def calculate_tariff(base_cost: float, is_canadian: bool) -> float:
"""
Calculates tariff for Canadian imports. Returns the tariff only, not the total cost.
Assumes tariff on dairy products from Canada is worth 2 * pi / 100, approx 6.2%
code
Args:
base_cost: the base cost of goods, not including transportation cost.
is_canadian: wether the import is from Canada.
"""
if is_canadian:
return base_cost * np.pi / 50
return 0
===============
from smolagents import HfApiModel, CodeAgent
from helper import get_huggingface_token
model = HfApiModel(
"HuggingFaceTB/SmolLM-135M-Instruct",
provider="hf-inference", # Choose a specific inference provider
max_tokens=4096,
temperature=0.1
)
agent.run(
"""Can you get me the transportation cost for 50 liters
of ice cream over 10 kilometers?"""
)
task = """Here is a dataframe of different ice cream suppliers.
Could you give me a comparative table (as a dataframe) of the total
daily price for getting daily ice cream delivery from each of them,
given that we need exactly 30 liters of ice cream per day? Take
into account transportation cost and tariffs.
"""
agent.logger.level = 1 # Lower verbosity level
agent.run(
task,
additional_args={"suppliers_data": suppliers_df, "data_description": data_description},
)
Now please help me recreate this simple agentic task above for my local development (I am on Ubuntu 22.04) for the following LLM:
HuggingFaceTB/SmolLM2-360M-Instruct
import os
import numpy as np
import pandas as pd
from dotenv import load_dotenv
from huggingface_hub import login
from smolagents import tool, HfApiModel, CodeAgent
# Load environment variables
load_dotenv()
# Login to Hugging Face (optional, but recommended)
login(os.environ.get('HF_API_KEY', ''))
# Supplier Data
suppliers_data = {
"name": [
"Montreal Ice Cream Co",
"Brain Freeze Brothers",
"Toronto Gelato Ltd",
"Buffalo Scoops",
"Vermont Creamery",
],
"location": [
"Montreal, QC",
"Burlington, VT",
"Toronto, ON",
"Buffalo, NY",
"Portland, ME",
],
"distance_km": [120, 85, 400, 220, 280],
"canadian": [True, False, True, False, False],
"price_per_liter": [1.95, 1.91, 1.82, 2.43, 2.33],
"tasting_fee": [0, 12.50, 30.14, 42.00, 0.20],
}
data_description = """Suppliers have an additional tasting fee: that is a fixed fee applied to each order to taste the ice cream."""
suppliers_df = pd.DataFrame(suppliers_data)
# Tools
@tool
def calculate_transport_cost(distance_km: float, order_volume: float) -> float:
"""
Calculate transportation cost based on distance and order size.
Refrigerated transport costs $1.2 per kilometer and has a capacity of 300 liters.
Args:
distance_km: the distance in kilometers
order_volume: the order volume in liters
"""
trucks_needed = np.ceil(order_volume / 300)
cost_per_km = 1.20
return distance_km * cost_per_km * trucks_needed
@tool
def calculate_tariff(base_cost: float, is_canadian: bool) -> float:
"""
Calculates tariff for Canadian imports. Returns the tariff only, not the total cost.
Assumes tariff on dairy products from Canada is worth 2 * pi / 100, approx 6.2%
Args:
base_cost: the base cost of goods, not including transportation cost.
is_canadian: whether the import is from Canada.
"""
if is_canadian:
return base_cost * np.pi / 50
return 0
# Set up the model
model = HfApiModel(
"HuggingFaceTB/SmolLM2-360M-Instruct",
provider="hf-inference",
max_tokens=4096,
temperature=0.1
)
# Create the agent
agent = CodeAgent(
model=model,
tools=[calculate_transport_cost, calculate_tariff],
max_steps=10,
additional_authorized_imports=["pandas", "numpy"],
verbosity_level=2
)
# Define the task
task = """Here is a dataframe of different ice cream suppliers.
Could you give me a comparative table (as a dataframe) of the total
daily price for getting daily ice cream delivery from each of them,
given that we need exactly 30 liters of ice cream per day? Take
into account transportation cost and tariffs.
"""
# Run the agent
result = agent.run(
task,
additional_args={"suppliers_data": suppliers_df, "data_description": data_description}
)
# Print the result
print(result)
Create a .env file in the same directory:
code
HF_API_KEY=your_hugging_face_api_key_here
Important Notes:
Replace your_hugging_face_api_key_here with your actual Hugging Face API key
You can get an API key by creating an account at huggingface.co
If you don't have an API key, you might need to use a different provider or model
Potential Modifications:
If you encounter any provider-specific issues, you might need to:
Try different providers like "hf-inference", "together", or "openai"
Adjust the model name if there are compatibility issues
Troubleshooting:
Ensure all dependencies are installed
Check your Hugging Face API key permissions
Verify the model name and availability
Would you like me to help you further customize or troubleshoot this script?
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from smolagents import tool, CodeAgent
# Download the model
model_name = "HuggingFaceTB/SmolLM2-360M-Instruct"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype=torch.float16, # Use float16 for memory efficiency
device_map="auto" # Automatically use available GPU or CPU
)
# Create a custom local model wrapper for SmolAgents
class LocalHuggingFaceModel:
def __init__(self, model, tokenizer):
self.model = model
self.tokenizer = tokenizer
def generate(self, prompt, max_tokens=4096, temperature=0.1):
# Prepare the input
inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device)
# Generate response
outputs = self.model.generate(
**inputs,
max_length=max_tokens,
temperature=temperature,
do_sample=True
)
# Decode the response
response = self.tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
# Create local model wrapper
local_model = LocalHuggingFaceModel(model, tokenizer)
# Rest of your existing code (tools, data, etc.)
import numpy as np
import pandas as pd
# Your existing tools
@tool
def calculate_transport_cost(distance_km: float, order_volume: float) -> float:
trucks_needed = np.ceil(order_volume / 300)
cost_per_km = 1.20
return distance_km * cost_per_km * trucks_needed
@tool
def calculate_tariff(base_cost: float, is_canadian: bool) -> float:
if is_canadian:
return base_cost * np.pi / 50
return 0
# Supplier data setup
suppliers_data = {
"name": [
"Montreal Ice Cream Co",
"Brain Freeze Brothers",
"Toronto Gelato Ltd",
"Buffalo Scoops",
"Vermont Creamery",
],
"location": [
"Montreal, QC",
"Burlington, VT",
"Toronto, ON",
"Buffalo, NY",
"Portland, ME",
],
"distance_km": [120, 85, 400, 220, 280],
"canadian": [True, False, True, False, False],
"price_per_liter": [1.95, 1.91, 1.82, 2.43, 2.33],
"tasting_fee": [0, 12.50, 30.14, 42.00, 0.20],
}
suppliers_df = pd.DataFrame(suppliers_data)
# Create the agent with local model
agent = CodeAgent(
model=local_model, # Use the local model wrapper
tools=[calculate_transport_cost, calculate_tariff],
max_steps=10,
additional_authorized_imports=["pandas", "numpy"],
verbosity_level=2
)
# Define the task
task = """Here is a dataframe of different ice cream suppliers.
Could you give me a comparative table (as a dataframe) of the total
daily price for getting daily ice cream delivery from each of them,
given that we need exactly 30 liters of ice cream per day? Take
into account transportation cost and tariffs.
"""
# Run the agent
result = agent.run(
task,
additional_args={"suppliers_data": suppliers_df}
)
# Print the result
print(result)