@@ -135,91 +135,6 @@ def rebuild_from_source(
135135 ) -> ChatCompletionToolMessageParam :
136136 """Rebuild tool message from SourceMessage."""
137137
138- # Priority 1: Use original_part if available
139- if hasattr (source , "original_part" ) and source .original_part :
140- original = source .original_part
141- # If it's a content part, wrap it in a message
142- if isinstance (original , dict ) and "type" in original :
143- return {
144- "role" : source .role or "user" ,
145- "tool_call_id" : source .tool_call_id or "" ,
146- "content" : [original ],
147- "chat_time" : source .chat_time ,
148- "message_id" : source .message_id ,
149- }
150- # If it's already a full message, return it
151- if isinstance (original , dict ) and "role" in original :
152- return original
153-
154- # Priority 2: Rebuild from source fields
155- if source .type == "text" :
156- return {
157- "role" : source .role or "tool" ,
158- "content" : [
159- {
160- "type" : "text" ,
161- "text" : source .content or "" ,
162- }
163- ],
164- "chat_time" : source .chat_time ,
165- "message_id" : source .message_id ,
166- }
167- elif source .type == "file" :
168- return {
169- "role" : source .role or "tool" ,
170- "content" : [
171- {
172- "type" : "file" ,
173- "file" : {
174- "file_id" : source .file_id or "" ,
175- "filename" : source .filename or "" ,
176- "file_data" : source .content or "" ,
177- },
178- }
179- ],
180- "chat_time" : source .chat_time ,
181- "message_id" : source .message_id ,
182- }
183- elif source .type == "image_url" :
184- return {
185- "role" : source .role or "tool" ,
186- "content" : [
187- {
188- "type" : "image_url" ,
189- "image_url" : {
190- "url" : source .content or "" ,
191- "detail" : source .detail or "auto" ,
192- },
193- }
194- ],
195- "chat_time" : source .chat_time ,
196- "message_id" : source .message_id ,
197- }
198- elif source .type == "input_audio" :
199- return {
200- "role" : source .role or "tool" ,
201- "content" : [
202- {
203- "type" : "input_audio" ,
204- "input_audio" : {
205- "data" : source .content or "" ,
206- "format" : source .format or "wav" ,
207- },
208- }
209- ],
210- "chat_time" : source .chat_time ,
211- "message_id" : source .message_id ,
212- }
213-
214- # Simple text message
215- return {
216- "role" : "tool" ,
217- "content" : source .content or "" ,
218- "tool_call_id" : source .message_id or "" ,
219- "chat_time" : source .chat_time ,
220- "message_id" : source .message_id ,
221- }
222-
223138 def parse_fast (
224139 self ,
225140 message : ChatCompletionToolMessageParam ,
@@ -261,25 +176,5 @@ def parse_fine(
261176 info : dict [str , Any ],
262177 ** kwargs ,
263178 ) -> list [TextualMemoryItem ]:
264- content = message .get ("content" , "" )
265- if isinstance (content , list ):
266- part_type = content [0 ].get ("type" , "" )
267- if part_type == "text" :
268- # text will fine parse in full chat content, no need to parse specially
269- return []
270- elif part_type == "file" :
271- # use file content parser to parse file content, no need to parse here
272- return []
273- elif part_type == "image_url" :
274- # TODO: use multi-modal llm to generate mem by image url
275- content = content [0 ].get ("image_url" , {}).get ("url" , "" )
276- return []
277- elif part_type == "input_audio" :
278- # TODO: unsupport audio for now
279- return []
280- else :
281- logger .warning (f"[ToolParser] Unsupported part type: { part_type } " )
282- return []
283- else :
284- # simple string content message, fine parse in full chat content, no need to parse specially
285- return []
179+ # tool message no special multimodal handling is required in fine mode.
180+ return []
0 commit comments