ChatGPT 插件
OpenAI 插件将
ChatGPT
连接到第三方应用程序。这些插件使ChatGPT
能够与开发者定义的API进行交互,增强ChatGPT
的能力,并使其能够执行各种操作。
插件允许
ChatGPT
做以下事情:
- 检索实时信息;例如,体育比分、股票价格、最新新闻等。
- 检索知识库信息;例如,公司文档、个人笔记等。
- 代表用户执行操作;例如,预订航班、订购食物等。
本笔记本展示了如何在LangChain中使用ChatGPT检索插件。
# 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_community.document_loaders import CSVLoader
from langchain_core.documents import Document
loader = CSVLoader(
file_path="../../document_loaders/examples/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
import json
from typing import List
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