From 2ea5c7abf01662924a5fde1ef51fd91a7542bf21 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 20 Aug 2024 16:13:06 -0500 Subject: [PATCH 1/2] Close #1620. Make sure Chat.messages(format='google') converts role assistant -> model --- shiny/ui/_chat_provider_types.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/shiny/ui/_chat_provider_types.py b/shiny/ui/_chat_provider_types.py index c99964bb9..db6b5b295 100644 --- a/shiny/ui/_chat_provider_types.py +++ b/shiny/ui/_chat_provider_types.py @@ -78,11 +78,15 @@ def as_google_message(message: ChatMessage) -> "GoogleMessage": import google.generativeai.types as gtypes # pyright: ignore[reportMissingTypeStubs] - if message["role"] == "system": + role = message["role"] + + if role == "system": raise ValueError( "Google requires a system prompt to be specified in the `GenerativeModel()` constructor." ) - return gtypes.ContentDict(parts=[message["content"]], role=message["role"]) + elif role == "assistant": + role = "model" + return gtypes.ContentDict(parts=[message["content"]], role=role) def as_langchain_message(message: ChatMessage) -> "LangChainMessage": From 062d8be5f17f5df76d4748b2037826bd97caca85 Mon Sep 17 00:00:00 2001 From: Carson Date: Tue, 20 Aug 2024 16:17:40 -0500 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6c9873d5..5b07d9d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Bug fixes -* An empty `ui.input_date()` value no longer crashes Shiny. (#1528) +* A handful of fixes for `ui.Chat()`, including: + * A fix for use inside Shiny modules. (#1582) + * `.messages(format="google")` now returns the correct role. (#1622) -* `ui.Chat()` now works as expected inside Shiny modules. (#1582) +* An empty `ui.input_date()` value no longer crashes Shiny. (#1528) * Fixed bug where calling `.update_filter(None)` on a data frame renderer did not visually reset non-numeric column filters. (It did reset the column's filtering, just not the label). Now it resets filter's label. (#1557)