Skip to content

Commit 3c55778

Browse files
committed
fix tool call part
1 parent c776c38 commit 3c55778

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/inferencesh/models/llm.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from contextlib import contextmanager
88
import base64
9+
import json
910

1011
from .base import BaseAppInput, BaseAppOutput
1112
from .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\nTool 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

0 commit comments

Comments
 (0)