AI创想

标题: langchain deepseek 实现shellTool [打印本页]

作者: 捡得灿    时间: 7 小时前
标题: langchain deepseek 实现shellTool
作者:极客-杀生丸
在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




欢迎光临 AI创想 (https://www.llms-ai.com/) Powered by Discuz! X3.4