langchain
langchain copied to clipboard
[idea] include a _repr_markdown_ for messages
Hey all!
I enjoy viewing chat messages and responses as markdown. There's a simple way to do this in IPython-backed frontends (jupyter lab, classic notebook, colab, noteable, etc.) -- including a _repr_markdown_
. In this PR I've added a simple addition to BaseMessage
.
Example:

However, this ruins a key feature when iterating in a notebook -- the ability to copy/paste the repr output to add to the messages.

I'd love to hear any thoughts you have on this. Happy to decorate a lot more classes with rich representations.
hmm yeah i do think the ability to copy/paste messages is pretty important
maybe we enable something like this with an environment variable? eg if os.environ["LANGCHAIN_FORMATTING"] = "pretty"
then we do this? else we just do normal? And that way if they want to see this they can just set that env var?
hmm yeah i do think the ability to copy/paste messages is pretty important
I wish there was a multi (jupyter) platform way to have a copy/paste icon in the corner that would enable copying the repr format. Anything I can think of (including an HTML repr) gets a bit hacky.
maybe we enable something like this with an environment variable? eg if
os.environ["LANGCHAIN_FORMATTING"] = "pretty"
then we do this? else we just do normal? And that way if they want to see this they can just set that env var?
My gut reaction is that I'm less likely to use a feature like this via an env var. I definitely see the tradeoff though! Let me know when you're sure of the direction as I'm happy to update it to match.
@hwchase17 what if we add flag in langchain/__init__.py
similar to verbose
and debug
, something like pretty_format
. then usage would look like
import langchain
from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage
langchain.pretty_format = True
ChatOpenAI(HumanMessage(content="foo bar"))
@rgbkrk Hi , could you, please, resolve the merging issues and address the last comments (if needed)? After that ping me and I push this PR for the review. Thanks!
Closing due to inactivity and library being a different directory structure now, and feel free to reopen against the current state of the repo!
Sounds great, thanks!