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