diff --git a/libs/langchain-standard-tests/.gitignore b/libs/langchain-standard-tests/.gitignore index ae701c7fe705..c10034e2f1be 100644 --- a/libs/langchain-standard-tests/.gitignore +++ b/libs/langchain-standard-tests/.gitignore @@ -1,3 +1,7 @@ +index.cjs +index.js +index.d.ts +index.d.cts node_modules dist .yarn diff --git a/libs/langchain-standard-tests/langchain.config.js b/libs/langchain-standard-tests/langchain.config.js index 46b1a2b31264..25a18707a316 100644 --- a/libs/langchain-standard-tests/langchain.config.js +++ b/libs/langchain-standard-tests/langchain.config.js @@ -14,7 +14,6 @@ export const config = { entrypoints: { index: "index", }, - requiresOptionalDependency: [], tsConfigPath: resolve("./tsconfig.json"), cjsSource: "./dist-cjs", cjsDestination: "./dist", diff --git a/libs/langchain-standard-tests/package.json b/libs/langchain-standard-tests/package.json index 8a33767a96f1..d25b4d51f886 100644 --- a/libs/langchain-standard-tests/package.json +++ b/libs/langchain-standard-tests/package.json @@ -14,26 +14,20 @@ }, "homepage": "https://github.com/langchain-ai/langchainjs/tree/main/libs/langchain-standard-tests/", "scripts": { - "build": "yarn clean && yarn build:esm && yarn build:cjs && yarn build:scripts", - "build:esm": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist/ && rm -rf dist/tests dist/**/tests", - "build:cjs": "NODE_OPTIONS=--max-old-space-size=4096 tsc --outDir dist-cjs/ -p tsconfig.cjs.json && yarn move-cjs-to-dist && rm -rf dist-cjs", - "build:watch": "yarn create-entrypoints && tsc --outDir dist/ --watch", - "build:scripts": "yarn create-entrypoints && yarn check-tree-shaking", + "build": "yarn turbo:command build:internal --filter=@langchain/standard-tests", + "build:internal": "yarn lc-build:v2 --create-entrypoints --pre --tree-shaking", "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/", "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts", "lint": "yarn lint:eslint && yarn lint:dpdm", "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm", - "clean": "rm -rf dist/ && NODE_OPTIONS=--max-old-space-size=4096 yarn lc-build --config ./langchain.config.js --create-entrypoints --pre", + "clean": "rm -rf .turbo dist/", "prepack": "yarn build", "test": "NODE_OPTIONS=--experimental-vm-modules jest --testPathIgnorePatterns=\\.int\\.test.ts --testTimeout 30000 --maxWorkers=50%", "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch --testPathIgnorePatterns=\\.int\\.test.ts", "test:single": "NODE_OPTIONS=--experimental-vm-modules yarn run jest --config jest.config.cjs --testTimeout 100000", "test:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%", "format": "prettier --config .prettierrc --write \"src\"", - "format:check": "prettier --config .prettierrc --check \"src\"", - "move-cjs-to-dist": "yarn lc-build --config ./langchain.config.js --move-cjs-dist", - "create-entrypoints": "yarn lc-build --config ./langchain.config.js --create-entrypoints", - "check-tree-shaking": "yarn lc-build --config ./langchain.config.js --tree-shaking" + "format:check": "prettier --config .prettierrc --check \"src\"" }, "author": "LangChain", "license": "MIT", @@ -69,7 +63,11 @@ }, "exports": { ".": { - "types": "./index.d.ts", + "types": { + "import": "./index.d.ts", + "require": "./index.d.cts", + "default": "./index.d.ts" + }, "import": "./index.js", "require": "./index.cjs" }, @@ -79,6 +77,7 @@ "dist/", "index.cjs", "index.js", - "index.d.ts" + "index.d.ts", + "index.d.cts" ] } diff --git a/libs/langchain-standard-tests/src/chat_models.ts b/libs/langchain-standard-tests/src/chat_models.ts deleted file mode 100644 index 7ead127849b1..000000000000 --- a/libs/langchain-standard-tests/src/chat_models.ts +++ /dev/null @@ -1,105 +0,0 @@ -import { type BaseMessage } from "@langchain/core/messages"; -import { type BaseLanguageModelCallOptions } from "@langchain/core/language_models/base"; - -import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager"; -import { - type BaseChatModelParams, - SimpleChatModel, -} from "@langchain/core/language_models/chat_models"; - -// Uncomment if implementing streaming - -// import { -// ChatGenerationChunk, -// } from "@langchain/core/outputs"; -// import { -// AIMessageChunk, -// } from "@langchain/core/messages"; - -/** - * Input to chat model class. - */ -export interface ChatIntegrationInput extends BaseChatModelParams {} - -/** - * Integration with a chat model. - */ -export class ChatIntegration< - CallOptions extends BaseLanguageModelCallOptions = BaseLanguageModelCallOptions - > - extends SimpleChatModel - implements ChatIntegrationInput -{ - // Used for tracing, replace with the same name as your class - static lc_name() { - return "ChatIntegration"; - } - - lc_serializable = true; - - /** - * Replace with any secrets this class passes to `super`. - * See {@link ../../langchain-cohere/src/chat_model.ts} for - * an example. - */ - get lc_secrets(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - get lc_aliases(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - constructor(fields?: ChatIntegrationInput) { - super(fields ?? {}); - } - - // Replace - _llmType() { - return "chat_integration"; - } - - /** - * For some given input messages and options, return a string output. - */ - _call( - _messages: BaseMessage[], - _options: this["ParsedCallOptions"], - _runManager?: CallbackManagerForLLMRun - ): Promise { - throw new Error("Not implemented."); - } - - /** - * Implement to support streaming. - * Should yield chunks iteratively. - */ - // async *_streamResponseChunks( - // messages: BaseMessage[], - // options: this["ParsedCallOptions"], - // runManager?: CallbackManagerForLLMRun - // ): AsyncGenerator { - // // All models have a built in `this.caller` property for retries - // const stream = await this.caller.call(async () => - // createStreamMethod() - // ); - // for await (const chunk of stream) { - // if (!chunk.done) { - // yield new ChatGenerationChunk({ - // text: chunk.response, - // message: new AIMessageChunk({ content: chunk.response }), - // }); - // await runManager?.handleLLMNewToken(chunk.response ?? ""); - // } - // } - // } - - /** @ignore */ - _combineLLMOutput() { - return []; - } -} diff --git a/libs/langchain-standard-tests/src/index.ts b/libs/langchain-standard-tests/src/index.ts index 564fb4a3c181..57ff0dc1b045 100644 --- a/libs/langchain-standard-tests/src/index.ts +++ b/libs/langchain-standard-tests/src/index.ts @@ -1,3 +1,2 @@ -export * from "./chat_models.js"; -export * from "./llms.js"; -export * from "./vectorstores.js"; +export * from "./unit_tests/chat_models.js"; +export * from "./integration_tests/chat_models.js"; diff --git a/libs/langchain-standard-tests/src/integration_tests/chat_models.ts b/libs/langchain-standard-tests/src/integration_tests/chat_models.ts new file mode 100644 index 000000000000..cb0ff5c3b541 --- /dev/null +++ b/libs/langchain-standard-tests/src/integration_tests/chat_models.ts @@ -0,0 +1 @@ +export {}; diff --git a/libs/langchain-standard-tests/src/llms.ts b/libs/langchain-standard-tests/src/llms.ts deleted file mode 100644 index 309de10163ed..000000000000 --- a/libs/langchain-standard-tests/src/llms.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager"; -import { LLM, type BaseLLMParams } from "@langchain/core/language_models/llms"; -import { type BaseLanguageModelCallOptions } from "@langchain/core/language_models/base"; - -// Uncomment if implementing streaming - -// import { -// GenerationChunk, -// } from "@langchain/core/outputs"; - -/** - * Input to LLM class. - */ -export interface LLMIntegrationInput extends BaseLLMParams {} - -/** - * Integration with an LLM. - */ -export class LLMIntegration - extends LLM - implements LLMIntegrationInput -{ - // Used for tracing, replace with the same name as your class - static lc_name() { - return "LLMIntegration"; - } - - lc_serializable = true; - - constructor(fields: LLMIntegrationInput) { - super(fields); - } - - // Replace - _llmType() { - return "llm_integration"; - } - - /** - * Replace with any secrets this class passes to `super`. - * See {@link ../../langchain-cohere/src/chat_model.ts} for - * an example. - */ - get lc_secrets(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - get lc_aliases(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - /** - * For some given input string and options, return a string output. - */ - async _call( - _prompt: string, - _options: this["ParsedCallOptions"], - _runManager?: CallbackManagerForLLMRun - ): Promise { - throw new Error("Not implemented."); - } - - /** - * Implement to support streaming. - * Should yield chunks iteratively. - */ - // async *_streamResponseChunks( - // prompt: string, - // options: this["ParsedCallOptions"], - // runManager?: CallbackManagerForLLMRun - // ): AsyncGenerator { - // const stream = await this.caller.call(async () => - // createStream() - // ); - // for await (const chunk of stream) { - // yield new GenerationChunk({ - // text: chunk.response, - // generationInfo: { - // ...chunk, - // response: undefined, - // }, - // }); - // await runManager?.handleLLMNewToken(chunk.response ?? ""); - // } - // } -} diff --git a/libs/langchain-standard-tests/src/tests/chat_models.test.ts b/libs/langchain-standard-tests/src/tests/chat_models.test.ts deleted file mode 100644 index 5d609f496501..000000000000 --- a/libs/langchain-standard-tests/src/tests/chat_models.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { test } from "@jest/globals"; - -test("Test chat model", async () => { - // Your test here -}); diff --git a/libs/langchain-standard-tests/src/tests/integration.int.test.ts b/libs/langchain-standard-tests/src/tests/integration.int.test.ts deleted file mode 100644 index 7fce4ce53302..000000000000 --- a/libs/langchain-standard-tests/src/tests/integration.int.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { test } from "@jest/globals"; - -test("Test chat model", async () => { - // Your integration test here -}); diff --git a/libs/langchain-standard-tests/src/tests/llms.test.ts b/libs/langchain-standard-tests/src/tests/llms.test.ts deleted file mode 100644 index 3428ecaaf599..000000000000 --- a/libs/langchain-standard-tests/src/tests/llms.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { test } from "@jest/globals"; - -test("Test LLM", async () => { - // Your test here -}); diff --git a/libs/langchain-standard-tests/src/tests/vectorstores.test.ts b/libs/langchain-standard-tests/src/tests/vectorstores.test.ts deleted file mode 100644 index 023cfbd8b77c..000000000000 --- a/libs/langchain-standard-tests/src/tests/vectorstores.test.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { test } from "@jest/globals"; - -test("Test vectorstore", async () => { - // Your test here -}); diff --git a/libs/langchain-standard-tests/src/unit_tests/chat_models.ts b/libs/langchain-standard-tests/src/unit_tests/chat_models.ts new file mode 100644 index 000000000000..cb0ff5c3b541 --- /dev/null +++ b/libs/langchain-standard-tests/src/unit_tests/chat_models.ts @@ -0,0 +1 @@ +export {}; diff --git a/libs/langchain-standard-tests/src/vectorstores.ts b/libs/langchain-standard-tests/src/vectorstores.ts deleted file mode 100644 index 5a24e3bba1db..000000000000 --- a/libs/langchain-standard-tests/src/vectorstores.ts +++ /dev/null @@ -1,100 +0,0 @@ -import type { EmbeddingsInterface } from "@langchain/core/embeddings"; -import { VectorStore } from "@langchain/core/vectorstores"; -import { Document } from "@langchain/core/documents"; - -/** - * Database config for your vectorstore. - */ -export interface VectorstoreIntegrationParams {} - -/** - * Class for managing and operating vector search applications with - * Tigris, an open-source Serverless NoSQL Database and Search Platform. - */ -export class VectorstoreIntegration extends VectorStore { - // Replace - _vectorstoreType(): string { - return "vectorstore_integration"; - } - - constructor( - embeddings: EmbeddingsInterface, - params: VectorstoreIntegrationParams - ) { - super(embeddings, params); - this.embeddings = embeddings; - } - - /** - * Replace with any secrets this class passes to `super`. - * See {@link ../../langchain-cohere/src/chat_model.ts} for - * an example. - */ - get lc_secrets(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - get lc_aliases(): { [key: string]: string } | undefined { - return { - apiKey: "API_KEY_NAME", - }; - } - - /** - * Method to add an array of documents to the vectorstore. - * - * Useful to override in case your vectorstore doesn't work directly with embeddings. - */ - async addDocuments( - documents: Document[], - options?: { ids?: string[] } | string[] - ): Promise { - const texts = documents.map(({ pageContent }) => pageContent); - await this.addVectors( - await this.embeddings.embedDocuments(texts), - documents, - options - ); - } - - /** - * Method to add raw vectors to the vectorstore. - */ - async addVectors( - _vectors: number[][], - _documents: Document[], - _options?: { ids?: string[] } | string[] - ) { - throw new Error("Not implemented."); - } - - /** - * Method to perform a similarity search over the vectorstore and return - * the k most similar vectors along with their similarity scores. - */ - async similaritySearchVectorWithScore( - _query: number[], - _k: number, - _filter?: object - ): Promise<[Document, number][]> { - throw new Error("Not implemented."); - } - - /** - * Static method to create a new instance of the vectorstore from an - * array of Document instances. - * - * Other common static initializer names are fromExistingIndex, initialize, and fromTexts. - */ - static async fromDocuments( - docs: Document[], - embeddings: EmbeddingsInterface, - dbConfig: VectorstoreIntegrationParams - ): Promise { - const instance = new this(embeddings, dbConfig); - await instance.addDocuments(docs); - return instance; - } -} diff --git a/libs/langchain-standard-tests/tsconfig.cjs.json b/libs/langchain-standard-tests/tsconfig.cjs.json index 3b7026ea406c..510d791e34ab 100644 --- a/libs/langchain-standard-tests/tsconfig.cjs.json +++ b/libs/langchain-standard-tests/tsconfig.cjs.json @@ -1,7 +1,6 @@ { "extends": "./tsconfig.json", "compilerOptions": { - "module": "commonjs", "declaration": false }, "exclude": ["node_modules", "dist", "docs", "**/tests"] diff --git a/libs/langchain-standard-tests/turbo.json b/libs/langchain-standard-tests/turbo.json new file mode 100644 index 000000000000..d024cee15c81 --- /dev/null +++ b/libs/langchain-standard-tests/turbo.json @@ -0,0 +1,11 @@ +{ + "extends": ["//"], + "pipeline": { + "build": { + "outputs": ["**/dist/**"] + }, + "build:internal": { + "dependsOn": ["^build:internal"] + } + } +}