forked from langchain-ai/langchainjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.mjs
49 lines (41 loc) · 1.31 KB
/
index.mjs
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
38
39
40
41
42
43
44
45
46
47
48
49
import assert from "assert";
import { OpenAI } from "langchain/llms/openai";
import { LLMChain } from "langchain/chains";
import { ChatPromptTemplate } from "langchain/prompts";
import { loadPrompt } from "langchain/prompts/load";
import { HNSWLib } from "langchain/vectorstores/hnswlib";
import { OpenAIEmbeddings } from "langchain/embeddings/openai";
import { Document } from "langchain/document";
import { CSVLoader } from "langchain/document_loaders/fs/csv";
// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof loadPrompt === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();
const vs = new HNSWLib(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" }), {
space: "ip",
numDimensions: 3,
index: 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 CSVLoader
const loader = new CSVLoader(new Blob(["a,b,c\n1,2,3\n4,5,6"]));
const docs = await loader.load();
assert(docs.length === 2);