Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jun 11, 2024
1 parent dda57e7 commit 1e11134
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 98 deletions.
4 changes: 0 additions & 4 deletions libs/langchain-google-vertexai-web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
"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%",
"test:standard:unit": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard:int": "NODE_OPTIONS=--experimental-vm-modules jest --testPathPattern=\\.standard\\.int\\.test.ts --testTimeout 100000 --maxWorkers=50%",
"test:standard": "yarn test:standard:unit && yarn test:standard:int",
"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",
Expand All @@ -49,7 +46,6 @@
"devDependencies": {
"@jest/globals": "^29.5.0",
"@langchain/scripts": "~0.0.14",
"@langchain/standard-tests": "0.0.0",
"@swc/core": "^1.3.90",
"@swc/jest": "^0.2.29",
"@tsconfig/recommended": "^1.0.3",
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,30 @@ GoogleAIBaseLanguageModelCallOptions,
},
});
}

async testUsageMetadataStreaming() {
this.skipTestMessage(
"testUsageMetadataStreaming",
"ChatVertexAI",
"Streaming tokens is not currently supported."
);
}

async testUsageMetadata() {
this.skipTestMessage(
"testUsageMetadata",
"ChatVertexAI",
"Usage metadata tokens is not currently supported."
);
}

async testToolMessageHistoriesListContent() {
this.skipTestMessage(
"testToolMessageHistoriesListContent",
"ChatVertexAI",
"Not implemented."
);
}
}

const testClass = new ChatVertexAIStandardIntegrationTests();
Expand Down
49 changes: 32 additions & 17 deletions libs/langchain-standard-tests/src/integration_tests/chat_models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,29 +36,44 @@ class AdderTool extends StructuredTool {
}
}

interface ChatModelIntegrationTestsFields<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk,
ConstructorArgs extends RecordStringAny = RecordStringAny
> extends BaseChatModelsTestsFields<CallOptions, OutputMessageType, ConstructorArgs> {
/**
* Override the default AIMessage response type
* to check for.
* @default AIMessage
*/
invokeResponseType?: typeof AIMessage | typeof AIMessageChunk;
/**
* The ID to set for function calls.
* Set this field to override the default function ID.
* @default "abc123"
*/
functionId?: string;
}

export abstract class ChatModelIntegrationTests<
CallOptions extends BaseChatModelCallOptions = BaseChatModelCallOptions,
OutputMessageType extends BaseMessageChunk = BaseMessageChunk,
ConstructorArgs extends RecordStringAny = RecordStringAny
> extends BaseChatModelsTests<CallOptions, OutputMessageType, ConstructorArgs> {
functionId = "abc123";

invokeResponseType: typeof AIMessage | typeof AIMessageChunk = AIMessage;

constructor(
fields: BaseChatModelsTestsFields<
fields: ChatModelIntegrationTestsFields<
CallOptions,
OutputMessageType,
ConstructorArgs
> & {
/**
* The ID to set for function calls.
* Set this field to override the default function ID.
* @default "abc123"
*/
functionId?: string;
}
>
) {
super(fields);
this.functionId = fields.functionId ?? this.functionId;
this.invokeResponseType = fields.invokeResponseType ?? this.invokeResponseType;
}

async testInvoke(
Expand All @@ -67,7 +82,7 @@ export abstract class ChatModelIntegrationTests<
const chatModel = new this.Cls(this.constructorArgs);
const result = await chatModel.invoke("Hello", callOptions);
expect(result).toBeDefined();
expect(result).toBeInstanceOf(AIMessage);
expect(result).toBeInstanceOf(this.invokeResponseType);
expect(typeof result.content).toBe("string");
expect(result.content.length).toBeGreaterThan(0);
}
Expand Down Expand Up @@ -98,7 +113,7 @@ export abstract class ChatModelIntegrationTests<
expect(batchResults.length).toBe(2);
for (const result of batchResults) {
expect(result).toBeDefined();
expect(result).toBeInstanceOf(AIMessage);
expect(result).toBeInstanceOf(this.invokeResponseType);
expect(typeof result.content).toBe("string");
expect(result.content.length).toBeGreaterThan(0);
}
Expand All @@ -115,7 +130,7 @@ export abstract class ChatModelIntegrationTests<
];
const result = await chatModel.invoke(messages, callOptions);
expect(result).toBeDefined();
expect(result).toBeInstanceOf(AIMessage);
expect(result).toBeInstanceOf(this.invokeResponseType);
expect(typeof result.content).toBe("string");
expect(result.content.length).toBeGreaterThan(0);
}
Expand All @@ -126,7 +141,7 @@ export abstract class ChatModelIntegrationTests<
const chatModel = new this.Cls(this.constructorArgs);
const result = await chatModel.invoke("Hello", callOptions);
expect(result).toBeDefined();
expect(result).toBeInstanceOf(AIMessage);
expect(result).toBeInstanceOf(this.invokeResponseType);
if (!("usage_metadata" in result)) {
throw new Error("result is not an instance of AIMessage");
}
Expand Down Expand Up @@ -211,7 +226,7 @@ export abstract class ChatModelIntegrationTests<
messagesStringContent,
callOptions
);
expect(resultStringContent).toBeInstanceOf(AIMessage);
expect(resultStringContent).toBeInstanceOf(this.invokeResponseType);
}

/**
Expand Down Expand Up @@ -269,7 +284,7 @@ export abstract class ChatModelIntegrationTests<
messagesListContent,
callOptions
);
expect(resultListContent).toBeInstanceOf(AIMessage);
expect(resultListContent).toBeInstanceOf(this.invokeResponseType);
}

/**
Expand Down Expand Up @@ -317,7 +332,7 @@ export abstract class ChatModelIntegrationTests<
messagesStringContent,
callOptions
);
expect(resultStringContent).toBeInstanceOf(AIMessage);
expect(resultStringContent).toBeInstanceOf(this.invokeResponseType);
}

async testWithStructuredOutput() {
Expand Down Expand Up @@ -358,7 +373,7 @@ export abstract class ChatModelIntegrationTests<
});

const resultStringContent = await modelWithTools.invoke("What is 1 + 2");
expect(resultStringContent.raw).toBeInstanceOf(AIMessage);
expect(resultStringContent.raw).toBeInstanceOf(this.invokeResponseType);
expect(resultStringContent.parsed.a).toBeDefined();
expect([1, 2].includes(resultStringContent.parsed.a)).toBeTruthy();
expect(resultStringContent.parsed.b).toBeDefined();
Expand Down
1 change: 0 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9789,7 +9789,6 @@ __metadata:
"@langchain/core": ">0.1.56 <0.3.0"
"@langchain/google-webauth": ~0.0.18
"@langchain/scripts": ~0.0.14
"@langchain/standard-tests": 0.0.0
"@swc/core": ^1.3.90
"@swc/jest": ^0.2.29
"@tsconfig/recommended": ^1.0.3
Expand Down

0 comments on commit 1e11134

Please sign in to comment.