mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-09 06:53:59 +00:00
community[minor]: add JsonRequestsWrapper tool (#15374)
**Description:** This new feature enhances the flexibility of pipeline integration, particularly when working with RESTful APIs. ``JsonRequestsWrapper`` allows for the decoding of JSON output, instead of the only option for text output. --------- Co-authored-by: Zhichao HAN <hanzhichao2000@hotmail.com>
This commit is contained in:
@@ -113,10 +113,63 @@
|
||||
"requests.get(\"https://www.google.com\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "4b0bf1d0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"If you need the output to be decoded from JSON, you can use the ``JsonRequestsWrapper``."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 1,
|
||||
"id": "3f27ee3d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n",
|
||||
"\n",
|
||||
"Type - <class 'dict'>\n",
|
||||
"\n",
|
||||
"Content: \n",
|
||||
"```\n",
|
||||
"{'count': 5707, 'name': 'jackson', 'age': 38}\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"from langchain_community.utilities.requests import JsonRequestsWrapper\n",
|
||||
"\n",
|
||||
"requests = JsonRequestsWrapper()\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"rval = requests.get(\"https://api.agify.io/?name=jackson\")\n",
|
||||
"\n",
|
||||
"print(\n",
|
||||
" f\"\"\"\n",
|
||||
"\n",
|
||||
"Type - {type(rval)}\n",
|
||||
"\n",
|
||||
"Content: \n",
|
||||
"```\n",
|
||||
"{rval}\n",
|
||||
"```\n",
|
||||
"\n",
|
||||
"\"\"\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3f27ee3d",
|
||||
"id": "52a1aa15",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
@@ -138,7 +191,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.2"
|
||||
"version": "3.10.13"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
Reference in New Issue
Block a user