Skip to content

Commit c24e8f3

Browse files
authored
fix(pkg-py): fix message_content()'s handling of chatlas Turn (#133)
* fix(pkg-py): fix message_content()'s handling of chatlas Turns * Update changelog
1 parent 2b9570a commit c24e8f3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

pkg-py/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [UNRELEASED]
9+
10+
### Bug fixes
11+
12+
* `message_content()` and `message_content_chunk()` correctly extract content from a `chatlas.Turn`. (#133)
13+
814
## [0.2.2] - 2025-09-10
915

1016
### Improvements

pkg-py/src/shinychat/_chat_normalize.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import sys
44
from functools import singledispatch
55

6-
from htmltools import HTML, Tagifiable, TagList
6+
from htmltools import HTML, Tagifiable
77

88
from ._chat_normalize_chatlas import tool_request_contents, tool_result_contents
99
from ._chat_types import ChatMessage
@@ -163,10 +163,15 @@ def _(chunk: ContentToolResult):
163163

164164
@message_content.register
165165
def _(message: Turn):
166-
contents = TagList()
166+
from chatlas import ContentToolResult
167+
content = ""
167168
for x in message.contents:
168-
contents.append(message_content(x).content)
169-
return ChatMessage(content=contents)
169+
content += message_content(x).content
170+
if all(isinstance(x, ContentToolResult) for x in message.contents):
171+
role = "assistant"
172+
else:
173+
role = message.role
174+
return ChatMessage(content=content, role=role)
170175

171176
@message_content_chunk.register
172177
def _(chunk: Turn):

0 commit comments

Comments
 (0)