开启左侧

langchain deepseek 实现shellTool

[复制链接]
捡得灿 发表于 9 小时前 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
作者:极客-杀生丸
在langchain使用openai接口,但模型使用国内deepseek,但是要先cq,API-key才能用
代码如下:
  1. import os
  2. import langchain
  3. from langchain.chat_models import ChatOpenAI
  4. from langchain.agents import AgentType, initialize_agent
  5. from langchain.tools import ShellTool
  6. def main():
  7.     # 如果没有从环境变量中读取,则可以手动写入
  8.     #os.environ["OPENAI_API_KEY"] = "your_openai_api_key"
  9.     # 1. 构建 LLM(这里使用 OpenAI 的 ChatGPT)
  10.     llm = ChatOpenAI(
  11.         model_name="deepseek-chat",  # 如 "gpt-3.5-turbo" 或其他
  12.         openai_api_base="https://api.deepseek.com",
  13.         openai_api_key="xxxxx",
  14.         temperature=0.7
  15.     )
  16.     # 2. 准备 Shell 工具
  17.     shell_tool = ShellTool()
  18.     # 3. 初始化 Agent
  19.     #    - 这里我们使用 ZERO_SHOT_REACT_DESCRIPTION 类型的 Agent
  20.     #    - tools 参数里放入一个列表,包含我们所需的工具
  21.     tools = [shell_tool]
  22.     agent = initiali
复制代码
原文地址:https://blog.csdn.net/weixin_44772948/article/details/144874115
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

发布主题
阅读排行更多+

Powered by Discuz! X3.4© 2001-2013 Discuz Team.( 京ICP备17022993号-3 )