Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(langchain): Respect split model name for initChatModel #7716

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/src/models/chat/configurable/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const gpt4o = await initChatModel("gpt-4o", {
});

// You can also specify the model provider in the model name like this in
// langchain>=0.3.17:
// langchain>=0.3.18:

// Returns a @langchain/anthropic ChatAnthropic instance.
const claudeOpus = await initChatModel("anthropic:claude-3-opus-20240229", {
Expand Down
12 changes: 9 additions & 3 deletions langchain/src/chat_models/tests/universal.int.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ test("Initialize non-configurable models", async () => {
});

test("Works with model provider in model name", async () => {
const gpt4 = await initChatModel("openai:gpt-4o-mini", {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let error: any;
const o3Mini = await initChatModel("openai:o3-mini", {
temperature: 0.25,
apiKey: openAIApiKey,
});
const result = await gpt4.invoke("what's your name");
expect(result).toBeDefined();
try {
await o3Mini.invoke("what's your name");
} catch (e) {
error = e;
}
expect(error.message).toContain("temperature");
});

test("Create a partially configurable model with no default model", async () => {
Expand Down
2 changes: 1 addition & 1 deletion langchain/src/chat_models/universal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ export async function initChatModel<
...(fields ?? {}),
};
if (modelProvider === undefined && model?.includes(":")) {
const modelComponents = model.split(":", 1);
const modelComponents = model.split(":", 2);
if (
_SUPPORTED_PROVIDERS.includes(modelComponents[0] as ChatModelProvider)
) {
Expand Down
Loading