smolagent是hf推出的agent開發庫,簡潔易用。這里嘗試用smolagents完成簡單數學題目。
1?smolagents安裝
conda create -n smolagents python=3.12
conda activate smolagents
pip install smolagents
pip install 'smolagents[mlx-lm]'
由于是在mac使用mlx,所以除smolagents外還需要安裝mlx-lm套件。
2 編寫agent程序
由于hf訪問問題,設置hf-mirror鏡像環境
受本地算力限制使用4位量化版Coder模型mlx-community/Qwen2.5-Coder-3B-Instruct-4bit
簡單算術題目?5+3 + 1294.678,對應如下任務指令。
What is the result of the following operation: 5 + 3 + 1294.678?
import os
os.environ['HF_ENDPOINT'] = "https://hf-mirror.com"from smolagents import CodeAgent, WebSearchTool, InferenceClientModel, MLXModelmodel = MLXModel(model_id="mlx-community/Qwen2.5-Coder-3B-Instruct-4bit")
agent = CodeAgent(tools=[WebSearchTool()], model=model, stream_outputs=False)agent.run("What is the result of the following operation: 5 + 3 + 1294.678?")
保存為smolagents_test.py
3 運行smolagents示例
運行python?smolagents_test.py,結果如下
可以看出smolagents不是直接用大模型做題,而是先生成解題程序,然后運行程序獲得答案。
reference
---
deepseek
DeepSeek
DeepResearchAgent
https://github.com/SkyworkAI/DeepResearchAgent.git
smolagents
https://github.com/huggingface/smolagents