Skip to content
Merged
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 @@ -182,7 +182,9 @@ internal sealed class ResponseInputJsonConverter : JsonConverter<ResponseInput>
return messages is not null ? ResponseInput.FromMessages(messages) : null;
}

throw new JsonException($"Unexpected token type for ResponseInput: {reader.TokenType}");
throw new JsonException(
"ResponseInput must be either a string or an array of messages. " +
$"Objects are not supported. Received token type: {reader.TokenType}");
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,20 @@ public void Deserialize_RefusalStreamingRequest_HasStream()
Assert.NotNull(request.Input);
}

[Fact]
public void Deserialize_InvalidInputObject_ThrowsHelpfulException()
{
// Arrange
const string Json = "{\"model\":\"gpt-4o-mini\",\"input\":{\"input\":\"testing!\"},\"stream\":true}";

// Act & Assert
var exception = Assert.Throws<JsonException>(() =>
JsonSerializer.Deserialize(Json, OpenAIHostingJsonContext.Default.CreateResponse));

Assert.Contains("ResponseInput must be either a string or an array of messages", exception.Message);
Assert.Contains("Objects are not supported", exception.Message);
}

[Fact]
public void Deserialize_AllRequests_CanBeDeserialized()
{
Expand Down
Loading
Loading