forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test-exports case for CJS dynamic import (langchain-ai#179)
Since we have this in the docs, we should test it (it does work)
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 deletions.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
async function test() { | ||
const { default: assert } = await import("assert"); | ||
const { OpenAI } = await import("langchain"); | ||
const { loadPrompt } = await import("langchain/prompts"); | ||
const { HNSWLib } = await import("langchain/vectorstores"); | ||
const { OpenAIEmbeddings } = await import("langchain/embeddings"); | ||
const { InMemoryDocstore, Document } = await import("langchain/docstore"); | ||
|
||
// Test exports | ||
assert(typeof OpenAI === "function"); | ||
assert(typeof loadPrompt === "function"); | ||
assert(typeof HNSWLib === "function"); | ||
|
||
// Test dynamic imports of peer dependencies | ||
const { HierarchicalNSW } = await HNSWLib.imports(); | ||
|
||
const vs = new HNSWLib( | ||
{ | ||
space: "ip", | ||
numDimensions: 3, | ||
}, | ||
new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" }), | ||
new InMemoryDocstore(), | ||
new HierarchicalNSW("ip", 3) | ||
); | ||
|
||
await vs.addVectors( | ||
[ | ||
[0, 1, 0], | ||
[0, 0, 1], | ||
], | ||
[ | ||
new Document({ | ||
pageContent: "a", | ||
}), | ||
new Document({ | ||
pageContent: "b", | ||
}), | ||
] | ||
); | ||
|
||
assert((await vs.similaritySearchVectorWithScore([0, 0, 1], 1)).length === 1); | ||
} | ||
|
||
test() | ||
.then(() => console.log("success")) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
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