Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save janzheng/0ac84f64af58e91f491b5adad6abdd28 to your computer and use it in GitHub Desktop.
Save janzheng/0ac84f64af58e91f491b5adad6abdd28 to your computer and use it in GitHub Desktop.
# 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