You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, if you want to teach Chat.append_message_stream() about response formats that it doesn't already know about, you have to register a new "message normalizer" strategy with this internal object.
Although convenient for developers and still potentially worth exporting (it's currently internal), it's a lot to ask for most users to learn and implement.
It'd be much easier if you could just pass a function to .append_message_stream() to grab the relevant content from each iteration of the stream.
fromshiny.ui._chat_normalizeimportBaseMessageNormalizer, message_normalizer_registryclassLangchainAgentResponseNormalizer(BaseMessageNormalizer):
# For each chunk of a .append_message_stream()defnormalize_chunk(self, chunk):
returnchunk["messages"][0].contentdefcan_normalize_chunk(self, chunk):
return"messages"inchunkandlen(chunk["messages"]) >0# For .append_message()defnormalize(self, message):
returnmessage["messages"][0].contentdefcan_normalize(self, message):
return"messages"inmessageandlen(message["messages"]) >0message_normalizer_registry.register(
"langchain-agents", LangchainAgentResponseNormalizer()
)
Currently, if you want to teach
Chat.append_message_stream()
about response formats that it doesn't already know about, you have to register a new "message normalizer" strategy with this internal object.Although convenient for developers and still potentially worth exporting (it's currently internal), it's a lot to ask for most users to learn and implement.
It'd be much easier if you could just pass a function to
.append_message_stream()
to grab the relevant content from each iteration of the stream.For example, something like this (from #1610):
could instead become something like:
The text was updated successfully, but these errors were encountered: