Skip to content

Commit

Permalink
langchain[patch]: update metadata and default expand param for conflu…
Browse files Browse the repository at this point in the history
…ence loader (#4220)

* update metadata and default expand param for confluence loader

* format

* Fix test

* Format

---------

Co-authored-by: Chris Chen <[email protected]>
Co-authored-by: jacoblee93 <[email protected]>
  • Loading branch information
3 people authored Feb 7, 2024
1 parent d4c5dd5 commit 12204d6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
18 changes: 11 additions & 7 deletions langchain/src/document_loaders/tests/confluence.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ test("Test ConfluenceLoader and fetchConfluenceData calls", async () => {
// until the size of the response is 0
const fetchConfluenceDataMock = jest
.spyOn(loader, "fetchConfluenceData")
.mockImplementationOnce(() =>
Promise.resolve({ size: 2, results: fakeResponse })
.mockImplementationOnce(
() =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Promise.resolve({ size: 2, results: fakeResponse }) as any
)
.mockImplementationOnce(() =>
Promise.resolve({ size: 2, results: fakeResponse })
.mockImplementationOnce(
() =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Promise.resolve({ size: 2, results: fakeResponse }) as any
)
.mockImplementationOnce(() => Promise.resolve({ size: 0, results: [] }));

Expand All @@ -57,15 +61,15 @@ test("Test ConfluenceLoader and fetchConfluenceData calls", async () => {
// Ensure the arguments are correct for each call
expect(fetchConfluenceDataMock).toHaveBeenNthCalledWith(
1,
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=0&expand=body.storage"
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=0&expand=body.storage,version"
);
expect(fetchConfluenceDataMock).toHaveBeenNthCalledWith(
2,
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=2&expand=body.storage"
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=2&expand=body.storage,version"
);
expect(fetchConfluenceDataMock).toHaveBeenNthCalledWith(
3,
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=4&expand=body.storage"
"https://example.atlassian.net/wiki/rest/api/content?spaceKey=SPACEKEY&limit=25&start=4&expand=body.storage,version"
);

// Check if the generated URLs in the metadata are correct
Expand Down
17 changes: 16 additions & 1 deletion langchain/src/document_loaders/web/confluence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@ export interface ConfluencePagesLoaderParams {
export interface ConfluencePage {
id: string;
title: string;
type: string;
body: {
storage: {
value: string;
};
};
status: string;
version?: {
number: number;
when: string;
by: {
displayName: string;
};
};
}

/**
Expand Down Expand Up @@ -76,7 +85,7 @@ export class ConfluencePagesLoader extends BaseDocumentLoader {
username,
accessToken,
limit = 25,
expand = "body.storage",
expand = "body.storage,version",
personalAccessToken,
}: ConfluencePagesLoaderParams) {
super();
Expand Down Expand Up @@ -212,8 +221,14 @@ export class ConfluencePagesLoader extends BaseDocumentLoader {
return new Document({
pageContent: textWithoutEmptyLines,
metadata: {
id: page.id,
status: page.status,
title: page.title,
type: page.type,
url: pageUrl,
version: page.version?.number,
updated_by: page.version?.by?.displayName,
updated_at: page.version?.when,
},
});
}
Expand Down

0 comments on commit 12204d6

Please sign in to comment.