diff --git a/OpenAI.SDK/Managers/OpenAIChatCompletions.cs b/OpenAI.SDK/Managers/OpenAIChatCompletions.cs
index 8018c604..a837d7f4 100644
--- a/OpenAI.SDK/Managers/OpenAIChatCompletions.cs
+++ b/OpenAI.SDK/Managers/OpenAIChatCompletions.cs
@@ -117,16 +117,22 @@ public void Process(ChatCompletionCreateResponse block)
// We're going to steal the partial message and squirrel it away for the time being.
if (!IsFnAssemblyActive && isStreamingFnCall)
{
- FnCall = firstChoice.Message.FunctionCall;
- firstChoice.Message.FunctionCall = null;
- justStarted = true;
+ if (firstChoice.Message != null)
+ {
+ FnCall = firstChoice.Message.FunctionCall;
+ firstChoice.Message.FunctionCall = null;
+ justStarted = true;
+ }
}
// As long as we're assembling, keep on appending those args
// (Skip the first one, because it was already processed in the block above)
if (IsFnAssemblyActive && !justStarted)
{
- FnCall.Arguments += ExtractArgsSoFar();
+ if (FnCall != null)
+ {
+ FnCall.Arguments += ExtractArgsSoFar();
+ }
}
// If we were assembling and it just finished, fill this block with the info we've assembled, and we're done.
diff --git a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs
index 037f3ac1..02177ec6 100644
--- a/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs
+++ b/OpenAI.SDK/ObjectModels/RequestModels/ChatMessage.cs
@@ -18,10 +18,10 @@ public class ChatMessage
/// length of 64 characters.
///
/// The name and arguments of a function that should be called, as generated by the model.
- public ChatMessage(string role, string content, string? name = null, FunctionCall? functionCall = null)
+ public ChatMessage(string? role = null, string? content = null, string? name = null, FunctionCall? functionCall = null)
{
- Role = role;
- Content = content;
+ Role = role ?? string.Empty;
+ Content = content ?? string.Empty;
Name = name;
FunctionCall = functionCall;
}
@@ -30,7 +30,7 @@ public ChatMessage(string role, string content, string? name = null, FunctionCal
/// The role of the author of this message. One of system, user, or assistant.
///
[JsonPropertyName("role")]
- public string Role { get; set; }
+ public string? Role { get; set; }
///
/// The contents of the message.
diff --git a/OpenAI.SDK/ObjectModels/ResponseModels/ChatCompletionCreateResponse.cs b/OpenAI.SDK/ObjectModels/ResponseModels/ChatCompletionCreateResponse.cs
index 0615826a..76ea2b5d 100644
--- a/OpenAI.SDK/ObjectModels/ResponseModels/ChatCompletionCreateResponse.cs
+++ b/OpenAI.SDK/ObjectModels/ResponseModels/ChatCompletionCreateResponse.cs
@@ -7,9 +7,9 @@ public record ChatCompletionCreateResponse : BaseResponse, IOpenAiModels.IId, IO
{
[JsonPropertyName("model")] public string Model { get; set; }
- [JsonPropertyName("choices")] public List Choices { get; set; }
+ [JsonPropertyName("choices")] public List? Choices { get; set; }
- [JsonPropertyName("usage")] public UsageResponse Usage { get; set; }
+ [JsonPropertyName("usage")] public UsageResponse? Usage { get; set; }
[JsonPropertyName("created")] public int CreatedAt { get; set; }
diff --git a/OpenAI.SDK/ObjectModels/SharedModels/ChatChoiceResponse.cs b/OpenAI.SDK/ObjectModels/SharedModels/ChatChoiceResponse.cs
index 441d51b5..a3a7b312 100644
--- a/OpenAI.SDK/ObjectModels/SharedModels/ChatChoiceResponse.cs
+++ b/OpenAI.SDK/ObjectModels/SharedModels/ChatChoiceResponse.cs
@@ -6,15 +6,15 @@ namespace OpenAI.ObjectModels.SharedModels;
public record ChatChoiceResponse
{
[JsonPropertyName("delta")]
- public ChatMessage Delta
+ public ChatMessage? Delta
{
get => Message;
set => Message = value;
}
- [JsonPropertyName("message")] public ChatMessage Message { get; set; }
+ [JsonPropertyName("message")] public ChatMessage? Message { get; set; }
[JsonPropertyName("index")] public int? Index { get; set; }
- [JsonPropertyName("finish_reason")] public string FinishReason { get; set; }
+ [JsonPropertyName("finish_reason")] public string? FinishReason { get; set; }
}
\ No newline at end of file