Skip to content

Commit

Permalink
Relax typing in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Aug 1, 2024
1 parent 5cb5cfc commit df05fc9
Showing 1 changed file with 42 additions and 40 deletions.
82 changes: 42 additions & 40 deletions libs/langchain-standard-tests/src/integration_tests/chat_models.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Create a new instance of the chat model
const chatModel = new this.Cls(this.constructorArgs);
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
const chatModel = new this.Cls(this.constructorArgs);
let numChars = 0;
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
const chatModel = new this.Cls(this.constructorArgs);

Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
const chatModel = new this.Cls(this.constructorArgs);

Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Create a new instance of the chat model
const chatModel = new this.Cls(this.constructorArgs);
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Create a new instance of the chat model
const chatModel = new this.Cls(this.constructorArgs);
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
const chatModel = new this.Cls(this.constructorArgs);
let finalChunks: AIMessageChunk | undefined;
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support tool calling
if (!this.chatModelHasToolCalling) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
if (!this.chatModelHasToolCalling) {
console.log("Test requires tool calling. Skipping...");
Expand Down Expand Up @@ -602,11 +604,11 @@ export abstract class ChatModelIntegrationTests<
* the patterns demonstrated in few-shot examples, particularly when those
* examples involve tool usage.
*
* @param {InstanceType<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support tool calling
if (!this.chatModelHasToolCalling) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support structured output
if (!this.chatModelHasStructuredOutput) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support structured output
if (!this.chatModelHasStructuredOutput) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support tool calling
if (!this.chatModelHasToolCalling) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support tool calling
if (!this.chatModelHasToolCalling) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Create a new instance of the chat model with caching enabled
const model = new this.Cls({
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
const model = new this.Cls(this.constructorArgs);
if (!model.bindTools) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
if (!this.chatModelHasToolCalling) {
console.log("Test requires tool calling. Skipping...");
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
if (!this.chatModelHasToolCalling) {
console.log("Test requires tool calling. Skipping...");
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"]
callOptions?: any
) {
// Skip the test if the model doesn't support tool calling
if (!this.chatModelHasToolCalling) {
Expand Down Expand Up @@ -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<this["Cls"]>["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<this["Cls"]>["ParsedCallOptions"],
callOptions?: any,
onlyVerifyHistory = false
) {
// Skip the test if the model doesn't support tool calling
Expand Down

0 comments on commit df05fc9

Please sign in to comment.