@@ -181,15 +181,55 @@ def generate_content(token_count: int) -> str:
181181
182182
183183def test_string_normalization ():
184- m = message_content_chunk ("Hello world!" )
184+ m = message_content ("Hello world!" )
185185 assert m .content == "Hello world!"
186186 assert m .role == "assistant"
187+ mc = message_content_chunk ("Hello world!" )
188+ assert mc .content == "Hello world!"
189+ assert mc .role == "assistant"
187190
188191
189192def test_dict_normalization ():
190- m = message_content_chunk ({"content" : "Hello world!" , "role" : "assistant" })
193+ m = message_content ({"content" : "Hello world!" , "role" : "assistant" })
191194 assert m .content == "Hello world!"
192195 assert m .role == "assistant"
196+ mc = message_content_chunk ({"content" : "Hello world!" })
197+ assert mc .content == "Hello world!"
198+ assert mc .role == "assistant"
199+
200+
201+ def test_chat_message_normalization ():
202+ m = message_content (ChatMessage (content = "Hello world!" , role = "assistant" ))
203+ assert m .content == "Hello world!"
204+ assert m .role == "assistant"
205+ mc = message_content_chunk (ChatMessage (content = "Hello world!" ))
206+ assert mc .content == "Hello world!"
207+ assert mc .role == "assistant"
208+
209+
210+ def test_tagifiable_normalization ():
211+ from shiny .ui import HTML , div
212+
213+ # Interpreted as markdown (without escaping)
214+ m = message_content ("Hello <span>world</span>!" )
215+ assert m .content == "Hello <span>world</span>!"
216+ assert m .role == "assistant"
217+
218+ # Interpreted as HTML (without escaping)
219+ m = message_content (HTML ("Hello <span>world</span>!" ))
220+ assert (
221+ m .content
222+ == "\n \n ````````{=html}\n Hello <span>world</span>!\n ````````\n \n "
223+ )
224+ assert m .role == "assistant"
225+
226+ # Interpreted as HTML (if top-level object is tag-like, inner string contents get escaped)
227+ m = message_content (div ("Hello <span>world</span>!" ))
228+ assert (
229+ m .content
230+ == "\n \n ````````{=html}\n <div>Hello <span>world</span>!</div>\n ````````\n \n "
231+ )
232+ assert m .role == "assistant"
193233
194234
195235def test_langchain_normalization ():
0 commit comments