Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/llm/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

# Handle imports for type checking
if TYPE_CHECKING:
from openai.types.chat.chat_completion_chunk import ChatCompletionChunk
from conversations.models import Conversation
from .models import LLMConfig

Expand Down Expand Up @@ -385,6 +386,8 @@ def _generate_openai_response(
function_calls = []
if hasattr(choice.message, "tool_calls") and choice.message.tool_calls:
for tool_call in choice.message.tool_calls:
if not hasattr(tool_call, "function"):
continue
try:
arguments = json.loads(tool_call.function.arguments)
function_calls.append(
Expand Down Expand Up @@ -878,6 +881,8 @@ def _stream_with_finish_reason_detection(
tool_calls_accumulator = {} # Accumulate tool call deltas by index

for chunk in stream:
if not isinstance(chunk, ChatCompletionChunk):
continue
if chunk.choices and len(chunk.choices) > 0:
choice = chunk.choices[0]

Expand Down
Loading