Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OpenAI Chat Generator - do not create TextContent if content is None #129

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ def _convert_chat_completion_to_chat_message(self, completion: ChatCompletion, c
:return: The ChatMessage.
"""
message: ChatCompletionMessage = choice.message
text = message.content or ""
text = message.content
tool_calls = []
if openai_tool_calls := message.tool_calls:
for openai_tc in openai_tool_calls:
Expand Down
5 changes: 5 additions & 0 deletions test/components/generators/chat/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,9 @@ def test_run_with_tools(self, tools):
assert len(response["replies"]) == 1
message = response["replies"][0]

assert not message.texts
assert not message.text

assert message.tool_calls
tool_call = message.tool_call
assert isinstance(tool_call, ToolCall)
Expand Down Expand Up @@ -641,6 +644,8 @@ def test_live_run_with_tools(self, tools):
assert len(results["replies"]) == 1
message = results["replies"][0]

assert not message.texts
assert not message.text
assert message.tool_calls
tool_call = message.tool_call
assert isinstance(tool_call, ToolCall)
Expand Down