coollad49's picture
restructure and use openrouter model
0cbdd47
Raw History Blame Contribute Delete
976 Bytes
from smolagents import ToolCallingAgent, DuckDuckGoSearchTool, VisitWebpageTool, CodeAgent, OpenAIServerModel
from dotenv import load_dotenv
import os
load_dotenv()
openrouter_api_key = os.environ.get("OPENROUTER_API_KEY")
model = OpenAIServerModel(
model_id="google/gemini-2.0-flash-lite-preview-02-05:free", # or any other OpenRouter model
api_base="https://openrouter.ai/api/v1",
api_key=openrouter_api_key,
custom_role_conversions=None,
max_tokens=2096,
temperature=0.5,
)
def web_agent():
"""
This function returns a web agent that uses the DuckDuckGoSearchTool and VisitWebpageTool to search for a query and visit a webpage.
"""
# Use the DuckDuckGoSearchTool to search for the query
return CodeAgent(
model=model,
tools=[DuckDuckGoSearchTool(), VisitWebpageTool()],
name="web_agent",
description="Browses the web to find information",
verbosity_level=0,
max_steps=10,
)