Lark套件 (飞书)
飞书 是字节跳动开发的一款企业协作平台。
本笔记本介绍如何将数据从飞书
REST API 加载到可以被 LangChain 摄取的格式中,以及文本摘要的示例用法。
飞书 API 需要访问令牌(tenant_access_token 或 user_access_token),请查看飞书开放平台文档了解 API 详细信息。
from getpass import getpass
from langchain_community.document_loaders.larksuite import (
LarkSuiteDocLoader,
LarkSuiteWikiLoader,
)
DOMAIN = input("larksuite domain")
ACCESS_TOKEN = getpass("larksuite tenant_access_token or user_access_token")
DOCUMENT_ID = input("larksuite document id")
API 参考:LarkSuiteDocLoader | LarkSuiteWikiLoader
从文档加载
from pprint import pprint
larksuite_loader = LarkSuiteDocLoader(DOMAIN, ACCESS_TOKEN, DOCUMENT_ID)
docs = larksuite_loader.load()
pprint(docs)
[Document(page_content='Test Doc\nThis is a Test Doc\n\n1\n2\n3\n\n', metadata={'document_id': 'V76kdbd2HoBbYJxdiNNccajunPf', 'revision_id': 11, 'title': 'Test Doc'})]
从 Wiki 加载
from pprint import pprint
DOCUMENT_ID = input("larksuite wiki id")
larksuite_loader = LarkSuiteWikiLoader(DOMAIN, ACCESS_TOKEN, DOCUMENT_ID)
docs = larksuite_loader.load()
pprint(docs)
[Document(page_content='Test doc\nThis is a test wiki doc.\n', metadata={'document_id': 'TxOKdtMWaoSTDLxYS4ZcdEI7nwc', 'revision_id': 15, 'title': 'Test doc'})]
# see https://python.langchain.ac.cn/docs/use_cases/summarization for more details
from langchain.chains.summarize import load_summarize_chain
from langchain_community.llms.fake import FakeListLLM
llm = FakeListLLM()
chain = load_summarize_chain(llm, chain_type="map_reduce")
chain.run(docs)
API 参考:load_summarize_chain | FakeListLLM