Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch RAG tools from nft.storage to pinata.cloud #100

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rag_tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The RAG (Retrieval-Augmented Generation) Knowledge Base Script is designed to au
Before you begin, ensure you have the following:
- Python 3.11 or later installed on your system.
- A funded wallet and corresponding private key
- An API key for `nft.storage` to facilitate document uploading to IPFS. You can obtain this key by registering at [nft.storage](https://nft.storage).
- An API key for `pinata.cloud` to facilitate document uploading to IPFS. You can obtain this key by registering at [pinata.cloud](https://www.pinata.cloud).

## Setup

Expand Down
2 changes: 1 addition & 1 deletion rag_tools/add_knowledge_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(directory: str, chunk_size: int, chunk_overlap: int) -> None:
parser.add_argument("-o", "--chunk-overlap", type=int, default=100)
args = parser.parse_args()

assert settings.STORAGE_KEY, "NFT_STORAGE_API_KEY missing from .env"
assert settings.STORAGE_KEY, "PINATA_API_KEY missing from .env"

if not os.path.exists(args.directory):
print(f"Directory {args.directory} does not exist, exiting.")
Expand Down
11 changes: 6 additions & 5 deletions rag_tools/knowledgebase/upload_documents_use_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

def execute(documents: List[Document]) -> str:
serialized_data = _serialize_documents(documents)
multipart_data = {
"file": ("file", serialized_data, ),
}
response = requests.post(
"https://api.nft.storage/upload",
"https://api.pinata.cloud/pinning/pinFileToIPFS",
headers={
"Authorization": f"Bearer {settings.STORAGE_KEY}",
"Content-Type": "text/plain",
},
data=serialized_data,
files=multipart_data,
)
response.raise_for_status()
return response.json().get("value").get("cid")
return response.json().get("IpfsHash")


def _serialize_documents(documents: List[Document]) -> str:
Expand Down
2 changes: 1 addition & 1 deletion rag_tools/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CHAIN_ID = int(os.getenv("CHAIN_ID", "696969"))
RPC_URL = os.getenv("RPC_URL", "https://devnet.galadriel.com")
PRIVATE_KEY = os.getenv("PRIVATE_KEY")
STORAGE_KEY = os.getenv("NFT_STORAGE_API_KEY")
STORAGE_KEY = os.getenv("PINATA_API_KEY")
ORACLE_ADDRESS = os.getenv("ORACLE_ADDRESS")
ORACLE_ABI_PATH = os.getenv(
"ORACLE_ABI_PATH",
Expand Down
2 changes: 1 addition & 1 deletion rag_tools/template.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ CHAIN_ID=696969
RPC_URL="https://devnet.galadriel.com"
PRIVATE_KEY="0x"
ORACLE_ADDRESS="0x"
NFT_STORAGE_API_KEY="0x"
PINATA_API_KEY="0x"
Loading