-
Notifications
You must be signed in to change notification settings - Fork 69
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
Add chat.messages(format='internal')
#1532
Conversation
@@ -406,7 +406,7 @@ def messages( | |||
def messages( | |||
self, | |||
*, | |||
format: MISSING_TYPE | ProviderMessageFormat = MISSING, | |||
format: ProviderMessageFormat | Literal["internal"], |
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.
However, this format is actually the least likely format that a user would want -- it is used internally in Shiny, but is not directly usable by any LLMs out there.
That's not actually true. This format can be passed directly OpenAI, LangChain, Anthropic, Ollama, and probably others without modification. It won't pass a type checker, but that doesn't seem like reason enough to force everyone to have to specify a format
.
format: ProviderMessageFormat | Literal["internal"], | |
format: ProviderMessageFormat | Literal["internal"] = "internal", |
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.
Oh wait, I think I misunderstood what the default format was -- I thought it was the actual internal format that the Chat
class uses, but that's not right. The internal format is StoredMessage
, not ChatMessage
. That's why I thought it wouldn't make sense to return that format by default.
So to summarize, prior to this PR, the default format was ChatMessage
, which is sort of a lowest-common-denominator format that has role
and content
.
So it might make sense to just drop this PR entirely. That said, it could still be useful to be able to access the StoredMessage
s in the chat object. That's something I actually wanted to do when I was trying to get a handle on the sizes of messages being sent to the LLM (but then I got sidetracked before I went in depth on it).
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.
Ah, I see. I'd be interested to know more about why you want access to StoredMessage
.
I'll close this PR and create another one for the format="anthropic"
thing
while messages2[-1]["role"] != "user": | ||
messages2.pop() |
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.
It's technically possible that messages2
is of length 0 here, so we'll need to be more careful about that.
from shiny import reactive
from shiny.express import ui
chat = ui.Chat(id="chat")
chat.ui()
@reactive.effect
def _():
print(chat.messages(format="anthropic"))
This changes PR changes
chat.messages()
so that:format
is required. Previously the default value wasMISSING
.chat.messages(format="internal")
(instead offormat=MISSING
, which was the previously the default).Previously, the default
MISSING
would result in it returning the messages in the internalChatMessage
format. However, this format is actually the least likely format that a user would want -- it is used internally in Shiny, but is not directly usable by any LLMs out there. I think that we don't want to have a default format which is not useful.Note that this builds on PR #1530.
Also, I'm open to ideas other than
"internal"
for the name.