mirror of https://github.com/hwchase17/langchain
Vwp/docs improved document loaders (#4006)
Huge thanks to @leo-gan for improving the document loaders notebooks --------- Co-authored-by: Leonid Ganeline <leo.gan.57@gmail.com>pull/3636/head
parent
1c68cbdb28
commit
aa38355999
@ -1,151 +1,149 @@
|
|||||||
{
|
{
|
||||||
"cells": [
|
"cells": [
|
||||||
{
|
{
|
||||||
"attachments": {},
|
"cell_type": "markdown",
|
||||||
"cell_type": "markdown",
|
"metadata": {
|
||||||
"metadata": {
|
"id": "vm8vn9t8DvC_"
|
||||||
"id": "vm8vn9t8DvC_"
|
},
|
||||||
},
|
"source": [
|
||||||
"source": [
|
"# Blockchain"
|
||||||
"# Blockchain"
|
]
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "5WjXERXzFEhg"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"## Overview"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {
|
|
||||||
"id": "juAmbgoWD17u"
|
|
||||||
},
|
|
||||||
"source": [
|
|
||||||
"The intention of this notebook is to provide a means of testing functionality in the Langchain Document Loader for Blockchain.\n",
|
|
||||||
"\n",
|
|
||||||
"Initially this Loader supports:\n",
|
|
||||||
"\n",
|
|
||||||
"* Loading NFTs as Documents from NFT Smart Contracts (ERC721 and ERC1155)\n",
|
|
||||||
"* Ethereum Maninnet, Ethereum Testnet, Polgyon Mainnet, Polygon Testnet (default is eth-mainnet)\n",
|
|
||||||
"* Alchemy's getNFTsForCollection API\n",
|
|
||||||
"\n",
|
|
||||||
"It can be extended if the community finds value in this loader. Specifically:\n",
|
|
||||||
"\n",
|
|
||||||
"* Additional APIs can be added (e.g. Tranction-related APIs)\n",
|
|
||||||
"\n",
|
|
||||||
"This Document Loader Requires:\n",
|
|
||||||
"\n",
|
|
||||||
"* A free [Alchemy API Key](https://www.alchemy.com/)\n",
|
|
||||||
"\n",
|
|
||||||
"The output takes the following format:\n",
|
|
||||||
"\n",
|
|
||||||
"- pageContent= Individual NFT\n",
|
|
||||||
"- metadata={'source': '0x1a92f7381b9f03921564a437210bb9396471050c', 'blockchain': 'eth-mainnet', 'tokenId': '0x15'})"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"## Load NFTs into Document Loader"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"alchemyApiKey = \"get from https://www.alchemy.com/ and set in environment variable ALCHEMY_API_KEY\""
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"### Option 1: Ethereum Mainnet (default BlockchainType)"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {
|
|
||||||
"id": "J3LWHARC-Kn0"
|
|
||||||
},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"contractAddress = \"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d\" # Bored Ape Yacht Club contract address\n",
|
|
||||||
"\n",
|
|
||||||
"blockchainType = BlockchainType.ETH_MAINNET #default value, optional parameter\n",
|
|
||||||
"\n",
|
|
||||||
"blockchainLoader = BlockchainDocumentLoader(contract_address=contractAddress,\n",
|
|
||||||
" api_key=alchemyApiKey)\n",
|
|
||||||
"\n",
|
|
||||||
"nfts = blockchainLoader.load()\n",
|
|
||||||
"\n",
|
|
||||||
"nfts[:2]"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"attachments": {},
|
|
||||||
"cell_type": "markdown",
|
|
||||||
"metadata": {},
|
|
||||||
"source": [
|
|
||||||
"### Option 2: Polygon Mainnet"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"contractAddress = \"0x448676ffCd0aDf2D85C1f0565e8dde6924A9A7D9\" # Polygon Mainnet contract address\n",
|
|
||||||
"\n",
|
|
||||||
"blockchainType = BlockchainType.POLYGON_MAINNET \n",
|
|
||||||
"\n",
|
|
||||||
"blockchainLoader = BlockchainDocumentLoader(contract_address=contractAddress, \n",
|
|
||||||
" blockchainType=blockchainType, \n",
|
|
||||||
" api_key=alchemyApiKey)\n",
|
|
||||||
"\n",
|
|
||||||
"nfts = blockchainLoader.load()\n",
|
|
||||||
"\n",
|
|
||||||
"nfts[:2]"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"metadata": {
|
|
||||||
"colab": {
|
|
||||||
"collapsed_sections": [
|
|
||||||
"5WjXERXzFEhg"
|
|
||||||
],
|
|
||||||
"provenance": []
|
|
||||||
},
|
|
||||||
"kernelspec": {
|
|
||||||
"display_name": "Python 3",
|
|
||||||
"name": "python3"
|
|
||||||
},
|
|
||||||
"language_info": {
|
|
||||||
"codemirror_mode": {
|
|
||||||
"name": "ipython",
|
|
||||||
"version": 3
|
|
||||||
},
|
|
||||||
"file_extension": ".py",
|
|
||||||
"mimetype": "text/x-python",
|
|
||||||
"name": "python",
|
|
||||||
"nbconvert_exporter": "python",
|
|
||||||
"pygments_lexer": "ipython3",
|
|
||||||
"version": "3.9.16"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"nbformat": 4,
|
{
|
||||||
"nbformat_minor": 0
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "5WjXERXzFEhg"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"## Overview"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {
|
||||||
|
"id": "juAmbgoWD17u"
|
||||||
|
},
|
||||||
|
"source": [
|
||||||
|
"The intention of this notebook is to provide a means of testing functionality in the Langchain Document Loader for Blockchain.\n",
|
||||||
|
"\n",
|
||||||
|
"Initially this Loader supports:\n",
|
||||||
|
"\n",
|
||||||
|
"* Loading NFTs as Documents from NFT Smart Contracts (ERC721 and ERC1155)\n",
|
||||||
|
"* Ethereum Maninnet, Ethereum Testnet, Polgyon Mainnet, Polygon Testnet (default is eth-mainnet)\n",
|
||||||
|
"* Alchemy's getNFTsForCollection API\n",
|
||||||
|
"\n",
|
||||||
|
"It can be extended if the community finds value in this loader. Specifically:\n",
|
||||||
|
"\n",
|
||||||
|
"* Additional APIs can be added (e.g. Tranction-related APIs)\n",
|
||||||
|
"\n",
|
||||||
|
"This Document Loader Requires:\n",
|
||||||
|
"\n",
|
||||||
|
"* A free [Alchemy API Key](https://www.alchemy.com/)\n",
|
||||||
|
"\n",
|
||||||
|
"The output takes the following format:\n",
|
||||||
|
"\n",
|
||||||
|
"- pageContent= Individual NFT\n",
|
||||||
|
"- metadata={'source': '0x1a92f7381b9f03921564a437210bb9396471050c', 'blockchain': 'eth-mainnet', 'tokenId': '0x15'})"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"## Load NFTs into Document Loader"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"# get ALCHEMY_API_KEY from https://www.alchemy.com/ \n",
|
||||||
|
"\n",
|
||||||
|
"alchemyApiKey = \"...\""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Option 1: Ethereum Mainnet (default BlockchainType)"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {
|
||||||
|
"id": "J3LWHARC-Kn0"
|
||||||
|
},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"from langchain.document_loaders.blockchain import BlockchainDocumentLoader, BlockchainType\n",
|
||||||
|
"contractAddress = \"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d\" # Bored Ape Yacht Club contract address\n",
|
||||||
|
"\n",
|
||||||
|
"blockchainType = BlockchainType.ETH_MAINNET #default value, optional parameter\n",
|
||||||
|
"\n",
|
||||||
|
"blockchainLoader = BlockchainDocumentLoader(contract_address=contractAddress,\n",
|
||||||
|
" api_key=alchemyApiKey)\n",
|
||||||
|
"\n",
|
||||||
|
"nfts = blockchainLoader.load()\n",
|
||||||
|
"\n",
|
||||||
|
"nfts[:2]"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "markdown",
|
||||||
|
"metadata": {},
|
||||||
|
"source": [
|
||||||
|
"### Option 2: Polygon Mainnet"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"cell_type": "code",
|
||||||
|
"execution_count": null,
|
||||||
|
"metadata": {},
|
||||||
|
"outputs": [],
|
||||||
|
"source": [
|
||||||
|
"contractAddress = \"0x448676ffCd0aDf2D85C1f0565e8dde6924A9A7D9\" # Polygon Mainnet contract address\n",
|
||||||
|
"\n",
|
||||||
|
"blockchainType = BlockchainType.POLYGON_MAINNET \n",
|
||||||
|
"\n",
|
||||||
|
"blockchainLoader = BlockchainDocumentLoader(contract_address=contractAddress, \n",
|
||||||
|
" blockchainType=blockchainType, \n",
|
||||||
|
" api_key=alchemyApiKey)\n",
|
||||||
|
"\n",
|
||||||
|
"nfts = blockchainLoader.load()\n",
|
||||||
|
"\n",
|
||||||
|
"nfts[:2]"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata": {
|
||||||
|
"colab": {
|
||||||
|
"collapsed_sections": [
|
||||||
|
"5WjXERXzFEhg"
|
||||||
|
],
|
||||||
|
"provenance": []
|
||||||
|
},
|
||||||
|
"kernelspec": {
|
||||||
|
"display_name": "Python 3 (ipykernel)",
|
||||||
|
"language": "python",
|
||||||
|
"name": "python3"
|
||||||
|
},
|
||||||
|
"language_info": {
|
||||||
|
"codemirror_mode": {
|
||||||
|
"name": "ipython",
|
||||||
|
"version": 3
|
||||||
|
},
|
||||||
|
"file_extension": ".py",
|
||||||
|
"mimetype": "text/x-python",
|
||||||
|
"name": "python",
|
||||||
|
"nbconvert_exporter": "python",
|
||||||
|
"pygments_lexer": "ipython3",
|
||||||
|
"version": "3.10.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nbformat": 4,
|
||||||
|
"nbformat_minor": 4
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue