Skip to content

Commit

Permalink
Make sure Chat.messages(format='google') converts role assistant ->…
Browse files Browse the repository at this point in the history
… model (#1622)
  • Loading branch information
cpsievert authored Aug 20, 2024
1 parent d90c0bf commit c97f09b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 6 additions & 2 deletions shiny/ui/_chat_provider_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down

0 comments on commit c97f09b

Please sign in to comment.