File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 66import time
77from contextlib import contextmanager
88import base64
9+ import json
910
1011from .base import BaseAppInput , BaseAppOutput
1112from .file import File
@@ -216,6 +217,10 @@ def build_messages(
216217 def render_message (msg : ContextMessage , allow_multipart : bool ) -> str | List [dict ]:
217218 parts = []
218219 text = transform_user_message (msg .text ) if transform_user_message and msg .role == ContextMessageRole .USER else msg .text
220+ if msg .tool_calls :
221+ for tool_call in msg .tool_calls :
222+ tool_call_string = json .dumps (tool_call )
223+ text += f"\n \n Tool call: { tool_call_string } "
219224 if text :
220225 parts .append ({"type" : "text" , "text" : text })
221226 if msg .image :
@@ -228,7 +233,11 @@ def render_message(msg: ContextMessage, allow_multipart: bool) -> str | List[dic
228233 return parts
229234 if len (parts ) == 1 and parts [0 ]["type" ] == "text" :
230235 return parts [0 ]["text" ]
231- raise ValueError ("Image content requires multipart support" )
236+ if len (parts ) > 1 :
237+ if parts .any (lambda x : x ["type" ] == "image_url" ):
238+ raise ValueError ("Image content requires multipart support" )
239+ return parts
240+ raise ValueError ("Invalid message content" )
232241
233242 messages = [{"role" : "system" , "content" : input_data .system_prompt }] if input_data .system_prompt is not None and input_data .system_prompt != "" else []
234243
You can’t perform that action at this time.
0 commit comments