-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(core): Add BaseMessage.toFormattedString()
#9228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(core): Add BaseMessage.toFormattedString()
#9228
Conversation
This matches the corresponding implementation in Python. You can now do `console.log(message.prettyPrint())`
🦋 Changeset detectedLatest commit: 5688d88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
prettyPrint
method to BaseMessage
BaseMessage.prettyPrint()
}; | ||
} | ||
|
||
protected override _prettyPrintDetails(): string[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This duplication with _prettyPrintDetails
above is awkward. Seems to be due to the inheritance / interface hierarchy of AIMessageChunk
. @hntrl any thoughts on this one? I could obv factor into a function but was hoping to understand the situation a bit better before blindly doing that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it is a little awkward, and I don't love the repeated code, but I think its fine to have two overrides (this is precedent with some other things in message inheritance as I understand it).
Could hoist this logic and have the methods call it directly (if that's not what you're talking about already)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh where were you thinking we'd hoist it to?
BaseMessage.prettyPrint()
BaseMessage.toFormattedString()
protected override _toFormattedStringDetails(): string[] { | ||
const lines: string[] = []; | ||
if (this.name) { | ||
lines.push(`Name: ${this.name}`); | ||
} | ||
return lines; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
later enhancement: tool call id, status, args, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You get those from the original ai message so if you're printing messages in a loop that would end up being a bit redundant. But agreed useful when printing on its own
Also fwiw I believe this is matching what Python pretty print does
@@ -0,0 +1,5 @@ | |||
--- | |||
"@langchain/core": patch |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think according to semver this would be minor
, because it is adding something to public api? Admittedly it is a small thing we're adding; not sure how strictly we're adhering to semver
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
think you're the first of us to ask that Q post v1! Will confer and let you know
@pokey hope you don't mind, I took some liberties with the implementation to resolve CI issues. When I mentioned hoisting the pretty print function, this is what I had in mind (and maybe lets us introduce other message |
Just translates the Python version of the supervisor tutorial to js. - Depends on langchain-ai/langchainjs#9228 - See also langchain-ai/langchainjs#9235 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Lauren Hirata Singh <[email protected]>
Just translates the Python version of the supervisor tutorial to js. - Depends on langchain-ai/langchainjs#9228 - See also langchain-ai/langchainjs#9235 --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: Lauren Hirata Singh <[email protected]>
This matches
pretty_print()
from Python, except it just returns the string. You can doconsole.log(message.prettyPrint())
to get python'spretty_print
behaviour