Skip to content

Commit

Permalink
format n lint
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed May 31, 2024
1 parent 968a047 commit 6b1c916
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion libs/langchain-standard-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
"author": "LangChain",
"license": "MIT",
"dependencies": {
"@jest/globals": "^29.5.0",
"@langchain/core": "workspace:*",
"zod": "^3.22.4"
},
"devDependencies": {
"@jest/globals": "^29.5.0",
"@langchain/scripts": "workspace:*",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
Expand Down
7 changes: 4 additions & 3 deletions libs/langchain-standard-tests/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,26 @@ import { BaseMessageChunk } from "@langchain/core/messages";
export type BaseChatModelConstructor<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk
// eslint-disable-next-line @typescript-eslint/no-explicit-any
> = new (...args: any[]) => BaseChatModel<CallOptions, OutputMessageType>;

export type BaseChatModelsTestsFields<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk
> = {
cls: BaseChatModelConstructor<CallOptions, OutputMessageType>;
Cls: BaseChatModelConstructor<CallOptions, OutputMessageType>;
};

export class BaseChatModelsTests<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk
> implements BaseChatModelsTestsFields<CallOptions, OutputMessageType>
{
cls: BaseChatModelConstructor<CallOptions, OutputMessageType>;
Cls: BaseChatModelConstructor<CallOptions, OutputMessageType>;

constructor(
fields: BaseChatModelsTestsFields<CallOptions, OutputMessageType>
) {
this.cls = fields.cls;
this.Cls = fields.Cls;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import { BaseMessageChunk } from "@langchain/core/messages";
type BaseChatModelConstructor<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk
// eslint-disable-next-line @typescript-eslint/no-explicit-any
> = new (...args: any[]) => BaseChatModel<CallOptions, OutputMessageType>;

export class ChatModelsIntegrationTests<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk
> {
cls: BaseChatModel<CallOptions, OutputMessageType>;
Cls: BaseChatModel<CallOptions, OutputMessageType>;

constructor(cls: BaseChatModelConstructor<CallOptions, OutputMessageType>) {
this.cls = new cls();
constructor(Cls: BaseChatModelConstructor<CallOptions, OutputMessageType>) {
this.Cls = new Cls();
}
}
15 changes: 8 additions & 7 deletions libs/langchain-standard-tests/src/unit_tests/chat_models.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from "@jest/globals";
import { BaseChatModelsTests, BaseChatModelsTestsFields } from "../base.js";
import {
BaseChatModelCallOptions,
LangSmithParams,
Expand All @@ -9,6 +8,7 @@ import { z } from "zod";
import { StructuredTool } from "@langchain/core/tools";
import { ChatResult } from "@langchain/core/outputs";
import { CallbackManagerForLLMRun } from "@langchain/core/callbacks/manager";
import { BaseChatModelsTests, BaseChatModelsTestsFields } from "../base.js";

const person = z
.object({
Expand Down Expand Up @@ -43,19 +43,19 @@ export class ChatModelUnitTests<
}

testChatModelInit(constructorArgs: RecordStringAny) {
const chatModel = new this.cls(constructorArgs);
const chatModel = new this.Cls(constructorArgs);
expect(chatModel).toBeDefined();
}

testChatModelInitApiKey(constructorArgs: RecordStringAny) {
const params = { ...constructorArgs, apiKey: "test" };
const chatModel = new this.cls(params);
const chatModel = new this.Cls(params);
expect(chatModel).toBeDefined();
}

testChatModelInitStreaming(constructorArgs: RecordStringAny) {
const params = { ...constructorArgs, streaming: true };
const chatModel = new this.cls(params);
const chatModel = new this.Cls(params);
expect(chatModel).toBeDefined();
}

Expand All @@ -66,7 +66,7 @@ export class ChatModelUnitTests<
if (!chatModelHasToolCalling) {
return;
}
const chatModel = new this.cls(constructorArgs);
const chatModel = new this.Cls(constructorArgs);
expect(chatModel.bindTools?.([new PersonTool()])).toBeDefined();
}

Expand All @@ -77,7 +77,8 @@ export class ChatModelUnitTests<
if (!chatModelHasStructuredOutput) {
return;
}
const chatModel = new this.cls(constructorArgs);
const chatModel = new this.Cls(constructorArgs);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
expect((chatModel as any).withStructuredOutput?.(person)).toBeDefined();
}

Expand All @@ -90,7 +91,7 @@ export class ChatModelUnitTests<
ls_max_tokens: 0,
ls_stop: ["Array<string>"],
};
class ModelExtendsChatModel extends this.cls {
class ModelExtendsChatModel extends this.Cls {
constructor(fields: RecordStringAny) {
super(fields);
}
Expand Down

0 comments on commit 6b1c916

Please sign in to comment.