langchain icon indicating copy to clipboard operation
langchain copied to clipboard

[idea] include a _repr_markdown_ for messages

Open rgbkrk opened this issue 1 year ago • 3 comments

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:

image

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

image

I'd love to hear any thoughts you have on this. Happy to decorate a lot more classes with rich representations.

rgbkrk avatar Apr 02 '23 17:04 rgbkrk

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?

hwchase17 avatar Apr 02 '23 20:04 hwchase17

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.

rgbkrk avatar Apr 03 '23 03:04 rgbkrk

@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"))

dev2049 avatar May 19 '23 00:05 dev2049

@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!

leo-gan avatar Sep 13 '23 00:09 leo-gan

Closing due to inactivity and library being a different directory structure now, and feel free to reopen against the current state of the repo!

efriis avatar Nov 03 '23 22:11 efriis

Sounds great, thanks!

rgbkrk avatar Nov 05 '23 00:11 rgbkrk