Skip to content

Commit 4f7deb8

Browse files
committed
Add JP
1 parent 6705866 commit 4f7deb8

File tree

8 files changed

+63
-43
lines changed

8 files changed

+63
-43
lines changed

api/OpenAI.net8.0.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6650,6 +6650,9 @@ public class WebSearchToolApproximateLocation : WebSearchToolLocation, IJsonMode
66506650
[Experimental("OPENAI001")]
66516651
public class WebSearchToolFilters : IJsonModel<WebSearchToolFilters>, IPersistableModel<WebSearchToolFilters> {
66526652
public IList<string> AllowedDomains { get; set; }
6653+
[EditorBrowsable(EditorBrowsableState.Never)]
6654+
[Experimental("SCME0001")]
6655+
public ref JsonPatch Patch { get; }
66536656
protected virtual WebSearchToolFilters JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
66546657
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
66556658
protected virtual WebSearchToolFilters PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);

api/OpenAI.netstandard2.0.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5851,6 +5851,8 @@ public class WebSearchToolApproximateLocation : WebSearchToolLocation, IJsonMode
58515851
}
58525852
public class WebSearchToolFilters : IJsonModel<WebSearchToolFilters>, IPersistableModel<WebSearchToolFilters> {
58535853
public IList<string> AllowedDomains { get; set; }
5854+
[EditorBrowsable(EditorBrowsableState.Never)]
5855+
public ref JsonPatch Patch { get; }
58545856
protected virtual WebSearchToolFilters JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
58555857
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
58565858
protected virtual WebSearchToolFilters PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);

specification/client/responses.client.tsp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ using TypeSpec.HttpClient.CSharp;
214214
@@dynamicModel(ResponseCodeInterpreterCallInterpretingEvent);
215215
@@dynamicModel(TopLogProb);
216216
@@dynamicModel(LogProb);
217+
@@dynamicModel(WebSearchToolFilters);
217218
// custom.tsp models
218219
@@dynamicModel(ResponseErrorResponse);
219220
@@dynamicModel(DeleteResponseResponse);

src/Generated/Models/Responses/WebSearchTool.Serialization.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ internal static WebSearchTool DeserializeWebSearchTool(JsonElement element, Bina
9696
filters = null;
9797
continue;
9898
}
99-
filters = WebSearchToolFilters.DeserializeWebSearchToolFilters(prop.Value, options);
99+
filters = WebSearchToolFilters.DeserializeWebSearchToolFilters(prop.Value, prop.Value.GetUtf8Bytes(), options);
100100
continue;
101101
}
102102
if (prop.NameEquals("user_location"u8))

src/Generated/Models/Responses/WebSearchToolFilters.Serialization.cs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System;
66
using System.ClientModel.Primitives;
77
using System.Collections.Generic;
8+
using System.Text;
89
using System.Text.Json;
910
using OpenAI;
1011

@@ -14,6 +15,14 @@ public partial class WebSearchToolFilters : IJsonModel<WebSearchToolFilters>
1415
{
1516
void IJsonModel<WebSearchToolFilters>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
1617
{
18+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
19+
if (Patch.Contains("$"u8))
20+
{
21+
writer.WriteRawValue(Patch.GetJson("$"u8));
22+
return;
23+
}
24+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
25+
1726
writer.WriteStartObject();
1827
JsonModelWriteCore(writer, options);
1928
writer.WriteEndObject();
@@ -26,41 +35,38 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
2635
{
2736
throw new FormatException($"The model {nameof(WebSearchToolFilters)} does not support writing '{format}' format.");
2837
}
29-
if (Optional.IsCollectionDefined(AllowedDomains) && _additionalBinaryDataProperties?.ContainsKey("allowed_domains") != true)
38+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
39+
if (Patch.Contains("$.allowed_domains"u8))
3040
{
31-
writer.WritePropertyName("allowed_domains"u8);
32-
writer.WriteStartArray();
33-
foreach (string item in AllowedDomains)
41+
if (!Patch.IsRemoved("$.allowed_domains"u8))
3442
{
35-
if (item == null)
36-
{
37-
writer.WriteNullValue();
38-
continue;
39-
}
40-
writer.WriteStringValue(item);
43+
writer.WritePropertyName("allowed_domains"u8);
44+
writer.WriteRawValue(Patch.GetJson("$.allowed_domains"u8));
4145
}
42-
writer.WriteEndArray();
4346
}
44-
// Plugin customization: remove options.Format != "W" check
45-
if (_additionalBinaryDataProperties != null)
47+
else if (Optional.IsCollectionDefined(AllowedDomains))
4648
{
47-
foreach (var item in _additionalBinaryDataProperties)
49+
writer.WritePropertyName("allowed_domains"u8);
50+
writer.WriteStartArray();
51+
for (int i = 0; i < AllowedDomains.Count; i++)
4852
{
49-
if (ModelSerializationExtensions.IsSentinelValue(item.Value))
53+
if (Patch.IsRemoved(Encoding.UTF8.GetBytes($"$.allowed_domains[{i}]")))
5054
{
5155
continue;
5256
}
53-
writer.WritePropertyName(item.Key);
54-
#if NET6_0_OR_GREATER
55-
writer.WriteRawValue(item.Value);
56-
#else
57-
using (JsonDocument document = JsonDocument.Parse(item.Value))
57+
if (AllowedDomains[i] == null)
5858
{
59-
JsonSerializer.Serialize(writer, document.RootElement);
59+
writer.WriteNullValue();
60+
continue;
6061
}
61-
#endif
62+
writer.WriteStringValue(AllowedDomains[i]);
6263
}
64+
Patch.WriteTo(writer, "$.allowed_domains"u8);
65+
writer.WriteEndArray();
6366
}
67+
68+
Patch.WriteTo(writer);
69+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
6470
}
6571

6672
WebSearchToolFilters IJsonModel<WebSearchToolFilters>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
@@ -73,17 +79,19 @@ protected virtual WebSearchToolFilters JsonModelCreateCore(ref Utf8JsonReader re
7379
throw new FormatException($"The model {nameof(WebSearchToolFilters)} does not support reading '{format}' format.");
7480
}
7581
using JsonDocument document = JsonDocument.ParseValue(ref reader);
76-
return DeserializeWebSearchToolFilters(document.RootElement, options);
82+
return DeserializeWebSearchToolFilters(document.RootElement, null, options);
7783
}
7884

79-
internal static WebSearchToolFilters DeserializeWebSearchToolFilters(JsonElement element, ModelReaderWriterOptions options)
85+
internal static WebSearchToolFilters DeserializeWebSearchToolFilters(JsonElement element, BinaryData data, ModelReaderWriterOptions options)
8086
{
8187
if (element.ValueKind == JsonValueKind.Null)
8288
{
8389
return null;
8490
}
8591
IList<string> allowedDomains = default;
86-
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
92+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
93+
JsonPatch patch = new JsonPatch(data is null ? ReadOnlyMemory<byte>.Empty : data.ToMemory());
94+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
8795
foreach (var prop in element.EnumerateObject())
8896
{
8997
if (prop.NameEquals("allowed_domains"u8))
@@ -107,10 +115,9 @@ internal static WebSearchToolFilters DeserializeWebSearchToolFilters(JsonElement
107115
allowedDomains = array;
108116
continue;
109117
}
110-
// Plugin customization: remove options.Format != "W" check
111-
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
118+
patch.Set([.. "$."u8, .. Encoding.UTF8.GetBytes(prop.Name)], prop.Value.GetUtf8Bytes());
112119
}
113-
return new WebSearchToolFilters(allowedDomains ?? new ChangeTrackingList<string>(), additionalBinaryDataProperties);
120+
return new WebSearchToolFilters(allowedDomains ?? new ChangeTrackingList<string>(), patch);
114121
}
115122

116123
BinaryData IPersistableModel<WebSearchToolFilters>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
@@ -137,7 +144,7 @@ protected virtual WebSearchToolFilters PersistableModelCreateCore(BinaryData dat
137144
case "J":
138145
using (JsonDocument document = JsonDocument.Parse(data))
139146
{
140-
return DeserializeWebSearchToolFilters(document.RootElement, options);
147+
return DeserializeWebSearchToolFilters(document.RootElement, data, options);
141148
}
142149
default:
143150
throw new FormatException($"The model {nameof(WebSearchToolFilters)} does not support reading '{options.Format}' format.");

src/Generated/Models/Responses/WebSearchToolFilters.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
#nullable disable
44

5-
using System;
5+
using System.ClientModel.Primitives;
66
using System.Collections.Generic;
7+
using System.ComponentModel;
78
using System.Diagnostics.CodeAnalysis;
89
using OpenAI;
910

@@ -12,25 +13,26 @@ namespace OpenAI.Responses
1213
[Experimental("OPENAI001")]
1314
public partial class WebSearchToolFilters
1415
{
15-
private protected IDictionary<string, BinaryData> _additionalBinaryDataProperties;
16+
[Experimental("SCME0001")]
17+
private JsonPatch _patch;
1618

17-
public WebSearchToolFilters() : this(null, null)
19+
public WebSearchToolFilters() : this(null, default)
1820
{
1921
}
2022

21-
internal WebSearchToolFilters(IList<string> allowedDomains, IDictionary<string, BinaryData> additionalBinaryDataProperties)
23+
#pragma warning disable SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
24+
internal WebSearchToolFilters(IList<string> allowedDomains, in JsonPatch patch)
2225
{
2326
// Plugin customization: ensure initialization of collections
2427
AllowedDomains = allowedDomains ?? new ChangeTrackingList<string>();
25-
_additionalBinaryDataProperties = additionalBinaryDataProperties;
28+
_patch = patch;
2629
}
30+
#pragma warning restore SCME0001 // Type is for evaluation purposes only and is subject to change or removal in future updates.
2731

28-
public IList<string> AllowedDomains { get; set; }
32+
[EditorBrowsable(EditorBrowsableState.Never)]
33+
[Experimental("SCME0001")]
34+
public ref JsonPatch Patch => ref _patch;
2935

30-
internal IDictionary<string, BinaryData> SerializedAdditionalRawData
31-
{
32-
get => _additionalBinaryDataProperties;
33-
set => _additionalBinaryDataProperties = value;
34-
}
36+
public IList<string> AllowedDomains { get; set; }
3537
}
3638
}

src/Generated/OpenAIModelFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ public static WebSearchToolFilters WebSearchToolFilters(IEnumerable<string> allo
566566
{
567567
allowedDomains ??= new ChangeTrackingList<string>();
568568

569-
return new WebSearchToolFilters(allowedDomains.ToList(), additionalBinaryDataProperties: null);
569+
return new WebSearchToolFilters(allowedDomains.ToList(), default);
570570
}
571571

572572
public static ImageGenerationToolInputImageMask ImageGenerationToolInputImageMask(string imageUrl = default, string fileId = default)

tspCodeModel.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54206,7 +54206,12 @@
5420654206
"namespace": "OpenAI",
5420754207
"crossLanguageDefinitionId": "OpenAI.WebSearchToolFilters",
5420854208
"usage": "Input,Output,Json",
54209-
"decorators": [],
54209+
"decorators": [
54210+
{
54211+
"name": "TypeSpec.HttpClient.CSharp.@dynamicModel",
54212+
"arguments": {}
54213+
}
54214+
],
5421054215
"properties": [
5421154216
{
5421254217
"$id": "4478",

0 commit comments

Comments
 (0)