Skip to content

Commit 1d5194b

Browse files
committed
llm function calling v0
1 parent bcf248d commit 1d5194b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/inferencesh/models/llm.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ def generation_thread():
416416
if "message" in delta:
417417
message = delta["message"]
418418
content = message.get("content", "")
419-
if "tool_calls" in message:
419+
if message.get("tool_calls"):
420420
for tool in message["tool_calls"]:
421421
if tool.get("id") not in {t.get("id") for t in tool_calls}:
422422
tool_calls.append(tool)
@@ -426,7 +426,7 @@ def generation_thread():
426426
content = delta_content.get("content", "")
427427

428428
# Handle streaming tool calls
429-
if "tool_calls" in delta_content:
429+
if delta_content.get("tool_calls"):
430430
for tool_delta in delta_content["tool_calls"]:
431431
tool_id = tool_delta.get("id")
432432

@@ -451,7 +451,13 @@ def generation_thread():
451451

452452
finish_reason = delta.get("finish_reason")
453453

454-
if content or "tool_calls" in (delta.get("message", {}) or delta.get("delta", {})):
454+
has_update = bool(content)
455+
has_tool_update = bool(
456+
(delta.get("message", {}) or {}).get("tool_calls") or
457+
(delta.get("delta", {}) or {}).get("tool_calls")
458+
)
459+
460+
if has_update or has_tool_update:
455461
if not timing.first_token_time:
456462
timing.mark_first_token()
457463
response_queue.put((content, {}, tool_calls[:] if tool_calls else None))

0 commit comments

Comments
 (0)