mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-16 17:47:06 +08:00
test: add test for None think content edge case in openai_source
This commit is contained in:
@@ -273,6 +273,36 @@ async def test_groq_payload_drops_reasoning_content_from_assistant_history():
|
||||
await provider.terminate()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_openai_payload_handles_none_think_content():
|
||||
"""Test that _finally_convert_payload handles think content being None."""
|
||||
provider = _make_provider()
|
||||
try:
|
||||
# Test case where think content might be None
|
||||
payloads = {
|
||||
"messages": [
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{"type": "think", "think": None}, # type: ignore
|
||||
{"type": "text", "text": "final answer"},
|
||||
],
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# Should not raise TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str'
|
||||
provider._finally_convert_payload(payloads)
|
||||
|
||||
assistant_message = payloads["messages"][0]
|
||||
assert assistant_message["content"] == [
|
||||
{"type": "text", "text": "final answer"}
|
||||
]
|
||||
finally:
|
||||
await provider.terminate()
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_handle_api_error_content_moderated_without_images_raises():
|
||||
provider = _make_provider(
|
||||
|
||||
Reference in New Issue
Block a user