{ "cells": [ { "cell_type": "markdown", "id": "f34864b5", "metadata": {}, "source": [ "# Requests\n", "\n", "The web contains a lot of information that LLMs do not have access to. In order to easily let LLMs interact with that information, we provide a wrapper around the Python Requests module that takes in a URL and fetches data from that URL." ] }, { "cell_type": "code", "execution_count": 3, "id": "5d8764ba", "metadata": {}, "outputs": [], "source": [ "from langchain.agents import load_tools\n", "\n", "requests_tools = load_tools([\"requests_all\"])" ] }, { "cell_type": "code", "execution_count": 6, "id": "bc5edde2", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[RequestsGetTool(name='requests_get', description='A portal to the internet. Use this when you need to get specific content from a website. Input should be a url (i.e. https://www.google.com). The output will be the text response of the GET request.', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None)),\n", " RequestsPostTool(name='requests_post', description='Use this when you want to POST to a website.\\n Input should be a json string with two keys: \"url\" and \"data\".\\n The value of \"url\" should be a string, and the value of \"data\" should be a dictionary of \\n key-value pairs you want to POST to the url.\\n Be careful to always use double quotes for strings in the json string\\n The output will be the text response of the POST request.\\n ', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None)),\n", " RequestsPatchTool(name='requests_patch', description='Use this when you want to PATCH to a website.\\n Input should be a json string with two keys: \"url\" and \"data\".\\n The value of \"url\" should be a string, and the value of \"data\" should be a dictionary of \\n key-value pairs you want to PATCH to the url.\\n Be careful to always use double quotes for strings in the json string\\n The output will be the text response of the PATCH request.\\n ', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None)),\n", " RequestsPutTool(name='requests_put', description='Use this when you want to PUT to a website.\\n Input should be a json string with two keys: \"url\" and \"data\".\\n The value of \"url\" should be a string, and the value of \"data\" should be a dictionary of \\n key-value pairs you want to PUT to the url.\\n Be careful to always use double quotes for strings in the json string.\\n The output will be the text response of the PUT request.\\n ', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None)),\n", " RequestsDeleteTool(name='requests_delete', description='A portal to the internet. Use this when you need to make a DELETE request to a URL. Input should be a specific url, and the output will be the text response of the DELETE request.', args_schema=None, return_direct=False, verbose=False, callbacks=None, callback_manager=None, requests_wrapper=TextRequestsWrapper(headers=None, aiosession=None))]" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "requests_tools" ] }, { "attachments": {}, "cell_type": "markdown", "id": "55cfe672", "metadata": {}, "source": [ "### Inside the tool\n", "\n", "Each requests tool contains a `requests` wrapper. You can work with these wrappers directly below" ] }, { "cell_type": "code", "execution_count": 8, "id": "c56d4678", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "TextRequestsWrapper(headers=None, aiosession=None)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Each tool wrapps a requests wrapper\n", "requests_tools[0].requests_wrapper" ] }, { "cell_type": "code", "execution_count": 4, "id": "81aae09e", "metadata": {}, "outputs": [], "source": [ "from langchain.utilities import TextRequestsWrapper\n", "requests = TextRequestsWrapper()\n" ] }, { "cell_type": "code", "execution_count": 5, "id": "fd210142", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'