Skip to content

Commit

Permalink
fix(core,langchain,community): Update LangSmith deps, lighten export …
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 authored and FilipZmijewski committed Sep 27, 2024
1 parent a410091 commit 6ca4cd7
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 270 deletions.
1 change: 0 additions & 1 deletion environment_tests/test-exports-cf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"@langchain/core": "workspace:*",
"@langchain/openai": "workspace:*",
"@tsconfig/recommended": "^1.0.2",
"d3-dsv": "2",
"langchain": "workspace:*",
"wrangler": "^3.19.0",
"vitest": "0.34.3",
Expand Down
17 changes: 8 additions & 9 deletions environment_tests/test-exports-cf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import "./entrypoints.js";

// Import a few things we'll use to test the exports
import { LLMChain } from "langchain/chains";
import { ChatOpenAI } from "@langchain/openai";
import {
ChatPromptTemplate,
HumanMessagePromptTemplate,
} from "@langchain/core/prompts";
import { OpenAI } from "@langchain/openai";
import { OpenAIEmbeddings } from "@langchain/openai";
import { StringOutputParser } from "@langchain/core/output_parsers";
import { MemoryVectorStore } from "langchain/vectorstores/memory";

export interface Env {
OPENAI_API_KEY?: string;
Expand Down Expand Up @@ -51,14 +52,12 @@ export default {
const emb = new OpenAIEmbeddings(constructorParameters);

// Test a chain + prompt + model
const chain = new LLMChain({
llm: new ChatOpenAI(constructorParameters),
prompt: ChatPromptTemplate.fromMessages([
HumanMessagePromptTemplate.fromTemplate("{input}"),
]),
});
const res = await chain.run("hello");

const prompt = ChatPromptTemplate.fromMessages([
HumanMessagePromptTemplate.fromTemplate("{input}"),
]);
const llm = new ChatOpenAI(constructorParameters);
const chain = prompt.pipe(llm).pipe(new StringOutputParser());
const res = await chain.invoke("hello");
return new Response(
`Hello, from Cloudflare Worker at ${request.url}. Assistant says: ${res}`
);
Expand Down
2 changes: 0 additions & 2 deletions environment_tests/test-exports-cjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
"@langchain/openai": "workspace:*",
"@tsconfig/recommended": "^1.0.2",
"@xenova/transformers": "^2.17.2",
"d3-dsv": "2",
"hnswlib-node": "^3.0.0",
"langchain": "workspace:*",
"typescript": "^5.0.0"
},
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-cjs/src/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ async function test() {
const { OpenAI } = await import("@langchain/openai");
const { LLMChain } = await import("langchain/chains");
const { ChatPromptTemplate } = await import("@langchain/core/prompts");
const { HNSWLib } = await import("@langchain/community/vectorstores/hnswlib");
const { HuggingFaceTransformersEmbeddings } = await import("@langchain/community/embeddings/hf_transformers");
const { Document } = await import("@langchain/core/documents");
const { MemoryVectorStore } = await import("langchain/vectorstores/memory");

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();

const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }));

await vs.addVectors(
[
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-cjs/src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from "assert";
import { OpenAI } from "@langchain/openai";
import { LLMChain } from "langchain/chains";
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { HuggingFaceTransformersEmbeddings } from "@langchain/community/embeddings/hf_transformers";
import { Document } from "@langchain/core/documents";
Expand All @@ -10,16 +10,9 @@ import { Document } from "@langchain/core/documents";
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();

const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }));

await vs.addVectors(
[
Expand Down
12 changes: 4 additions & 8 deletions environment_tests/test-exports-cjs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "assert";
import { OpenAI } from "@langchain/openai";
import { LLMChain } from "langchain/chains";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { HuggingFaceTransformersEmbeddings } from "@langchain/community/embeddings/hf_transformers";
import { Document } from "@langchain/core/documents";

Expand All @@ -11,10 +11,9 @@ async function test(useAzure: boolean = false) {
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();
const openAIParameters = useAzure
? {
azureOpenAIApiKey: "sk-XXXX",
Expand All @@ -25,11 +24,8 @@ async function test(useAzure: boolean = false) {
: {
openAIApiKey: "sk-XXXX",
};
const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});

const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }));

await vs.addVectors(
[
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-cjs/src/require.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require("assert");
const { OpenAI } = require("@langchain/openai");
const { LLMChain } = require("langchain/chains");
const { ChatPromptTemplate } = require("@langchain/core/prompts");
const { HNSWLib } = require("@langchain/community/vectorstores/hnswlib");
const { MemoryVectorStore } = require("langchain/vectorstores/memory");
const { HuggingFaceTransformersEmbeddings } = require("@langchain/community/embeddings/hf_transformers");
const { Document } = require("@langchain/core/documents");

Expand All @@ -11,16 +11,9 @@ async function test() {
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();

const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2" }));

await vs.addVectors(
[
Expand Down
1 change: 0 additions & 1 deletion environment_tests/test-exports-esbuild/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@langchain/openai": "workspace:*",
"@tsconfig/recommended": "^1.0.2",
"esbuild": "^0.17.18",
"hnswlib-node": "^3.0.0",
"langchain": "workspace:*",
"typescript": "^5.0.0"
},
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-esbuild/src/import.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ async function test() {
const { OpenAI } = await import("@langchain/openai");
const { LLMChain } = await import("langchain/chains");
const { ChatPromptTemplate } = await import("@langchain/core/prompts");
const { HNSWLib } = await import("@langchain/community/vectorstores/hnswlib");
const { MemoryVectorStore } = await import("langchain/vectorstores/memory");
const { OpenAIEmbeddings } = await import("@langchain/openai");
const { Document } = await import("@langchain/core/documents");

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "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),
});
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" }));

await vs.addVectors(
[
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-esbuild/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "assert";
import { OpenAI } from "@langchain/openai";
import { LLMChain } from "langchain/chains";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";
import { CallbackManager } from "@langchain/core/callbacks/manager";
Expand All @@ -11,18 +11,11 @@ import { CallbackManager } from "@langchain/core/callbacks/manager";
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");
assert(typeof OpenAIEmbeddings === "function");
assert(typeof CallbackManager === "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),
});
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" }));

await vs.addVectors(
[
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-esbuild/src/require.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const assert = require("assert");
const { OpenAI } = require("@langchain/openai");
const { LLMChain } = require("langchain/chains");
const { ChatPromptTemplate } = require("@langchain/core/prompts");
const { HNSWLib } = require("@langchain/community/vectorstores/hnswlib");
const { MemoryVectorStore } = require("langchain/vectorstores/memory");
const { OpenAIEmbeddings } = require("@langchain/openai");
const { Document } = require("@langchain/core/documents");

Expand All @@ -11,16 +11,9 @@ async function test() {
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "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),
});
const vs = new MemoryVectorStore(new OpenAIEmbeddings({ openAIApiKey: "sk-XXXX" }));

await vs.addVectors(
[
Expand Down
12 changes: 3 additions & 9 deletions environment_tests/test-exports-esbuild/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "assert";
import { OpenAI } from "@langchain/openai";
import { LLMChain } from "langchain/chains";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { OpenAIEmbeddings } from "@langchain/openai";
import { Document } from "@langchain/core/documents";

Expand All @@ -11,10 +11,8 @@ async function test(useAzure: boolean = false) {
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();
const openAIParameters = useAzure
? {
azureOpenAIApiKey: "sk-XXXX",
Expand All @@ -26,11 +24,7 @@ async function test(useAzure: boolean = false) {
openAIApiKey: "sk-XXXX",
};

const vs = new HNSWLib(new OpenAIEmbeddings(openAIParameters), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new OpenAIEmbeddings(openAIParameters));

await vs.addVectors(
[
Expand Down
1 change: 0 additions & 1 deletion environment_tests/test-exports-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"@langchain/openai": "workspace:*",
"@tsconfig/recommended": "^1.0.2",
"@xenova/transformers": "^2.17.2",
"hnswlib-node": "^3.0.0",
"langchain": "workspace:*",
"typescript": "^5.0.0"
},
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-esm/src/import.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ async function test() {
const { OpenAI } = await import("@langchain/openai");
const { LLMChain } = await import("langchain/chains");
const { ChatPromptTemplate } = await import("@langchain/core/prompts");
const { HNSWLib } = await import("@langchain/community/vectorstores/hnswlib");
const { MemoryVectorStore } = await import("langchain/vectorstores/memory");
const { HuggingFaceTransformersEmbeddings } = await import("@langchain/community/embeddings/hf_transformers");
const { Document } = await import("@langchain/core/documents");

// Test exports
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();

const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2", }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2", }));

await vs.addVectors(
[
Expand Down
13 changes: 3 additions & 10 deletions environment_tests/test-exports-esm/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from "assert";
import { OpenAI } from "@langchain/openai";
import { LLMChain } from "langchain/chains";
import { ChatPromptTemplate } from "@langchain/core/prompts";
import { HNSWLib } from "@langchain/community/vectorstores/hnswlib";
import { MemoryVectorStore } from "langchain/vectorstores/memory";
import { HuggingFaceTransformersEmbeddings } from "@langchain/community/embeddings/hf_transformers";
import { Document } from "@langchain/core/documents";
import { CallbackManager } from "@langchain/core/callbacks/manager";
Expand All @@ -11,18 +11,11 @@ import { CallbackManager } from "@langchain/core/callbacks/manager";
assert(typeof OpenAI === "function");
assert(typeof LLMChain === "function");
assert(typeof ChatPromptTemplate === "function");
assert(typeof HNSWLib === "function");
assert(typeof MemoryVectorStore === "function");
assert(typeof HuggingFaceTransformersEmbeddings === "function");
assert(typeof CallbackManager === "function");

// Test dynamic imports of peer dependencies
const { HierarchicalNSW } = await HNSWLib.imports();

const vs = new HNSWLib(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2", }), {
space: "ip",
numDimensions: 3,
index: new HierarchicalNSW("ip", 3),
});
const vs = new MemoryVectorStore(new HuggingFaceTransformersEmbeddings({ model: "Xenova/all-MiniLM-L6-v2", }));

await vs.addVectors(
[
Expand Down
Loading

0 comments on commit 6ca4cd7

Please sign in to comment.