Skip to content

Commit 28eceac

Browse files
sapenleihntrl
andauthored
fix(chat): enhance model name parsing to preserve full model name wit… (#9244)
Co-authored-by: Hunter Lovell <[email protected]>
1 parent 6426eb6 commit 28eceac

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"langchain": patch
3+
---
4+
5+
preserve full model name when deciding model provider

libs/langchain/src/chat_models/tests/universal.int.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,3 +807,19 @@ describe("Can be initialized without `modelProvider`", () => {
807807
expect(modelResult.content.length).toBeGreaterThan(0);
808808
});
809809
});
810+
811+
describe.skip("Model name parsing with multiple colons preserves full model name", () => {
812+
test.each([
813+
"ollama:qwen2.5:14b",
814+
"ollama:llama3:8b",
815+
"ollama:deepseek-r1:1.5b",
816+
])("for %s", async (modelName) => {
817+
const model = await initChatModel(modelName, {
818+
temperature: 0,
819+
});
820+
821+
const modelResult = await model.invoke("what's your name");
822+
expect(modelResult).toBeDefined();
823+
expect(modelResult.content.length).toBeGreaterThan(0);
824+
});
825+
});

libs/langchain/src/chat_models/universal.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,11 @@ export async function initChatModel<
855855
...(fields ?? {}),
856856
};
857857
if (modelProvider === undefined && model?.includes(":")) {
858-
const modelComponents = model.split(":", 2);
858+
const [provider, ...remainingParts] = model.split(":");
859+
const modelComponents =
860+
remainingParts.length === 0
861+
? [provider]
862+
: [provider, remainingParts.join(":")];
859863
if (SUPPORTED_PROVIDERS.includes(modelComponents[0] as ChatModelProvider)) {
860864
// eslint-disable-next-line no-param-reassign
861865
[modelProvider, model] = modelComponents;

0 commit comments

Comments
 (0)