1414
1515import json
1616import os
17- from typing import TYPE_CHECKING , Any , Dict , Generator , List , Optional , Sequence , Tuple
17+ from typing import TYPE_CHECKING , Any , Dict , Generator , List , Optional , Tuple
1818
1919from ..chat import ChatModel
2020from ..data import Role
@@ -120,26 +120,26 @@ def unload_model(self, data) -> Generator[str, None, None]:
120120
121121 def append (
122122 self ,
123- chatbot : List [List [ Optional [ str ] ]],
124- messages : Sequence [Dict [str , str ]],
123+ chatbot : List [Dict [ str , str ]],
124+ messages : List [Dict [str , str ]],
125125 role : str ,
126126 query : str ,
127- ) -> Tuple [List [List [ Optional [ str ] ]], List [Dict [str , str ]], str ]:
128- return chatbot + [[ query , None ] ], messages + [{"role" : role , "content" : query }], ""
127+ ) -> Tuple [List [Dict [ str , str ]], List [Dict [str , str ]], str ]:
128+ return chatbot + [{ "role" : "user" , "content" : query } ], messages + [{"role" : role , "content" : query }], ""
129129
130130 def stream (
131131 self ,
132- chatbot : List [List [ Optional [ str ] ]],
133- messages : Sequence [Dict [str , str ]],
132+ chatbot : List [Dict [ str , str ]],
133+ messages : List [Dict [str , str ]],
134134 system : str ,
135135 tools : str ,
136136 image : Optional [Any ],
137137 video : Optional [Any ],
138138 max_new_tokens : int ,
139139 top_p : float ,
140140 temperature : float ,
141- ) -> Generator [Tuple [List [List [ Optional [ str ] ]], List [Dict [str , str ]]], None , None ]:
142- chatbot [ - 1 ][ 1 ] = ""
141+ ) -> Generator [Tuple [List [Dict [ str , str ]], List [Dict [str , str ]]], None , None ]:
142+ chatbot . append ({ "role" : "assistant" , "content" : "" })
143143 response = ""
144144 for new_text in self .stream_chat (
145145 messages ,
@@ -166,5 +166,5 @@ def stream(
166166 output_messages = messages + [{"role" : Role .ASSISTANT .value , "content" : result }]
167167 bot_text = result
168168
169- chatbot [- 1 ][ 1 ] = bot_text
169+ chatbot [- 1 ] = { "role" : "assistant" , "content" : bot_text }
170170 yield chatbot , output_messages
0 commit comments