diff --git a/libs/langchain-standard-tests/src/integration_tests/chat_models.ts b/libs/langchain-standard-tests/src/integration_tests/chat_models.ts index 8fff150f1cf5..5fdb651e2a7d 100644 --- a/libs/langchain-standard-tests/src/integration_tests/chat_models.ts +++ b/libs/langchain-standard-tests/src/integration_tests/chat_models.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ + import { expect } from "@jest/globals"; import { BaseChatModelCallOptions } from "@langchain/core/language_models/chat_models"; import { @@ -112,11 +114,11 @@ export abstract class ChatModelIntegrationTests< * 1. The result is defined and is an instance of the correct type. * 2. The content of the response is a non-empty string. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testInvoke( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Create a new instance of the chat model const chatModel = new this.Cls(this.constructorArgs); @@ -147,11 +149,11 @@ export abstract class ChatModelIntegrationTests< * 2. The content of each token is a string. * 3. The total number of characters streamed is greater than zero. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testStream( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { const chatModel = new this.Cls(this.constructorArgs); let numChars = 0; @@ -183,11 +185,11 @@ export abstract class ChatModelIntegrationTests< * 2. The number of results matches the number of inputs. * 3. Each result is of the correct type and has non-empty content. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testBatch( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { const chatModel = new this.Cls(this.constructorArgs); @@ -229,11 +231,11 @@ export abstract class ChatModelIntegrationTests< * * Finally, it verifies the final chunk's `event.data.output` field * matches the concatenated content of all `on_chat_model_stream` events. - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testStreamEvents( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { const chatModel = new this.Cls(this.constructorArgs); @@ -300,11 +302,11 @@ export abstract class ChatModelIntegrationTests< * 1. The result is defined and is an instance of the correct response type. * 2. The content of the response is a non-empty string. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testConversation( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Create a new instance of the chat model const chatModel = new this.Cls(this.constructorArgs); @@ -343,11 +345,11 @@ export abstract class ChatModelIntegrationTests< * 3. The `usage_metadata` field contains `input_tokens`, `output_tokens`, and `total_tokens`, * all of which are numbers. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testUsageMetadata( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Create a new instance of the chat model const chatModel = new this.Cls(this.constructorArgs); @@ -393,11 +395,11 @@ export abstract class ChatModelIntegrationTests< * 3. The `usage_metadata` field contains `input_tokens`, `output_tokens`, and `total_tokens`, * all of which are numbers. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testUsageMetadataStreaming( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { const chatModel = new this.Cls(this.constructorArgs); let finalChunks: AIMessageChunk | undefined; @@ -451,11 +453,11 @@ export abstract class ChatModelIntegrationTests< * This test ensures that the model can correctly process and respond to complex message * histories that include tool calls with string-based content structures. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testToolMessageHistoriesStringContent( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support tool calling if (!this.chatModelHasToolCalling) { @@ -522,10 +524,10 @@ export abstract class ChatModelIntegrationTests< * This test ensures that the model can correctly process and respond to complex message * histories that include tool calls with list-based content structures. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. */ async testToolMessageHistoriesListContent( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { if (!this.chatModelHasToolCalling) { console.log("Test requires tool calling. Skipping..."); @@ -602,11 +604,11 @@ export abstract class ChatModelIntegrationTests< * the patterns demonstrated in few-shot examples, particularly when those * examples involve tool usage. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testStructuredFewShotExamples( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support tool calling if (!this.chatModelHasToolCalling) { @@ -667,11 +669,11 @@ export abstract class ChatModelIntegrationTests< * This test is crucial for ensuring that the model can generate responses * in a specific format, which is useful for tasks requiring structured data output. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testWithStructuredOutput( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support structured output if (!this.chatModelHasStructuredOutput) { @@ -726,11 +728,11 @@ export abstract class ChatModelIntegrationTests< * This test is crucial for ensuring that the model can generate responses in a specific format * while also providing access to the original, unprocessed model output. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testWithStructuredOutputIncludeRaw( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support structured output if (!this.chatModelHasStructuredOutput) { @@ -788,11 +790,11 @@ export abstract class ChatModelIntegrationTests< * This test is crucial for ensuring compatibility with OpenAI's function * calling format, which is a common standard in AI tool integration. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testBindToolsWithOpenAIFormattedTools( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support tool calling if (!this.chatModelHasToolCalling) { @@ -855,11 +857,11 @@ export abstract class ChatModelIntegrationTests< * from Runnable objects, which provides a flexible way to integrate * custom logic into the model's tool-calling capabilities. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testBindToolsWithRunnableToolLike( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support tool calling if (!this.chatModelHasToolCalling) { @@ -923,11 +925,11 @@ export abstract class ChatModelIntegrationTests< * This test is crucial for ensuring that the caching mechanism works correctly * with various message structures, maintaining consistency and efficiency. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testCacheComplexMessageTypes( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Create a new instance of the chat model with caching enabled const model = new this.Cls({ @@ -987,11 +989,11 @@ export abstract class ChatModelIntegrationTests< * 3. The usage metadata is present in the streamed result. * 4. Both input and output tokens are present and greater than zero in the usage metadata. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testStreamTokensWithToolCalls( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { const model = new this.Cls(this.constructorArgs); if (!model.bindTools) { @@ -1053,11 +1055,11 @@ export abstract class ChatModelIntegrationTests< * 5. Send a followup request including the tool call and response. * 6. Verify the model generates a non-empty final response. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testModelCanUseToolUseAIMessage( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { if (!this.chatModelHasToolCalling) { console.log("Test requires tool calling. Skipping..."); @@ -1147,11 +1149,11 @@ export abstract class ChatModelIntegrationTests< * 5. Stream a followup request including the tool call and response. * 6. Verify the model generates a non-empty final streamed response. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testModelCanUseToolUseAIMessageWithStreaming( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { if (!this.chatModelHasToolCalling) { console.log("Test requires tool calling. Skipping..."); @@ -1253,11 +1255,11 @@ export abstract class ChatModelIntegrationTests< * This test is particularly important for ensuring compatibility with APIs * that may not accept JSON schemas with unknown object fields (e.g., Google's API). * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * These options will be applied to the model at runtime. */ async testInvokeMoreComplexTools( - callOptions?: InstanceType["ParsedCallOptions"] + callOptions?: any ) { // Skip the test if the model doesn't support tool calling if (!this.chatModelHasToolCalling) { @@ -1333,11 +1335,11 @@ Extraction path: {extractionPath}`, * It ensures that the model can correctly process and respond to prompts requiring multiple tool calls, * both in streaming and non-streaming contexts, and can handle message histories with parallel tool calls. * - * @param {InstanceType["ParsedCallOptions"] | undefined} callOptions Optional call options to pass to the model. + * @param {any | undefined} callOptions Optional call options to pass to the model. * @param {boolean} onlyVerifyHistory If true, only verifies the message history test. */ async testParallelToolCalling( - callOptions?: InstanceType["ParsedCallOptions"], + callOptions?: any, onlyVerifyHistory = false ) { // Skip the test if the model doesn't support tool calling