当前位置:   article > 正文

langchain agent简单使用;文档总结load_summarize_chain_langchain agent

langchain agent

1、langchain agent简单使用

参考:https://zhuanlan.zhihu.com/p/643868934?utm_id=0

from langchain.agents.agent_toolkits import create_python_agent
from langchain.agents import load_tools, initialize_agent
from langchain.agents import AgentType
from langchain.tools.python.tool import PythonREPLTool
from langchain.python import PythonREPL
from langchain.chat_models import ChatOpenAI
 

#创建llm;llm调用本地模型
api_base_url = "http://localhost:10860/v1" 
api_key= "EMPTY"
LLM_MODEL = "/mnt/data/loong/AquilaChat2-7B"
llm = ChatOpenAI(
    streaming=True,
    verbose=True,
    # callbacks=[callback],
    openai_api_key=api_key,
    openai_api_base=api_base_url,
    model_name=LLM_MODEL
)


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

#定义工具
tools = load_tools(["llm-math"], llm=llm)
 
#创建代理; ReAct框架默认
agent= initialize_agent(
    tools, 
    llm, 
    agent=A
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/610480
推荐阅读
相关标签
  

闽ICP备14008679号