Skip to content

Commit

Permalink
Disallow nullish values
Browse files Browse the repository at this point in the history
  • Loading branch information
jacoblee93 committed Oct 12, 2023
1 parent 806060f commit e3f5fd4
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
4 changes: 2 additions & 2 deletions langchain/src/prompts/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,12 @@ export class MessagesPlaceholder<
return true;
}

formatMessages(
async formatMessages(
values: TypedPromptInputValues<RunInput>
): Promise<BaseMessage[]> {
this.validateInputOrThrow(values[this.variableName], this.variableName);

return Promise.resolve(values[this.variableName] as BaseMessage[]);
return values[this.variableName];
}
}

Expand Down
2 changes: 1 addition & 1 deletion langchain/src/prompts/tests/chat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,5 +344,5 @@ test("Does not throw if null or undefined is passed as input to MessagesPlacehol
question: "What is the meaning of life?",
});

expect(formatted).toHaveLength(4);
expect(formatted).toHaveLength(2);
});
6 changes: 1 addition & 5 deletions langchain/src/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,7 @@ export type BaseMessageLike =
export function isBaseMessage(
messageLike?: unknown
): messageLike is BaseMessage {
return (
typeof (messageLike as BaseMessage)?._getType === "function" ||
messageLike === null ||
messageLike === undefined
);
return typeof (messageLike as BaseMessage)?._getType === "function";
}

export function coerceMessageLikeToMessage(
Expand Down

0 comments on commit e3f5fd4

Please sign in to comment.