from langchain.agents import Tool
from langchain.tools import BaseTool
from math import pi
from typing import Union
from langchain.agents import initialize_agent
from langchain.agents import AgentType
import os
from langchain.chat_models import ChatOpenAI
os.environ["OPENAI_API_KEY"] = "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
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
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"
llm = ChatOpenAI(
openai_api_key=os.environ["OPENAI_API_KEY"] ,
temperature=0,
model_name='gpt-3.5-turbo'
)
class CustomTool(BaseTool):
name = "Temperature Detector"
description = "This is a custom tool for my temperature detection use case"
def _run(self, input: str) -> str:
# Your logic here
return "temperature is not bad,huh,20 celceius"
def _arun(self, query: str):
raise NotImplementedError("This tool does not support async")
class Robotic_Control(BaseTool):
name = "Robotic Arm Control"
description = "This is a custom tool for my Robotic Arm Control"
def _run(self, input: str) -> str:
# Your logic here
return "Working "
def _arun(self, query: str):
raise NotImplementedError("This tool does not support async")
tools = [CustomTool(),Robotic_Control()]
# agent = initialize_agent(tools, agent=AgentType.DEFAULT)
agent = initialize_agent(tools,
llm,
agent="zero-shot-react-description",
verbose=True)
agent("How's the temperature and Robotic Arm Control")
其他友情链接:
为 LLM 代理构建自定义工具 |松果 (pinecone.io)
Create Custom Tools for Chatbots in LangChain — LangChain #8 - YouTube
//油管这个小哥讲的比较好 文章来源:https://www.toymoban.com/news/detail-514816.html
Tools怎么使用?可以定义自己的tool么? - General - LangChain中文社区文章来源地址https://www.toymoban.com/news/detail-514816.html
到了这里,关于LangChain-Agent自定义Tools类 ——基础篇(一)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!