Agents入门案例演示

python 复制代码
import os
from langchain_community.llms import QianfanLLMEndpoint
from langchain.agents import load_tools, initialize_agent, AgentType
from langchain_core.prompts import PromptTemplate
from project2.API_Config import *
os.environ["QIANFAN_AK"] = QIANFAN_AK
os.environ["QIANFAN_SK"] = QIANFAN_SK

# 实例化模型
llm = QianfanLLMEndpoint(model="Qianfan-BLOOMZ-7B-compressed")

# 定义工具:这里指定两个工具来选择使用:llm-math计算,wikipedia
tools = load_tools(["wikipedia"], llm=llm)

# 实例化agent
agent = initialize_agent(tools=tools,
                         llm=llm,
                         agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
                         verbose=True)

# print(f'agent-->{agent}')

prompt_template = "中国目前有多少人口"
prompt = PromptTemplate.from_template(prompt_template)

# 执行代理
result = agent.run(prompt)
print(result)
相关推荐
KAI智习6 小时前
大模型榜单周报(2025/12/20)
人工智能·大模型
咩图8 小时前
使用ollama完成私有大模型搭建
大模型·ollama·私有化
我很哇塞耶8 小时前
BOSS直聘3B超越Qwen3-32B,更多训练数据刷新小模型极限
人工智能·ai·大模型
骚戴11 小时前
n1n:从替代LiteLLM Proxy自建网关到企业级统一架构的进阶之路
人工智能·python·大模型·llm·gateway·api
喜欢吃豆14 小时前
下一代 AI 销售陪练系统的架构蓝图与核心技术挑战深度研究报告
人工智能·架构·大模型·多模态·ai销售陪练
不会吉他的肌肉男不是好的挨踢男17 小时前
SearXNG AI 的免费搜索引擎api 调用
搜索引擎·ai·大模型·serxng
骚戴17 小时前
LLM API Gateway:LLM API 架构、AI 聚合与成本优化全解(2025深度指南)
人工智能·python·大模型·llm·gateway·api
北邮刘老师1 天前
【智能体互联协议解析】北邮ACPs协议和代码与智能体互联AIP标准的关系
人工智能·大模型·智能体·智能体互联网
Yan-英杰1 天前
从Free Tier到Serverless:用亚马逊云科技打造零门槛AI应用
服务器·开发语言·科技·ai·大模型