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.
Adds Bun runtime and export test (langchain-ai#2595)
- Loading branch information
1 parent
378bc19
commit c706e8c
Showing
12 changed files
with
383 additions
and
0 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
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
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,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euxo pipefail | ||
|
||
export CI=true | ||
|
||
# enable extended globbing for omitting build artifacts | ||
shopt -s extglob | ||
|
||
# avoid copying build artifacts from the host | ||
cp -r ../package/!(node_modules|dist|dist-cjs|dist-esm|build|.next|.turbo) . | ||
|
||
mkdir ../langchain | ||
cp -r ../langchain-workspace/!(node_modules|build|.next|.turbo) ../langchain | ||
|
||
# Link the package locally | ||
cd ../langchain | ||
bun link | ||
|
||
# Reinstall deps with bun because bun doesn't install deps of linked deps | ||
bun install --no-save | ||
|
||
cd ../app | ||
|
||
# Replace the workspace dependency with the local copy, and install all others | ||
sed -i 's/"langchain": "workspace:\*"/"langchain": "link:langchain"/g' package.json | ||
bun install --no-save | ||
|
||
# Check the build command completes successfully | ||
bun run build | ||
|
||
# Check the test command completes successfully | ||
bun run test |
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,29 @@ | ||
{ | ||
"name": "test-exports-bun", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "Tests for the things exported by the langchain package", | ||
"main": "./index.mjs", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc", | ||
"test": "bun run test:esm && bun run test:cjs && bun run test:cjs:import && bun run test:entrypoints && bun run test:ts", | ||
"test:esm": "bun src/index.js", | ||
"test:cjs": "bun src/require.cjs", | ||
"test:cjs:import": "bun src/import.cjs", | ||
"test:entrypoints": "bun src/entrypoints.js", | ||
"test:ts": "bun dist/index.js" | ||
}, | ||
"author": "LangChain", | ||
"license": "MIT", | ||
"dependencies": { | ||
"d3-dsv": "2", | ||
"hnswlib-node": "^1.4.2", | ||
"langchain": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@tsconfig/recommended": "^1.0.2", | ||
"@types/node": "^18.15.11", | ||
"typescript": "^5.0.0" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
environment_tests/test-exports-bun/scripts/combine-dependencies.js
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,8 @@ | ||
import * as fs from "fs"; | ||
|
||
const langchainPackageJson = JSON.parse(fs.readFileSync("../langchain/package.json")); | ||
const testPackageJson = JSON.parse(fs.readFileSync("./package.json")); | ||
|
||
testPackageJson.dependencies = { ...testPackageJson.dependencies, ...langchainPackageJson.dependencies }; | ||
|
||
fs.writeFileSync("./package.json", JSON.stringify(testPackageJson, null, 2)); |
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,69 @@ | ||
export * from "langchain/load"; | ||
export * from "langchain/load/serializable"; | ||
export * from "langchain/agents"; | ||
export * from "langchain/agents/toolkits"; | ||
export * from "langchain/base_language"; | ||
export * from "langchain/tools"; | ||
export * from "langchain/chains"; | ||
export * from "langchain/chains/openai_functions"; | ||
export * from "langchain/embeddings/base"; | ||
export * from "langchain/embeddings/cache_backed"; | ||
export * from "langchain/embeddings/fake"; | ||
export * from "langchain/embeddings/ollama"; | ||
export * from "langchain/embeddings/openai"; | ||
export * from "langchain/embeddings/minimax"; | ||
export * from "langchain/llms/base"; | ||
export * from "langchain/llms/openai"; | ||
export * from "langchain/llms/ai21"; | ||
export * from "langchain/llms/aleph_alpha"; | ||
export * from "langchain/llms/ollama"; | ||
export * from "langchain/prompts"; | ||
export * from "langchain/vectorstores/base"; | ||
export * from "langchain/vectorstores/memory"; | ||
export * from "langchain/vectorstores/prisma"; | ||
export * from "langchain/vectorstores/vectara"; | ||
export * from "langchain/vectorstores/xata"; | ||
export * from "langchain/text_splitter"; | ||
export * from "langchain/memory"; | ||
export * from "langchain/document"; | ||
export * from "langchain/document_loaders/base"; | ||
export * from "langchain/document_loaders/web/serpapi"; | ||
export * from "langchain/document_loaders/web/sort_xyz_blockchain"; | ||
export * from "langchain/document_transformers/openai_functions"; | ||
export * from "langchain/chat_models/base"; | ||
export * from "langchain/chat_models/openai"; | ||
export * from "langchain/chat_models/anthropic"; | ||
export * from "langchain/chat_models/baiduwenxin"; | ||
export * from "langchain/chat_models/ollama"; | ||
export * from "langchain/chat_models/minimax"; | ||
export * from "langchain/schema"; | ||
export * from "langchain/schema/document"; | ||
export * from "langchain/schema/output_parser"; | ||
export * from "langchain/schema/query_constructor"; | ||
export * from "langchain/schema/retriever"; | ||
export * from "langchain/schema/runnable"; | ||
export * from "langchain/schema/storage"; | ||
export * from "langchain/callbacks"; | ||
export * from "langchain/output_parsers"; | ||
export * from "langchain/retrievers/remote"; | ||
export * from "langchain/retrievers/databerry"; | ||
export * from "langchain/retrievers/contextual_compression"; | ||
export * from "langchain/retrievers/document_compressors"; | ||
export * from "langchain/retrievers/multi_vector"; | ||
export * from "langchain/retrievers/parent_document"; | ||
export * from "langchain/retrievers/time_weighted"; | ||
export * from "langchain/retrievers/document_compressors/chain_extract"; | ||
export * from "langchain/retrievers/hyde"; | ||
export * from "langchain/retrievers/score_threshold"; | ||
export * from "langchain/retrievers/vespa"; | ||
export * from "langchain/cache"; | ||
export * from "langchain/stores/doc/in_memory"; | ||
export * from "langchain/stores/file/in_memory"; | ||
export * from "langchain/stores/message/in_memory"; | ||
export * from "langchain/storage/in_memory"; | ||
export * from "langchain/util/math"; | ||
export * from "langchain/experimental/autogpt"; | ||
export * from "langchain/experimental/babyagi"; | ||
export * from "langchain/experimental/generative_agents"; | ||
export * from "langchain/experimental/plan_and_execute"; | ||
export * from "langchain/evaluation"; |
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,51 @@ | ||
async function test() { | ||
const { default: assert } = await import("assert"); | ||
const { OpenAI } = await import("langchain/llms/openai"); | ||
const { LLMChain } = await import("langchain/chains"); | ||
const { ChatPromptTemplate } = await import("langchain/prompts"); | ||
const { loadPrompt } = await import("langchain/prompts/load"); | ||
const { MemoryVectorStore } = await import("langchain/vectorstores/memory"); | ||
const { OpenAIEmbeddings } = await import("langchain/embeddings/openai"); | ||
const { Document } = await import("langchain/document"); | ||
const { CSVLoader } = await import("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 MemoryVectorStore === "function"); | ||
|
||
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" })); | ||
|
||
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); | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
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 { MemoryVectorStore } from "langchain/vectorstores/memory"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
import { Document } from "langchain/document"; | ||
import { CSVLoader } from "langchain/document_loaders/fs/csv"; | ||
import { CallbackManager } from "langchain/callbacks"; | ||
|
||
// Test exports | ||
assert(typeof OpenAI === "function"); | ||
assert(typeof LLMChain === "function"); | ||
assert(typeof loadPrompt === "function"); | ||
assert(typeof ChatPromptTemplate === "function"); | ||
assert(typeof MemoryVectorStore === "function"); | ||
assert(typeof OpenAIEmbeddings === "function"); | ||
assert(typeof CallbackManager === "function"); | ||
|
||
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" })); | ||
|
||
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); |
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,69 @@ | ||
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 { MemoryVectorStore } from "langchain/vectorstores/memory"; | ||
import { OpenAIEmbeddings } from "langchain/embeddings/openai"; | ||
import { Document } from "langchain/document"; | ||
import { CSVLoader } from "langchain/document_loaders/fs/csv"; | ||
|
||
async function test(useAzure: boolean = false) { | ||
// Test exports | ||
assert(typeof OpenAI === "function"); | ||
assert(typeof LLMChain === "function"); | ||
assert(typeof loadPrompt === "function"); | ||
assert(typeof ChatPromptTemplate === "function"); | ||
assert(typeof MemoryVectorStore === "function"); | ||
|
||
// Test dynamic imports of peer dependencies | ||
const openAIParameters = useAzure | ||
? { | ||
azureOpenAIApiKey: "sk-XXXX", | ||
azureOpenAIApiInstanceName: "XXXX", | ||
azureOpenAIApiDeploymentName: "XXXX", | ||
azureOpenAIApiVersion: "XXXX", | ||
} | ||
: { | ||
openAIApiKey: "sk-XXXX", | ||
}; | ||
|
||
const vs = new MemoryVectorStore(new OpenAIEmbeddings(openAIParameters)); | ||
|
||
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); | ||
} | ||
|
||
test(false) | ||
.then(() => console.log("openAI Api success")) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); | ||
test(true) | ||
.then(() => console.log("Azure openAI Api 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
const assert = require("assert"); | ||
const { OpenAI } = require("langchain/llms/openai"); | ||
const { LLMChain } = require("langchain/chains"); | ||
const { ChatPromptTemplate } = require("langchain/prompts"); | ||
const { loadPrompt } = require("langchain/prompts/load"); | ||
const { MemoryVectorStore } = require("langchain/vectorstores/memory"); | ||
const { OpenAIEmbeddings } = require("langchain/embeddings/openai"); | ||
const { Document } = require("langchain/document"); | ||
const { CSVLoader } = require("langchain/document_loaders/fs/csv"); | ||
|
||
async function test() { | ||
// Test exports | ||
assert(typeof OpenAI === "function"); | ||
assert(typeof LLMChain === "function"); | ||
assert(typeof loadPrompt === "function"); | ||
assert(typeof ChatPromptTemplate === "function"); | ||
assert(typeof MemoryVectorStore === "function"); | ||
|
||
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" })); | ||
|
||
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); | ||
} | ||
|
||
test() | ||
.then(() => console.log("success")) | ||
.catch((e) => { | ||
console.error(e); | ||
process.exit(1); | ||
}); |
Oops, something went wrong.