File tree 2 files changed +24
-2
lines changed
langchain-core/src/prompts
2 files changed +24
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { BaseLanguageModel } from "../language_models/base.js" ;
2
+ import { BaseChatModel } from "../language_models/chat_models.js" ;
1
3
import { ChatPromptValueInterface } from "../prompt_values.js" ;
2
4
import {
3
5
RunnableLike ,
@@ -22,7 +24,18 @@ function isWithStructuredOutput(
22
24
typeof x === "object" &&
23
25
x != null &&
24
26
"withStructuredOutput" in x &&
25
- typeof x . withStructuredOutput === "function"
27
+ x . withStructuredOutput !== BaseLanguageModel . prototype . withStructuredOutput
28
+ ) ;
29
+ }
30
+
31
+ function isBindTools ( x : unknown ) : x is {
32
+ bindTools : ( ...arg : unknown [ ] ) => Runnable ;
33
+ } {
34
+ return (
35
+ typeof x === "object" &&
36
+ x != null &&
37
+ "bindTools" in x &&
38
+ x . bindTools !== BaseChatModel . prototype . bindTools
26
39
) ;
27
40
}
28
41
@@ -84,7 +97,8 @@ export class StructuredPrompt<
84
97
85
98
if (
86
99
isRunnableBinding ( coerceable ) &&
87
- isWithStructuredOutput ( coerceable . bound )
100
+ isWithStructuredOutput ( coerceable . bound ) &&
101
+ isBindTools ( coerceable . bound )
88
102
) {
89
103
return super . pipe (
90
104
coerceable . bound
Original file line number Diff line number Diff line change @@ -4,15 +4,23 @@ import {
4
4
StructuredOutputMethodParams ,
5
5
StructuredOutputMethodOptions ,
6
6
BaseLanguageModelInput ,
7
+ ToolDefinition ,
7
8
} from "../../language_models/base.js" ;
8
9
import { BaseMessage } from "../../messages/index.js" ;
9
10
import { Runnable , RunnableLambda } from "../../runnables/base.js" ;
10
11
import { RunnableConfig } from "../../runnables/config.js" ;
11
12
import { FakeListChatModel } from "../../utils/testing/index.js" ;
12
13
import { StructuredPrompt } from "../structured.js" ;
13
14
import { load } from "../../load/index.js" ;
15
+ import { StructuredToolInterface } from "../../tools.js" ;
14
16
15
17
class FakeStructuredChatModel extends FakeListChatModel {
18
+ override bindTools (
19
+ _tools : ( StructuredToolInterface | ToolDefinition | Record < string , any > ) [ ]
20
+ ) : Runnable {
21
+ return this . bind ( { } ) ;
22
+ }
23
+
16
24
withStructuredOutput <
17
25
RunOutput extends Record < string , any > = Record < string , any >
18
26
> (
You can’t perform that action at this time.
0 commit comments