LangChain-16 Using Tools LangChain封装好的工具集tools

本文涉及的产品
阿里云百炼推荐规格 ADB PostgreSQL,4核16GB 100GB 1个月
简介: LangChain-16 Using Tools LangChain封装好的工具集tools

背景描述

LangChain的社区提供了很多封装好的工具,可以直接拿来用(有的需要申请和配置API KEY)

安装依赖

pip install --upgrade --quiet  langchain-core langchain langchain-openai

编写代码

这里使用 DuckDuckGoSearchRun搜索功能,可以帮助我们调用 DuckDuck搜索引擎

from langchain.tools import DuckDuckGoSearchRun
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI


search = DuckDuckGoSearchRun()

template = """turn the following user input into a search query for a search engine:

{input}"""
prompt = ChatPromptTemplate.from_template(template)

# 使用GPT-4-Turbo 3.5完成的效果不好
model = ChatOpenAI(
    model="gpt-4-0125-preview"
)

chain = prompt | model | StrOutputParser() | search
message1 = chain.invoke({"input": "I'd like to figure out what games are tonight"})
print(f"message1: {message1}")

此外,它的工具包中,还封装了这些

__all__ = [
    "AINAppOps",
    "AINOwnerOps",
    "AINRuleOps",
    "AINTransfer",
    "AINValueOps",
    "AIPluginTool",
    "APIOperation",
    "ArxivQueryRun",
    "AzureCogsFormRecognizerTool",
    "AzureCogsImageAnalysisTool",
    "AzureCogsSpeech2TextTool",
    "AzureCogsText2SpeechTool",
    "BaseGraphQLTool",
    "BaseRequestsTool",
    "BaseSQLDatabaseTool",
    "BaseSparkSQLTool",
    "BaseTool",
    "BingSearchResults",
    "BingSearchRun",
    "BraveSearch",
    "ClickTool",
    "CopyFileTool",
    "CurrentWebPageTool",
    "DeleteFileTool",
    "DuckDuckGoSearchResults",
    "DuckDuckGoSearchRun",
    "EdenAiExplicitImageTool",
    "EdenAiObjectDetectionTool",
    "EdenAiParsingIDTool",
    "EdenAiParsingInvoiceTool",
    "EdenAiTextToSpeechTool",
    "EdenAiSpeechToTextTool",
    "EdenAiTextModerationTool",
    "EdenaiTool",
    "ElevenLabsText2SpeechTool",
    "ExtractHyperlinksTool",
    "ExtractTextTool",
    "FileSearchTool",
    "GetElementsTool",
    "GmailCreateDraft",
    "GmailGetMessage",
    "GmailGetThread",
    "GmailSearch",
    "GmailSendMessage",
    "GooglePlacesTool",
    "GoogleSearchResults",
    "GoogleSearchRun",
    "GoogleSerperResults",
    "GoogleSerperRun",
    "HumanInputRun",
    "IFTTTWebhook",
    "InfoPowerBITool",
    "InfoSQLDatabaseTool",
    "InfoSparkSQLTool",
    "JiraAction",
    "JsonGetValueTool",
    "JsonListKeysTool",
    "ListDirectoryTool",
    "ListPowerBITool",
    "ListSQLDatabaseTool",
    "ListSparkSQLTool",
    "MetaphorSearchResults",
    "MoveFileTool",
    "NavigateBackTool",
    "NavigateTool",
    "O365SearchEmails",
    "O365SearchEvents",
    "O365CreateDraftMessage",
    "O365SendMessage",
    "O365SendEvent",
    "authenticate",
    "OpenAPISpec",
    "OpenWeatherMapQueryRun",
    "PubmedQueryRun",
    "PythonAstREPLTool",
    "PythonREPLTool",
    "QueryCheckerTool",
    "QueryPowerBITool",
    "QuerySQLCheckerTool",
    "QuerySQLDataBaseTool",
    "QuerySparkSQLTool",
    "ReadFileTool",
    "RequestsDeleteTool",
    "RequestsGetTool",
    "RequestsPatchTool",
    "RequestsPostTool",
    "RequestsPutTool",
    "SceneXplainTool",
    "SearxSearchResults",
    "SearxSearchRun",
    "ShellTool",
    "SleepTool",
    "StdInInquireTool",
    "SteamshipImageGenerationTool",
    "StructuredTool",
    "Tool",
    "VectorStoreQATool",
    "VectorStoreQAWithSourcesTool",
    "WikipediaQueryRun",
    "WolframAlphaQueryRun",
    "WriteFileTool",
    "YouTubeSearchTool",
    "ZapierNLAListActions",
    "ZapierNLARunAction",
    "tool",
    "format_tool_to_openai_function",
    "BearlyInterpreterTool",
]

运行结果

➜ python3 test16.py
/Users/wuzikang/Desktop/py/langchain_test/own_learn/env/lib/python3.12/site-packages/langchain/tools/__init__.py:63: LangChainDeprecationWarning: Importing tools from langchain is deprecated. Importing from langchain will no longer be supported as of langchain==0.2.0. Please import from langchain-community instead:

`from langchain_community.tools import DuckDuckGoSearchRun`.

To install langchain-community run `pip install -U langchain-community`.
  warnings.warn(
message1: How to live stream NBA games tonight. Pelicans vs Thunder and Clippers vs Lakers will air on ESPN. Viewers can also stream NBA games on Sling TV. Fans in the U.S. can watch the biggest games of ... NBA Games on TV Tonight - 2023-2024 NBA TV Schedule What Channel and Time is NBA Games on TV Today, Tonight, Tomorrow? Watch and Stream live NBA games on TV tonight and today. NBA games are broadcast on ABC, ESPN, TNT, NBATV and local networks. NBA on TV Sunday, 3/17/2024. NBA REGULAR SEASON TIME ET TV; Phoenix at Milwaukee: What Channel and Time do NHL Games Play on TV Today, Tonight, Tomorrow? Watch and stream NHL live games today on TV. 2023-24 NHL TV Schedule for tonight includes games on ABC, ESPN, TNT, TBS & Hulu. NHL on TV Sunday, 3/17/2024. NHL REGULAR SEASON TIME ET TV; NY Islanders at NY Rangers: 1:00pm: TNT: New Jersey at Vegas: 3:30pm: TNT: The web page shows the schedule of NFL Network programs for the next two weeks. There are no games on tonight, only replays of previous games and shows. Tonight's schedule features two primetime games. The Tennessee Titans take on the Miami Dolphins at Hard Rock Stadium and the Green Bay Packers face the New York Giants at MetLife. Both games take place at 8:15 PM. ... One regular season game and one NFL Playoff game will only be available to Peacock subscribers. The first game will take ...

相关实践学习
阿里云百炼xAnalyticDB PostgreSQL构建AIGC应用
通过该实验体验在阿里云百炼中构建企业专属知识库构建及应用全流程。同时体验使用ADB-PG向量检索引擎提供专属安全存储,保障企业数据隐私安全。
AnalyticDB PostgreSQL 企业智能数据中台:一站式管理数据服务资产
企业在数据仓库之上可构建丰富的数据服务用以支持数据应用及业务场景;ADB PG推出全新企业智能数据平台,用以帮助用户一站式的管理企业数据服务资产,包括创建, 管理,探索, 监控等; 助力企业在现有平台之上快速构建起数据服务资产体系
目录
相关文章
|
人工智能 缓存 安全
LangChain开发环境准备-实现私有大模型OpenAI标准接口封装
今天这节课我就将带领小伙伴们将这未完成的一步补全,实现私有大模型OpenAI标准接口封装,并完成LangChain对大模型的调用与测试
1964 0
|
1月前
LangChain-12 Routing By Semantic Similarity 让GPT根据不明确的问题 自动选择工具集 根据语义自动路由
LangChain-12 Routing By Semantic Similarity 让GPT根据不明确的问题 自动选择工具集 根据语义自动路由
33 6
|
1月前
LangChain-24 Agengts 通过TavilySearch Agent实现检索内容并回答 AgentExecutor转换Search 借助Prompt Tools工具
LangChain-24 Agengts 通过TavilySearch Agent实现检索内容并回答 AgentExecutor转换Search 借助Prompt Tools工具
28 0
|
3月前
|
传感器 人工智能 开发框架
LangChain 构建问题之tools列表中search_by_exact工具的添加如何解决
LangChain 构建问题之tools列表中search_by_exact工具的添加如何解决
15 0
|
6月前
|
数据采集 存储 人工智能
【AI大模型应用开发】【LangChain系列】实战案例2:通过URL加载网页内容 - LangChain对爬虫功能的封装
【AI大模型应用开发】【LangChain系列】实战案例2:通过URL加载网页内容 - LangChain对爬虫功能的封装
383 0
|
6月前
Appium自动化常用adb操作封装
Appium自动化常用adb操作封装
65 0
|
缓存 网络协议 安全
adb常用命令总结及.bat文件封装
adb常用命令总结及.bat文件封装
573 0
|
6月前
|
Shell Android开发
Android系统 adb shell push/pull 禁止特定文件
Android系统 adb shell push/pull 禁止特定文件
533 1
|
6月前
|
Android开发 Python
Python封装ADB获取Android设备wifi地址的方法
Python封装ADB获取Android设备wifi地址的方法
147 0
|
3月前
|
Shell Linux 开发工具
"开发者的救星:揭秘如何用adb神器征服Android设备,开启高效调试之旅!"
【8月更文挑战第20天】Android Debug Bridge (adb) 是 Android 开发者必备工具,用于实现计算机与 Android 设备间通讯,执行调试及命令操作。adb 提供了丰富的命令行接口,覆盖从基础设备管理到复杂系统操作的需求。本文详细介绍 adb 的安装配置流程,并列举实用命令示例,包括设备连接管理、应用安装调试、文件系统访问等基础功能,以及端口转发、日志查看等高级技巧。此外,还提供了常见问题的故障排除指南,帮助开发者快速解决问题。掌握 adb 将极大提升 Android 开发效率,助力项目顺利推进。
82 0
下一篇
无影云桌面