快速入门smolagents

官方教程地址Agents - Guided tour

1. 安装

pip install smolagents[litellm]
或者
uv add smolagents[litellm]

2. 配置api key

这里我用的火山的api,注意如果是使用的火山或阿里云的这种服务商的api,model_id这里要以"openai/" 开头,后跟模型名称。

model = LiteLLMModel(
    model_id="openai/deepseek-v3-250324",  # This model is a bit weak for agentic behaviours though
    api_base="https://ark.cn-beijing.volces.com/api/v3",
    api_key="",  # replace with API key if necessary
    num_ctx=8192,
)

3. 完整代码

from smolagents import CodeAgent, LiteLLMModel
from smolagents import ToolCallingAgent, GradioUI, load_tool



model = LiteLLMModel(
    model_id="openai/deepseek-v3-250324",  # This model is a bit weak for agentic behaviours though
    api_base="https://ark.cn-beijing.volces.com/api/v3",
    api_key="",  # replace with API key if necessary
    num_ctx=8192,
)


# Initialize the agent with the image generation tool
agent = CodeAgent(tools=[], model=model, add_base_tools=True)
agent.run("斐波那契数列的第100个数是什么")

smolagents 中的CodeAgent是使用代码作为模型的中间输出,然后调用本地的python编译器工具执行代码,最终得到query的答案。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值