Skip to content

Commit

Permalink
core[patch]: Add check for bind tools in structured promot
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Jun 24, 2024
1 parent ff0ac6e commit d2ec14e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion langchain-core/src/prompts/structured.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ function isWithStructuredOutput(
);
}

function isBindTools(x: unknown): x is {
bindTools: (...arg: unknown[]) => Runnable;
} {
return (
typeof x === "object" &&
x != null &&
"bindTools" in x &&
typeof x.bindTools === "function"
);
}

function isRunnableBinding(x: unknown): x is RunnableBinding<unknown, unknown> {
return (
typeof x === "object" &&
Expand Down Expand Up @@ -84,7 +95,8 @@ export class StructuredPrompt<

if (
isRunnableBinding(coerceable) &&
isWithStructuredOutput(coerceable.bound)
isWithStructuredOutput(coerceable.bound) &&
isBindTools(coerceable.bound)
) {
return super.pipe(
coerceable.bound
Expand Down

0 comments on commit d2ec14e

Please sign in to comment.