Skip to content

Commit bc8e90f

Browse files
authored
fix(langchain): patch prompts created from runs fix (#9586)
1 parent 163614e commit bc8e90f

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

.changeset/clever-bottles-yell.md

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+
patch prompts created from runs fix

libs/langchain/src/hub/node.ts

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,31 @@ import {
88
import { load } from "../load/index.js";
99
import { getChatModelByClassName } from "../chat_models/universal.js";
1010

11-
// TODO: Make this the default, add web entrypoint in next breaking release
12-
1311
export { basePush as push } from "./base.js";
1412

13+
function _idEquals(a: string[], b: string[]): boolean {
14+
if (!Array.isArray(a) || !Array.isArray(b)) {
15+
return false;
16+
}
17+
if (a.length !== b.length) {
18+
return false;
19+
}
20+
for (let i = 0; i < a.length; i++) {
21+
if (a[i] !== b[i]) {
22+
return false;
23+
}
24+
}
25+
return true;
26+
}
27+
28+
function isRunnableBinding(a: string[]): boolean {
29+
const wellKnownIds = [
30+
["langchain_core", "runnables", "RunnableBinding"],
31+
["langchain", "schema", "runnable", "RunnableBinding"],
32+
];
33+
return wellKnownIds.some((id) => _idEquals(a, id));
34+
}
35+
1536
/**
1637
* Pull a prompt from the hub.
1738
* @param ownerRepoCommit The name of the repo containing the prompt, as well as an optional commit hash separated by a slash.
@@ -33,9 +54,14 @@ export async function pull<T extends Runnable>(
3354
const promptObject = await basePull(ownerRepoCommit, options);
3455
let modelClass;
3556
if (options?.includeModel) {
36-
if (Array.isArray(promptObject.manifest.kwargs?.last?.kwargs?.bound?.id)) {
37-
const modelName =
38-
promptObject.manifest.kwargs?.last?.kwargs?.bound?.id.at(-1);
57+
const chatModelObject = isRunnableBinding(
58+
promptObject.manifest.kwargs?.last?.id
59+
)
60+
? promptObject.manifest.kwargs?.last?.kwargs?.bound
61+
: promptObject.manifest.kwargs?.last;
62+
63+
if (Array.isArray(chatModelObject?.id)) {
64+
const modelName = chatModelObject?.id.at(-1);
3965

4066
if (modelName) {
4167
modelClass = await getChatModelByClassName(modelName);

0 commit comments

Comments
 (0)