Skip to content

Commit cf1cb15

Browse files
committed
remove content_parts from ChatCompletion
1 parent c7ea5db commit cf1cb15

File tree

8 files changed

+10611
-10699
lines changed

8 files changed

+10611
-10699
lines changed

specification/base/typespec/chat/models.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ alias CreateChatCompletionStreamResponseChoice = {
124124
alias ChatCompletionMessageListData = {
125125
...ChatCompletionResponseMessage;
126126

127+
content_parts?: ChatCompletionRequestMessageContentPart[] | null;
128+
127129
/** The identifier of the chat message. */
128130
id: string;
129131
};
@@ -719,8 +721,6 @@ model ChatCompletionResponseMessage {
719721
/** The contents of the message. */
720722
content: string | null;
721723

722-
content_parts?: ChatCompletionRequestMessageContentPart[] | null;
723-
724724
/** The refusal message generated by the model. */
725725
refusal: string | null;
726726

src/Custom/Chat/OpenAIChatModelFactory.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,16 @@ public static ChatCompletion ChatCompletion(
6262
string systemFingerprint = null,
6363
ChatTokenUsage usage = default,
6464
ChatOutputAudio outputAudio = default,
65-
IEnumerable<ChatMessageAnnotation> messageAnnotations = default,
66-
IEnumerable<ChatMessageContentPart> contentParts = default)
65+
IEnumerable<ChatMessageAnnotation> messageAnnotations = default)
6766
{
6867
content ??= new ChatMessageContent();
6968
toolCalls ??= new List<ChatToolCall>();
7069
contentTokenLogProbabilities ??= new List<ChatTokenLogProbabilityDetails>();
7170
refusalTokenLogProbabilities ??= new List<ChatTokenLogProbabilityDetails>();
7271
messageAnnotations ??= new List<ChatMessageAnnotation>();
73-
contentParts ??= new List<ChatMessageContentPart>();
7472

7573
InternalChatCompletionResponseMessage message = new(
7674
content: content,
77-
contentParts: contentParts.ToList(),
7875
refusal: refusal,
7976
toolCalls: toolCalls.ToList(),
8077
annotations: messageAnnotations.ToList(),

src/Generated/Models/Chat/ChatCompletionMessageListDatum.Serialization.cs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace OpenAI.Chat
1313
{
1414
public partial class ChatCompletionMessageListDatum : IJsonModel<ChatCompletionMessageListDatum>
1515
{
16-
internal ChatCompletionMessageListDatum() : this(null, null, null, null, null, default, null, null, null, default)
16+
internal ChatCompletionMessageListDatum() : this(null, null, null, null, default, null, null, null, null, default)
1717
{
1818
}
1919

@@ -49,29 +49,6 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
4949
{
5050
writer.WriteNull("content"u8);
5151
}
52-
if (Patch.Contains("$.content_parts"u8))
53-
{
54-
if (!Patch.IsRemoved("$.content_parts"u8))
55-
{
56-
writer.WritePropertyName("content_parts"u8);
57-
writer.WriteRawValue(Patch.GetJson("$.content_parts"u8));
58-
}
59-
}
60-
else if (Optional.IsCollectionDefined(ContentParts))
61-
{
62-
writer.WritePropertyName("content_parts"u8);
63-
writer.WriteStartArray();
64-
for (int i = 0; i < ContentParts.Count; i++)
65-
{
66-
if (ContentParts[i].Patch.IsRemoved("$"u8))
67-
{
68-
continue;
69-
}
70-
writer.WriteObjectValue(ContentParts[i], options);
71-
}
72-
Patch.WriteTo(writer, "$.content_parts"u8);
73-
writer.WriteEndArray();
74-
}
7552
if (Optional.IsDefined(Refusal) && !Patch.Contains("$.refusal"u8))
7653
{
7754
writer.WritePropertyName("refusal"u8);
@@ -142,6 +119,29 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
142119
writer.WritePropertyName("audio"u8);
143120
writer.WriteObjectValue(OutputAudio, options);
144121
}
122+
if (Patch.Contains("$.content_parts"u8))
123+
{
124+
if (!Patch.IsRemoved("$.content_parts"u8))
125+
{
126+
writer.WritePropertyName("content_parts"u8);
127+
writer.WriteRawValue(Patch.GetJson("$.content_parts"u8));
128+
}
129+
}
130+
else if (Optional.IsCollectionDefined(ContentParts))
131+
{
132+
writer.WritePropertyName("content_parts"u8);
133+
writer.WriteStartArray();
134+
for (int i = 0; i < ContentParts.Count; i++)
135+
{
136+
if (ContentParts[i].Patch.IsRemoved("$"u8))
137+
{
138+
continue;
139+
}
140+
writer.WriteObjectValue(ContentParts[i], options);
141+
}
142+
Patch.WriteTo(writer, "$.content_parts"u8);
143+
writer.WriteEndArray();
144+
}
145145
if (!Patch.Contains("$.id"u8))
146146
{
147147
writer.WritePropertyName("id"u8);
@@ -172,13 +172,13 @@ internal static ChatCompletionMessageListDatum DeserializeChatCompletionMessageL
172172
return null;
173173
}
174174
string content = default;
175-
IList<ChatMessageContentPart> contentParts = default;
176175
string refusal = default;
177176
IReadOnlyList<ChatToolCall> toolCalls = default;
178177
IReadOnlyList<ChatMessageAnnotation> annotations = default;
179178
ChatMessageRole role = default;
180179
InternalChatCompletionResponseMessageFunctionCall functionCall = default;
181180
ChatOutputAudio outputAudio = default;
181+
IList<ChatMessageContentPart> contentParts = default;
182182
string id = default;
183183
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
184184
JsonPatch patch = new JsonPatch(data is null ? ReadOnlyMemory<byte>.Empty : data.ToMemory());
@@ -195,20 +195,6 @@ internal static ChatCompletionMessageListDatum DeserializeChatCompletionMessageL
195195
content = prop.Value.GetString();
196196
continue;
197197
}
198-
if (prop.NameEquals("content_parts"u8))
199-
{
200-
if (prop.Value.ValueKind == JsonValueKind.Null)
201-
{
202-
continue;
203-
}
204-
List<ChatMessageContentPart> array = new List<ChatMessageContentPart>();
205-
foreach (var item in prop.Value.EnumerateArray())
206-
{
207-
array.Add(ChatMessageContentPart.DeserializeChatMessageContentPart(item, item.GetUtf8Bytes(), options));
208-
}
209-
contentParts = array;
210-
continue;
211-
}
212198
if (prop.NameEquals("refusal"u8))
213199
{
214200
if (prop.Value.ValueKind == JsonValueKind.Null)
@@ -271,6 +257,20 @@ internal static ChatCompletionMessageListDatum DeserializeChatCompletionMessageL
271257
outputAudio = ChatOutputAudio.DeserializeChatOutputAudio(prop.Value, prop.Value.GetUtf8Bytes(), options);
272258
continue;
273259
}
260+
if (prop.NameEquals("content_parts"u8))
261+
{
262+
if (prop.Value.ValueKind == JsonValueKind.Null)
263+
{
264+
continue;
265+
}
266+
List<ChatMessageContentPart> array = new List<ChatMessageContentPart>();
267+
foreach (var item in prop.Value.EnumerateArray())
268+
{
269+
array.Add(ChatMessageContentPart.DeserializeChatMessageContentPart(item, item.GetUtf8Bytes(), options));
270+
}
271+
contentParts = array;
272+
continue;
273+
}
274274
if (prop.NameEquals("id"u8))
275275
{
276276
id = prop.Value.GetString();
@@ -280,13 +280,13 @@ internal static ChatCompletionMessageListDatum DeserializeChatCompletionMessageL
280280
}
281281
return new ChatCompletionMessageListDatum(
282282
content,
283-
contentParts ?? new ChangeTrackingList<ChatMessageContentPart>(),
284283
refusal,
285284
toolCalls ?? new ChangeTrackingList<ChatToolCall>(),
286285
annotations ?? new ChangeTrackingList<ChatMessageAnnotation>(),
287286
role,
288287
functionCall,
289288
outputAudio,
289+
contentParts ?? new ChangeTrackingList<ChatMessageContentPart>(),
290290
id,
291291
patch);
292292
}
@@ -334,35 +334,35 @@ private bool PropagateGet(ReadOnlySpan<byte> jsonPath, out JsonPatch.EncodedValu
334334
{
335335
return FunctionCall.Patch.TryGetEncodedValue([.. "$"u8, .. local.Slice("function_call"u8.Length)], out value);
336336
}
337-
if (local.StartsWith("content_parts"u8))
337+
if (local.StartsWith("tool_calls"u8))
338338
{
339-
int propertyLength = "content_parts"u8.Length;
339+
int propertyLength = "tool_calls"u8.Length;
340340
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
341341
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
342342
{
343343
return false;
344344
}
345-
return ContentParts[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
345+
return ToolCalls[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
346346
}
347-
if (local.StartsWith("tool_calls"u8))
347+
if (local.StartsWith("annotations"u8))
348348
{
349-
int propertyLength = "tool_calls"u8.Length;
349+
int propertyLength = "annotations"u8.Length;
350350
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
351351
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
352352
{
353353
return false;
354354
}
355-
return ToolCalls[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
355+
return Annotations[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
356356
}
357-
if (local.StartsWith("annotations"u8))
357+
if (local.StartsWith("content_parts"u8))
358358
{
359-
int propertyLength = "annotations"u8.Length;
359+
int propertyLength = "content_parts"u8.Length;
360360
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
361361
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
362362
{
363363
return false;
364364
}
365-
return Annotations[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
365+
return ContentParts[index].Patch.TryGetEncodedValue([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], out value);
366366
}
367367
return false;
368368
}
@@ -378,37 +378,37 @@ private bool PropagateSet(ReadOnlySpan<byte> jsonPath, JsonPatch.EncodedValue va
378378
FunctionCall.Patch.Set([.. "$"u8, .. local.Slice("function_call"u8.Length)], value);
379379
return true;
380380
}
381-
if (local.StartsWith("content_parts"u8))
381+
if (local.StartsWith("tool_calls"u8))
382382
{
383-
int propertyLength = "content_parts"u8.Length;
383+
int propertyLength = "tool_calls"u8.Length;
384384
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
385385
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
386386
{
387387
return false;
388388
}
389-
ContentParts[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
389+
ToolCalls[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
390390
return true;
391391
}
392-
if (local.StartsWith("tool_calls"u8))
392+
if (local.StartsWith("annotations"u8))
393393
{
394-
int propertyLength = "tool_calls"u8.Length;
394+
int propertyLength = "annotations"u8.Length;
395395
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
396396
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
397397
{
398398
return false;
399399
}
400-
ToolCalls[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
400+
Annotations[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
401401
return true;
402402
}
403-
if (local.StartsWith("annotations"u8))
403+
if (local.StartsWith("content_parts"u8))
404404
{
405-
int propertyLength = "annotations"u8.Length;
405+
int propertyLength = "content_parts"u8.Length;
406406
ReadOnlySpan<byte> currentSlice = local.Slice(propertyLength);
407407
if (!currentSlice.TryGetIndex(out int index, out int bytesConsumed))
408408
{
409409
return false;
410410
}
411-
Annotations[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
411+
ContentParts[index].Patch.Set([.. "$"u8, .. currentSlice.Slice(bytesConsumed)], value);
412412
return true;
413413
}
414414
return false;

src/Generated/Models/Chat/ChatCompletionMessageListDatum.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ public partial class ChatCompletionMessageListDatum
1919
internal ChatCompletionMessageListDatum(string content, string refusal, string id)
2020
{
2121
Content = content;
22-
ContentParts = new ChangeTrackingList<ChatMessageContentPart>();
2322
Refusal = refusal;
2423
ToolCalls = new ChangeTrackingList<ChatToolCall>();
2524
Annotations = new ChangeTrackingList<ChatMessageAnnotation>();
25+
ContentParts = new ChangeTrackingList<ChatMessageContentPart>();
2626
Id = id;
2727
}
2828

2929
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
30-
internal ChatCompletionMessageListDatum(string content, IList<ChatMessageContentPart> contentParts, string refusal, IReadOnlyList<ChatToolCall> toolCalls, IReadOnlyList<ChatMessageAnnotation> annotations, ChatMessageRole role, InternalChatCompletionResponseMessageFunctionCall functionCall, ChatOutputAudio outputAudio, string id, in JsonPatch patch)
30+
internal ChatCompletionMessageListDatum(string content, string refusal, IReadOnlyList<ChatToolCall> toolCalls, IReadOnlyList<ChatMessageAnnotation> annotations, ChatMessageRole role, InternalChatCompletionResponseMessageFunctionCall functionCall, ChatOutputAudio outputAudio, IList<ChatMessageContentPart> contentParts, string id, in JsonPatch patch)
3131
{
3232
// Plugin customization: ensure initialization of collections
3333
Content = content;
34-
ContentParts = contentParts ?? new ChangeTrackingList<ChatMessageContentPart>();
3534
Refusal = refusal;
3635
ToolCalls = toolCalls ?? new ChangeTrackingList<ChatToolCall>();
3736
Annotations = annotations ?? new ChangeTrackingList<ChatMessageAnnotation>();
3837
Role = role;
3938
FunctionCall = functionCall;
4039
OutputAudio = outputAudio;
40+
ContentParts = contentParts ?? new ChangeTrackingList<ChatMessageContentPart>();
4141
Id = id;
4242
_patch = patch;
4343
_patch.SetPropagators(PropagateSet, PropagateGet);
@@ -50,8 +50,6 @@ internal ChatCompletionMessageListDatum(string content, IList<ChatMessageContent
5050

5151
public string Content { get; }
5252

53-
public IList<ChatMessageContentPart> ContentParts { get; }
54-
5553
public string Refusal { get; }
5654

5755
public IReadOnlyList<ChatToolCall> ToolCalls { get; }
@@ -60,6 +58,8 @@ internal ChatCompletionMessageListDatum(string content, IList<ChatMessageContent
6058

6159
internal InternalChatCompletionResponseMessageFunctionCall FunctionCall { get; }
6260

61+
public IList<ChatMessageContentPart> ContentParts { get; }
62+
6363
public string Id { get; }
6464
}
6565
}

0 commit comments

Comments
 (0)