-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
anthropic[minor]: Add standard chat model tests to anthropic (#5659)
* anthropic[minor]: Add standard chat model tests to anthropic * format
- Loading branch information
1 parent
840e787
commit 7d7b5ad
Showing
5 changed files
with
89 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
libs/langchain-anthropic/src/tests/chat_models.standard.int.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable no-process-env */ | ||
import { test, expect } from "@jest/globals"; | ||
import { ChatModelIntegrationTests } from "@langchain/standard-tests"; | ||
import { AIMessageChunk } from "@langchain/core/messages"; | ||
import { ChatAnthropic, ChatAnthropicCallOptions } from "../chat_models.js"; | ||
|
||
class ChatAnthropicStandardIntegrationTests extends ChatModelIntegrationTests< | ||
ChatAnthropicCallOptions, | ||
AIMessageChunk | ||
> { | ||
constructor() { | ||
if (!process.env.ANTHROPIC_API_KEY) { | ||
throw new Error( | ||
"ANTHROPIC_API_KEY must be set to run standard integration tests." | ||
); | ||
} | ||
super({ | ||
Cls: ChatAnthropic, | ||
chatModelHasToolCalling: true, | ||
chatModelHasStructuredOutput: true, | ||
constructorArgs: { | ||
model: "claude-3-haiku-20240307", | ||
}, | ||
}); | ||
} | ||
|
||
async testUsageMetadataStreaming() { | ||
console.warn( | ||
"Skipping testUsageMetadataStreaming, not implemented in ChatAnthropic." | ||
); | ||
} | ||
} | ||
|
||
const testClass = new ChatAnthropicStandardIntegrationTests(); | ||
|
||
test("ChatAnthropicStandardIntegrationTests", async () => { | ||
const testResults = await testClass.runTests(); | ||
expect(testResults).toBe(true); | ||
}); |
39 changes: 39 additions & 0 deletions
39
libs/langchain-anthropic/src/tests/chat_models.standard.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* eslint-disable no-process-env */ | ||
import { test, expect } from "@jest/globals"; | ||
import { ChatModelUnitTests } from "@langchain/standard-tests"; | ||
import { AIMessageChunk } from "@langchain/core/messages"; | ||
import { ChatAnthropic, ChatAnthropicCallOptions } from "../chat_models.js"; | ||
|
||
class ChatAnthropicStandardUnitTests extends ChatModelUnitTests< | ||
ChatAnthropicCallOptions, | ||
AIMessageChunk | ||
> { | ||
constructor() { | ||
super({ | ||
Cls: ChatAnthropic, | ||
chatModelHasToolCalling: true, | ||
chatModelHasStructuredOutput: true, | ||
constructorArgs: {}, | ||
}); | ||
// This must be set so method like `.bindTools` or `.withStructuredOutput` | ||
// which we call after instantiating the model will work. | ||
// (constructor will throw if API key is not set) | ||
process.env.ANTHROPIC_API_KEY = "test"; | ||
} | ||
|
||
testChatModelInitApiKey() { | ||
// Unset the API key env var here so this test can properly check | ||
// the API key class arg. | ||
process.env.ANTHROPIC_API_KEY = ""; | ||
super.testChatModelInitApiKey(); | ||
// Re-set the API key env var here so other tests can run properly. | ||
process.env.ANTHROPIC_API_KEY = "test"; | ||
} | ||
} | ||
|
||
const testClass = new ChatAnthropicStandardUnitTests(); | ||
|
||
test("ChatAnthropicStandardUnitTests", () => { | ||
const testResults = testClass.runTests(); | ||
expect(testResults).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters