-
Notifications
You must be signed in to change notification settings - Fork 15.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
community: add include_labels option to ConfluenceLoader #28259
Merged
efriis
merged 4 commits into
langchain-ai:master
from
nakamasato:add-include-labels-option-to-confluence-loaders
Dec 9, 2024
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,7 @@ def __init__( | |
include_archived_content: bool = False, | ||
include_attachments: bool = False, | ||
include_comments: bool = False, | ||
include_labels: bool = False, | ||
content_format: ContentFormat = ContentFormat.STORAGE, | ||
limit: Optional[int] = 50, | ||
max_pages: Optional[int] = 1000, | ||
|
@@ -181,6 +182,7 @@ def __init__( | |
self.include_archived_content = include_archived_content | ||
self.include_attachments = include_attachments | ||
self.include_comments = include_comments | ||
self.include_labels = include_labels | ||
self.content_format = content_format | ||
self.limit = limit | ||
self.max_pages = max_pages | ||
|
@@ -327,12 +329,20 @@ def _lazy_load(self, **kwargs: Any) -> Iterator[Document]: | |
) | ||
include_attachments = self._resolve_param("include_attachments", kwargs) | ||
include_comments = self._resolve_param("include_comments", kwargs) | ||
include_labels = self._resolve_param("include_labels", kwargs) | ||
content_format = self._resolve_param("content_format", kwargs) | ||
limit = self._resolve_param("limit", kwargs) | ||
max_pages = self._resolve_param("max_pages", kwargs) | ||
ocr_languages = self._resolve_param("ocr_languages", kwargs) | ||
keep_markdown_format = self._resolve_param("keep_markdown_format", kwargs) | ||
keep_newlines = self._resolve_param("keep_newlines", kwargs) | ||
expand = ",".join( | ||
[ | ||
content_format.value, | ||
"version", | ||
*(["metadata.labels"] if include_labels else []), | ||
] | ||
) | ||
|
||
if not space_key and not page_ids and not label and not cql: | ||
raise ValueError( | ||
|
@@ -347,13 +357,14 @@ def _lazy_load(self, **kwargs: Any) -> Iterator[Document]: | |
limit=limit, | ||
max_pages=max_pages, | ||
status="any" if include_archived_content else "current", | ||
expand=f"{content_format.value},version", | ||
expand=expand, | ||
) | ||
yield from self.process_pages( | ||
pages, | ||
include_restricted_content, | ||
include_attachments, | ||
include_comments, | ||
include_labels, | ||
content_format, | ||
ocr_languages=ocr_languages, | ||
keep_markdown_format=keep_markdown_format, | ||
|
@@ -380,13 +391,14 @@ def _lazy_load(self, **kwargs: Any) -> Iterator[Document]: | |
limit=limit, | ||
max_pages=max_pages, | ||
include_archived_spaces=include_archived_content, | ||
expand=f"{content_format.value},version", | ||
expand=expand, | ||
) | ||
yield from self.process_pages( | ||
pages, | ||
include_restricted_content, | ||
include_attachments, | ||
include_comments, | ||
False, # labels are not included in the search results | ||
content_format, | ||
ocr_languages, | ||
keep_markdown_format, | ||
|
@@ -408,14 +420,16 @@ def _lazy_load(self, **kwargs: Any) -> Iterator[Document]: | |
before_sleep=before_sleep_log(logger, logging.WARNING), | ||
)(self.confluence.get_page_by_id) | ||
page = get_page( | ||
page_id=page_id, expand=f"{content_format.value},version" | ||
page_id=page_id, | ||
expand=expand, | ||
) | ||
if not include_restricted_content and not self.is_public_page(page): | ||
continue | ||
yield self.process_page( | ||
page, | ||
include_attachments, | ||
include_comments, | ||
include_labels, | ||
content_format, | ||
ocr_languages, | ||
keep_markdown_format, | ||
|
@@ -498,6 +512,7 @@ def process_pages( | |
include_restricted_content: bool, | ||
include_attachments: bool, | ||
include_comments: bool, | ||
include_labels: bool, | ||
content_format: ContentFormat, | ||
ocr_languages: Optional[str] = None, | ||
keep_markdown_format: Optional[bool] = False, | ||
|
@@ -511,6 +526,7 @@ def process_pages( | |
page, | ||
include_attachments, | ||
include_comments, | ||
include_labels, | ||
content_format, | ||
ocr_languages=ocr_languages, | ||
keep_markdown_format=keep_markdown_format, | ||
|
@@ -522,6 +538,7 @@ def process_page( | |
page: dict, | ||
include_attachments: bool, | ||
include_comments: bool, | ||
include_labels: bool, | ||
content_format: ContentFormat, | ||
ocr_languages: Optional[str] = None, | ||
keep_markdown_format: Optional[bool] = False, | ||
|
@@ -575,10 +592,19 @@ def process_page( | |
] | ||
text = text + "".join(comment_texts) | ||
|
||
if include_labels: | ||
labels = [ | ||
label["name"] | ||
for label in page.get("metadata", {}) | ||
.get("labels", {}) | ||
.get("results", []) | ||
] | ||
Comment on lines
+596
to
+601
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
metadata = { | ||
"title": page["title"], | ||
"id": page["id"], | ||
"source": self.base_url.strip("/") + page["_links"]["webui"], | ||
**({"labels": labels} if include_labels else {}), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set |
||
} | ||
|
||
if "version" in page and "when" in page["version"]: | ||
|
This file contains 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expand
is a comma-separated query parameter. originally hardcoded asf"{content_format.value},version"
.I made a variable so we can add more option if necessary in the future as
expand
parameter supports a lot more values.(ref)