Forked from hwchase17/langchain_to_chatgpt-retrieval-plugin.py
Created
March 23, 2023 21:28
-
-
Save wahidurahman/a8aab02279c668d4c0a4f7495fd64a67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# STEP 1: Load | |
# Load documents using LangChain's DocumentLoaders | |
# This is from https://langchain.readthedocs.io/en/latest/modules/document_loaders/examples/csv.html | |
from langchain.document_loaders.csv_loader import CSVLoader | |
loader = CSVLoader(file_path='./example_data/mlb_teams_2012.csv') | |
data = loader.load() | |
# STEP 2: Convert | |
# Convert Document to format expected by https://github.com/openai/chatgpt-retrieval-plugin | |
from typing import List | |
from langchain.docstore.document import Document | |
import json | |
def write_json(path: str, documents: List[Document])-> None: | |
results = [{"text": doc.page_content} for doc in documents] | |
with open(path, "w") as f: | |
json.dump(results, f, indent=2) | |
write_json("foo.json", data) | |
# STEP 3: Use | |
# Ingest this as you would any other json file in https://github.com/openai/chatgpt-retrieval-plugin/tree/main/scripts/process_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment