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)
相关推荐
远上寒山12 小时前
FlashAttention 原理与工程实践:从 IO-aware 到 H100 上的 1 PFLOPs/s
大模型·注意力机制·flash_attention·online softmax·shared memory
有点不太正常15 小时前
Differentially Private Synthetic Text Generation for RAG——论文阅读
论文阅读·大模型·llm·rag
山顶夕景16 小时前
【LLM】大模型vibe coding(cursor、copilot、comate)
大模型·copilot·coding·vibe coding·代码模型
杀生丸学AI19 小时前
【三维重建】即插即用的3DGS的PDE优化:高质量渲染和重建
人工智能·3d·大模型·aigc·3dgs·高斯泼溅·空间智能
想躺平的咸鱼干1 天前
远程MCP的调用和阿里云生态的知识库和工作流的使用
阿里云·大模型·云计算·idea·格式化输出·mcp
haogexiaole1 天前
什么是语言模型
大模型
泥烟2 天前
使用Milvus和DeepSeek构建RAG demo
大模型·milvus·deepseek
CoderJia程序员甲2 天前
GitHub 热榜项目 - 日榜(2025-10-09)
ai·开源·大模型·github·ai教程
Wild_Pointer.2 天前
面向Qt/C++开发工程师的Ai提示词(附Trae示例)
人工智能·ai·大模型
喜欢吃豆3 天前
从潜在空间到实际应用:Embedding模型架构与训练范式的综合解析
python·自然语言处理·架构·大模型·微调·embedding