ConfluenceLoader#
- class langchain_community.document_loaders.confluence.ConfluenceLoader(url: str, api_key: str | None = None, username: str | None = None, session: Session | None = None, oauth2: dict | None = None, token: str | None = None, cloud: bool | None = True, number_of_retries: int | None = 3, min_retry_seconds: int | None = 2, max_retry_seconds: int | None = 10, confluence_kwargs: dict | None = None, *, cookies: dict | None = None, space_key: str | None = None, page_ids: List[str] | None = None, label: str | None = None, cql: str | None = None, include_restricted_content: bool = False, include_archived_content: bool = False, include_attachments: bool = False, include_comments: bool = False, include_labels: bool = False, content_format: ContentFormat = ContentFormat.STORAGE, limit: int | None = 50, max_pages: int | None = 1000, ocr_languages: str | None = None, keep_markdown_format: bool = False, keep_newlines: bool = False)[source]#
加载 Confluence 页面。
端口 https://llamahub.ai/l/confluence 目前支持用户名/api_key、Oauth2登录、个人访问令牌 或cookies认证。
指定一个页面ID列表和/或空间键,以将相应的页面加载到Document对象中,如果两者都指定,则将返回两者的并集。
您还可以指定一个布尔值 include_attachments 来包含附件,默认情况下设置为 False,如果设置为 True,所有附件将被下载,并且 ConfluenceLoader 将从附件中提取文本并将其添加到 Document 对象中。目前支持的附件类型有:PDF、PNG、JPEG/JPG、SVG、Word 和 Excel。
Confluence API 支持不同格式的页面内容。存储格式是用于存储的原始 XML 表示形式。视图格式是用于查看的 HTML 表示形式,宏会像用户查看时一样呈现。你可以传递一个枚举 content_format 参数来指定内容格式,默认情况下设置为 ContentFormat.STORAGE,支持的值为:ContentFormat.EDITOR、ContentFormat.EXPORT_VIEW、ContentFormat.ANONYMOUS_EXPORT_VIEW、ContentFormat.STORAGE 和 ContentFormat.VIEW。
提示:space_key 和 page_id 都可以在 Confluence 页面的 URL 中找到 - https://yoursite.atlassian.com/wiki/spaces/
/pages/ 示例
from langchain_community.document_loaders import ConfluenceLoader loader = ConfluenceLoader( url="https://yoursite.atlassian.com/wiki", username="me", api_key="12345", space_key="SPACE", limit=50, ) documents = loader.load() # Server on perm loader = ConfluenceLoader( url="https://confluence.yoursite.com/", username="me", api_key="your_password", cloud=False, space_key="SPACE", limit=50, ) documents = loader.load()
- Parameters:
url (str) – 描述
api_key (str, optional) – _描述_, 默认为 None
username (str, optional) – _描述_, 默认为 None
oauth2 (dict, optional) – _描述_, 默认为 {}
token (str, optional) – _描述_, 默认为 None
cloud (bool, optional) – _描述_, 默认为 True
number_of_retries (可选[int], 可选) – 重试次数,默认为3
min_retry_seconds (可选[int], 可选) – 默认为2
max_retry_seconds (可选[int], 可选) – 默认为10
confluence_kwargs (dict, optional) – 用于初始化confluence的额外kwargs
cookies (dict, optional) – _描述_, 默认为 {}
space_key (可选[str], 可选) – 从Confluence URL中获取的空间键,默认为None
page_ids (可选[列表[字符串]], 可选) – 要加载的特定页面ID列表,默认为None
label (可选[str], 可选) – 获取所有带有此标签的页面,默认为 None
cql (可选[str], 可选) – CQL 表达式,默认为 None
include_restricted_content (bool, optional) – 默认为 False
include_archived_content (bool, optional) – 是否包含已归档的内容,默认为 False
include_attachments (bool, 可选) – 默认为 False
include_comments (bool, 可选) – 默认为 False
content_format (ContentFormat) – 指定内容格式,默认为 ContentFormat.STORAGE,支持的值为: ContentFormat.EDITOR, ContentFormat.EXPORT_VIEW, ContentFormat.ANONYMOUS_EXPORT_VIEW, ContentFormat.STORAGE, 和 ContentFormat.VIEW。
limit (int, optional) – 每次请求检索的最大页数,默认为50
max_pages (int, optional) – 总共要检索的最大页数,默认为1000
ocr_languages (str, optional) – 用于Tesseract代理的语言。要使用某种语言,您首先需要安装相应的Tesseract语言包。
keep_markdown_format (bool) – 是否保留markdown格式,默认为False
keep_newlines (bool) – 是否保留换行格式,默认为 False
session (Session | None)
include_labels (bool)
- Raises:
ValueError – 验证输入时出错
ImportError – 所需的依赖项未安装。
方法
__init__
(url[, api_key, username, session, ...])一个用于文档的懒加载器。
aload
()将数据加载到Document对象中。
is_public_page
(page)检查页面是否可公开访问。
一个用于文档的懒加载器。
load
(**kwargs)将数据加载到Document对象中。
load_and_split
([text_splitter])加载文档并将其分割成块。
paginate_request
(retrieval_method, **kwargs)分页各种方法来检索页面组。
process_attachment
(page_id[, ocr_languages])process_doc
(link)process_image
(link[, ocr_languages])process_page
(page, include_attachments, ...)process_pages
(pages, ...[, ocr_languages, ...])将页面列表处理为文档列表。
process_pdf
(link[, ocr_languages])process_svg
(link[, ocr_languages])process_xls
(link)validate_init_args
([url, api_key, username, ...])验证初始化参数的正确组合
- __init__(url: str, api_key: str | None = None, username: str | None = None, session: Session | None = None, oauth2: dict | None = None, token: str | None = None, cloud: bool | None = True, number_of_retries: int | None = 3, min_retry_seconds: int | None = 2, max_retry_seconds: int | None = 10, confluence_kwargs: dict | None = None, *, cookies: dict | None = None, space_key: str | None = None, page_ids: List[str] | None = None, label: str | None = None, cql: str | None = None, include_restricted_content: bool = False, include_archived_content: bool = False, include_attachments: bool = False, include_comments: bool = False, include_labels: bool = False, content_format: ContentFormat = ContentFormat.STORAGE, limit: int | None = 50, max_pages: int | None = 1000, ocr_languages: str | None = None, keep_markdown_format: bool = False, keep_newlines: bool = False)[来源]#
- Parameters:
url (str)
api_key (str | None)
username (str | None)
session (Session | None)
oauth2 (dict | None)
token (str | None)
cloud (bool | None)
number_of_retries (int | None)
min_retry_seconds (int | None)
max_retry_seconds (int | None)
confluence_kwargs (dict | None)
cookies (字典 | 无)
space_key (str | None)
page_ids (列表[字符串] | 无)
标签 (字符串 | 无)
cql (str | None)
include_restricted_content (布尔值)
include_archived_content (bool)
include_attachments (bool)
include_comments (bool)
include_labels (bool)
content_format (ContentFormat)
limit (int | None)
max_pages (int | None)
ocr_languages (str | None)
keep_markdown_format (bool)
keep_newlines (bool)
- load(**kwargs: Any) List[Document] [来源]#
将数据加载到Document对象中。
- Parameters:
kwargs (任意)
- Return type:
列表[文档]
- load_and_split(text_splitter: TextSplitter | None = None) list[Document] #
加载文档并将其分割成块。块以文档形式返回。
不要重写此方法。它应该被视为已弃用!
- Parameters:
text_splitter (可选[TextSplitter]) – 用于分割文档的TextSplitter实例。 默认为RecursiveCharacterTextSplitter。
- Returns:
文档列表。
- Return type:
列表[Document]
- paginate_request(retrieval_method: Callable, **kwargs: Any) List [source]#
分页各种方法来检索页面组。
不幸的是,由于页面大小的限制,有时Confluence API无法匹配限制值。如果limit大于100,Confluence似乎会将响应限制在100。此外,由于Atlassian Python包的原因,我们无法从“_links”键中获取“next”值,因为它们只返回结果键中的值。因此,在这里,分页从0开始,直到max_pages,每次请求获取limit数量的页面。我们必须根据返回的页面列表的长度手动检查是否有更多文档,而不是像这个页面所建议的那样,仅仅检查响应中是否存在next键: https://developer.atlassian.com/server/confluence/pagination-in-the-rest-api/
- Parameters:
retrieval_method (callable) – 用于检索文档的函数
kwargs (Any)
- Returns:
文档列表
- Return type:
列表
- process_attachment(page_id: str, ocr_languages: str | None = None) List[str] [source]#
- Parameters:
page_id (str)
ocr_languages (str | None)
- Return type:
列表[str]
- process_image(link: str, ocr_languages: str | None = None) str [来源]#
- Parameters:
link (str)
ocr_languages (str | None)
- Return type:
字符串
- process_page(page: dict, include_attachments: bool, include_comments: bool, include_labels: bool, content_format: ContentFormat, ocr_languages: str | None = None, keep_markdown_format: bool | None = False, keep_newlines: bool = False) Document [source]#
- Parameters:
page (字典)
include_attachments (bool)
include_comments (bool)
include_labels (bool)
content_format (ContentFormat)
ocr_languages (str | None)
keep_markdown_format (bool | None)
keep_newlines (bool)
- Return type:
- process_pages(pages: List[dict], include_restricted_content: bool, include_attachments: bool, include_comments: bool, include_labels: bool, content_format: ContentFormat, ocr_languages: str | None = None, keep_markdown_format: bool | None = False, keep_newlines: bool = False) Iterator[Document] [source]#
将页面列表处理为文档列表。
- Parameters:
pages (列表[字典])
include_restricted_content (布尔值)
include_attachments (bool)
include_comments (bool)
include_labels (bool)
content_format (ContentFormat)
ocr_languages (str | None)
keep_markdown_format (bool | None)
keep_newlines (bool)
- Return type:
迭代器[文档]
- process_pdf(link: str, ocr_languages: str | None = None) str [source]#
- Parameters:
link (str)
ocr_languages (str | None)
- Return type:
字符串
- process_svg(link: str, ocr_languages: str | None = None) str [来源]#
- Parameters:
link (str)
ocr_languages (str | None)
- Return type:
字符串
- static validate_init_args(url: str | None = None, api_key: str | None = None, username: str | None = None, session: Session | None = None, oauth2: dict | None = None, token: str | None = None, cookies: dict | None = None) List | None [source]#
验证init参数的正确组合
- Parameters:
url (str | None)
api_key (str | None)
username (str | None)
session (Session | None)
oauth2 (dict | None)
token (str | None)
cookies (字典 | 无)
- Return type:
列表 | 无
使用 ConfluenceLoader 的示例