File tree Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Expand file tree Collapse file tree 3 files changed +38
-3
lines changed Original file line number Diff line number Diff line change 77 bindOutputSchema ,
88} from "./base.js" ;
99import { load } from "../load/index.js" ;
10+ import { arraysEqual } from "../util/misc.js" ;
1011
1112// TODO: Make this the default, add web entrypoint in next breaking release
1213
@@ -33,9 +34,15 @@ export async function pull<T extends Runnable>(
3334 const promptObject = await basePull ( ownerRepoCommit , options ) ;
3435 let modelClass ;
3536 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 ) ;
37+ const chatModelObject = arraysEqual (
38+ promptObject . manifest . kwargs ?. last ?. id ,
39+ [ "langchain_core" , "runnables" , "RunnableBinding" ]
40+ )
41+ ? promptObject . manifest . kwargs ?. last ?. kwargs ?. bound
42+ : promptObject . manifest . kwargs ?. last ;
43+
44+ if ( Array . isArray ( chatModelObject ?. id ) ) {
45+ const modelName = chatModelObject ?. id . at ( - 1 ) ;
3946 if ( modelName === "ChatOpenAI" ) {
4047 modelClass = ( await import ( "@langchain/openai" ) ) . ChatOpenAI ;
4148 } else if ( modelName === "ChatAnthropic" ) {
Original file line number Diff line number Diff line change @@ -112,3 +112,14 @@ test("Test LangChain Hub while loading model with dynamic imports and structured
112112 expect ( res ) . not . toBeInstanceOf ( AIMessage ) ;
113113 expect ( typeof res . correctness ) . toBe ( "boolean" ) ;
114114} ) ;
115+
116+ test ( "Test LangChain Hub while loading model not defined in a RunnableBinding" , async ( ) => {
117+ const promptA = await nodePull ( "hntrl/binding-manifest" , {
118+ includeModel : true ,
119+ } ) ;
120+ const resA = await promptA . invoke ( {
121+ question : "What's the capital of the USA?" ,
122+ } ) ;
123+ expect ( resA ) . toBeInstanceOf ( AIMessage ) ;
124+ expect ( resA . content ) . toBeDefined ( ) ;
125+ } ) ;
Original file line number Diff line number Diff line change 1+ /**
2+ * Helper function to check if two arrays are deeply equal
3+ */
4+ export function arraysEqual < T > ( a : T [ ] , b : T [ ] ) : boolean {
5+ if ( ! Array . isArray ( a ) || ! Array . isArray ( b ) ) {
6+ return false ;
7+ }
8+ if ( a . length !== b . length ) {
9+ return false ;
10+ }
11+ for ( let i = 0 ; i < a . length ; i ++ ) {
12+ if ( a [ i ] !== b [ i ] ) {
13+ return false ;
14+ }
15+ }
16+ return true ;
17+ }
You can’t perform that action at this time.
0 commit comments