Skip to content

Commit e2402a3

Browse files
committed
fix: OpenAIChatGenerator - improve the logic to exclude custom tool calls (#9725)
1 parent c0868f3 commit e2402a3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

haystack/components/generators/chat/openai.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
from typing import Any, Optional, Union
99

1010
from openai import AsyncOpenAI, AsyncStream, OpenAI, Stream
11-
from openai.types.chat import ChatCompletion, ChatCompletionChunk, ChatCompletionMessage
11+
from openai.types.chat import (
12+
ChatCompletion,
13+
ChatCompletionChunk,
14+
ChatCompletionMessage,
15+
ChatCompletionMessageCustomToolCall,
16+
)
1217
from openai.types.chat.chat_completion import Choice
1318
from openai.types.chat.chat_completion_chunk import Choice as ChunkChoice
1419

@@ -480,7 +485,7 @@ def _convert_chat_completion_to_chat_message(completion: ChatCompletion, choice:
480485
if message.tool_calls:
481486
# we currently only support function tools (not custom tools)
482487
# https://platform.openai.com/docs/guides/function-calling#custom-tools
483-
openai_tool_calls = [tc for tc in message.tool_calls if tc.type == "function"]
488+
openai_tool_calls = [tc for tc in message.tool_calls if not isinstance(tc, ChatCompletionMessageCustomToolCall)]
484489
for openai_tc in openai_tool_calls:
485490
arguments_str = openai_tc.function.arguments
486491
try:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
In `OpenAIChatGenerator`, improved the logic to exclude unsupported custom tool calls.
5+
The previous implementation caused compatibility issues with the Mistral Haystack core integration,
6+
which extends `OpenAIChatGenerator`.

0 commit comments

Comments
 (0)