-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy path10_fetch_confluence_document.py
More file actions
37 lines (28 loc) · 1.23 KB
/
10_fetch_confluence_document.py
File metadata and controls
37 lines (28 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2023-2025 Broadcom
# SPDX-License-Identifier: Apache-2.0
import logging
import os
from langchain_community.document_loaders import ConfluenceLoader
from vdk.api.job_input import IJobInput
log = logging.getLogger(__name__)
def fetch_confluence_document(url, token, document_id):
try:
# For more info regarding the LangChain ConfluenceLoader:
# https://python.langchain.com/docs/integrations/document_loaders/confluence
loader = ConfluenceLoader(url=url, token=token)
documents = loader.load(page_ids=[document_id])
return documents[0] if documents else None
except Exception as e:
log.error(f"Error fetching document with ID {document_id} from Confluence: {e}")
return None
def run(job_input: IJobInput):
log.info(f"Starting job step {__name__}")
confluence_url = os.environ.get("VDK_CONFLUENCE_URL")
token = os.environ.get("VDK_CONFLUENCE_TOKEN")
doc_id = os.environ.get("VDK_CONFLUENCE_DOC_ID")
doc = fetch_confluence_document(confluence_url, token, doc_id)
if doc:
log.info(f"Document with ID {doc_id} fetched successfully.")
print(doc.page_content)
else:
log.error(f"Failed to fetch the document with ID {doc_id}.")