Skip to content

Commit 2820af5

Browse files
committed
fb
1 parent 2cbe28a commit 2820af5

15 files changed

+12946
-12543
lines changed

specification/base/typespec/responses/models.tsp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,9 +1858,9 @@ model CodeInterpreterTool extends Tool {
18581858
* Configuration for a code interpreter container. Optionally specify the IDs
18591859
* of the files to run the code on.
18601860
*/
1861-
model CodeInterpreterToolAuto /* extends CodeInterpreterContainerConfiguration */ {
1861+
model CodeInterpreterToolAuto extends CodeInterpreterContainerConfiguration {
18621862
@doc("Always `auto`.")
1863-
//type: CodeInterpreterContainerConfigurationType.auto;
1863+
type: CodeInterpreterContainerConfigurationType.auto;
18641864

18651865
/** An optional list of uploaded files to make available to your code. */
18661866
file_ids?: string[];

src/Custom/Responses/GeneratorStubs.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ namespace OpenAI.Responses;
44
[CodeGenType("CodeInterpreterToolLogsOutput")] public partial class CodeInterpreterToolLogsOutput {}
55
[CodeGenType("CodeInterpreterToolOutput")] public partial class CodeInterpreterToolOutput {}
66
[CodeGenType("CodeInterpreterToolAuto")] public partial class CodeInterpreterToolAuto {}
7+
[CodeGenType("CodeInterpreterContainerConfiguration")] public partial class CodeInterpreterContainerConfiguration {}
8+
[CodeGenType("CodeInterpreterContainerConfigurationType")] readonly partial struct CodeInterpreterContainerConfigurationType {}

src/Custom/Responses/Internal/GeneratorStubs.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ namespace OpenAI.Responses;
9696
[CodeGenType("ImageGenToolOutputFormat")] internal readonly partial struct InternalImageGenToolOutputFormat {}
9797
[CodeGenType("ImageGenToolModeration")] internal readonly partial struct InternalImageGenToolModeration {}
9898
[CodeGenType("ImageGenToolBackground")] internal readonly partial struct InternalImageGenToolBackground {}
99-
[CodeGenType("CodeInterpreterContainerConfigurationType")] internal readonly partial struct InternalCodeInterpreterContainerConfigurationType {}
100-
[CodeGenType("CodeInterpreterContainerConfiguration")] internal readonly partial struct InternalCodeInterpreterContainerConfiguration {}
10199
[CodeGenType("CodeInterpreterFileOutputType")] internal readonly partial struct InternalCodeInterpreterFileOutputType {}
102100
[CodeGenType("CodeInterpreterTextOutputType")] internal readonly partial struct InternalCodeInterpreterTextOutputType {}
103101
[CodeGenType("CodeInterpreterToolOutputType")] internal readonly partial struct InternalCodeInterpreterToolOutputType {}

src/Custom/Responses/Tools/AutomaticCodeInterpreterContainerConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public partial class CodeInterpreterToolAuto : CodeInterpreterContainerConfigura
99
{
1010

1111
/// <summary>
12-
/// Initializes a new instance of the <see cref="AutomaticCodeInterpreterContainerConfiguration"/> class.
12+
/// Initializes a new instance of the <see cref="CodeInterpreterToolAuto"/> class.
1313
/// </summary>
1414
/// <param name="fileIds"></param>
1515
public CodeInterpreterToolAuto(IEnumerable<string> fileIds = null)

src/Custom/Responses/Tools/CodeInterpreterContainerConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace OpenAI.Responses;
55
/// <summary>
66
/// Represents the configuration for a Code Interpreter container.
77
/// </summary>
8-
public class CodeInterpreterContainerConfiguration
8+
public partial class CodeInterpreterContainerConfiguration
99
{
1010

1111
/// <summary>

src/Generated/Models/OpenAIContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ namespace OpenAI
6464
[ModelReaderWriterBuildable(typeof(ChatToolChoice))]
6565
[ModelReaderWriterBuildable(typeof(ChatWebSearchOptions))]
6666
[ModelReaderWriterBuildable(typeof(CodeInterpreterCallResponseItem))]
67+
[ModelReaderWriterBuildable(typeof(CodeInterpreterContainerConfiguration))]
6768
[ModelReaderWriterBuildable(typeof(CodeInterpreterTool))]
6869
[ModelReaderWriterBuildable(typeof(CodeInterpreterToolAuto))]
6970
[ModelReaderWriterBuildable(typeof(CodeInterpreterToolDefinition))]
@@ -579,6 +580,7 @@ namespace OpenAI
579580
[ModelReaderWriterBuildable(typeof(InternalUnknownChatResponseFormat))]
580581
[ModelReaderWriterBuildable(typeof(InternalUnknownChunkingStrategyRequestParamProxy))]
581582
[ModelReaderWriterBuildable(typeof(InternalUnknownChunkingStrategyResponseParam))]
583+
[ModelReaderWriterBuildable(typeof(InternalUnknownCodeInterpreterContainerConfiguration))]
582584
[ModelReaderWriterBuildable(typeof(InternalUnknownCodeInterpreterToolOutput))]
583585
[ModelReaderWriterBuildable(typeof(InternalUnknownComparisonFilter))]
584586
[ModelReaderWriterBuildable(typeof(InternalUnknownCompoundFilter))]
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.ClientModel.Primitives;
7+
using System.Text.Json;
8+
using OpenAI;
9+
10+
namespace OpenAI.Responses
11+
{
12+
[PersistableModelProxy(typeof(InternalUnknownCodeInterpreterContainerConfiguration))]
13+
public partial class CodeInterpreterContainerConfiguration : IJsonModel<CodeInterpreterContainerConfiguration>
14+
{
15+
internal CodeInterpreterContainerConfiguration()
16+
{
17+
}
18+
19+
void IJsonModel<CodeInterpreterContainerConfiguration>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
20+
{
21+
writer.WriteStartObject();
22+
JsonModelWriteCore(writer, options);
23+
writer.WriteEndObject();
24+
}
25+
26+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
27+
{
28+
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterContainerConfiguration>)this).GetFormatFromOptions(options) : options.Format;
29+
if (format != "J")
30+
{
31+
throw new FormatException($"The model {nameof(CodeInterpreterContainerConfiguration)} does not support writing '{format}' format.");
32+
}
33+
if (_additionalBinaryDataProperties?.ContainsKey("type") != true)
34+
{
35+
writer.WritePropertyName("type"u8);
36+
writer.WriteStringValue(Kind.ToString());
37+
}
38+
// Plugin customization: remove options.Format != "W" check
39+
if (_additionalBinaryDataProperties != null)
40+
{
41+
foreach (var item in _additionalBinaryDataProperties)
42+
{
43+
if (ModelSerializationExtensions.IsSentinelValue(item.Value))
44+
{
45+
continue;
46+
}
47+
writer.WritePropertyName(item.Key);
48+
#if NET6_0_OR_GREATER
49+
writer.WriteRawValue(item.Value);
50+
#else
51+
using (JsonDocument document = JsonDocument.Parse(item.Value))
52+
{
53+
JsonSerializer.Serialize(writer, document.RootElement);
54+
}
55+
#endif
56+
}
57+
}
58+
}
59+
60+
CodeInterpreterContainerConfiguration IJsonModel<CodeInterpreterContainerConfiguration>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
61+
62+
protected virtual CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
63+
{
64+
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterContainerConfiguration>)this).GetFormatFromOptions(options) : options.Format;
65+
if (format != "J")
66+
{
67+
throw new FormatException($"The model {nameof(CodeInterpreterContainerConfiguration)} does not support reading '{format}' format.");
68+
}
69+
using JsonDocument document = JsonDocument.ParseValue(ref reader);
70+
return DeserializeCodeInterpreterContainerConfiguration(document.RootElement, options);
71+
}
72+
73+
internal static CodeInterpreterContainerConfiguration DeserializeCodeInterpreterContainerConfiguration(JsonElement element, ModelReaderWriterOptions options)
74+
{
75+
if (element.ValueKind == JsonValueKind.Null)
76+
{
77+
return null;
78+
}
79+
if (element.TryGetProperty("type"u8, out JsonElement discriminator))
80+
{
81+
switch (discriminator.GetString())
82+
{
83+
case "auto":
84+
return CodeInterpreterToolAuto.DeserializeCodeInterpreterToolAuto(element, options);
85+
}
86+
}
87+
return InternalUnknownCodeInterpreterContainerConfiguration.DeserializeInternalUnknownCodeInterpreterContainerConfiguration(element, options);
88+
}
89+
90+
BinaryData IPersistableModel<CodeInterpreterContainerConfiguration>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
91+
92+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
93+
{
94+
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterContainerConfiguration>)this).GetFormatFromOptions(options) : options.Format;
95+
switch (format)
96+
{
97+
case "J":
98+
return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
99+
default:
100+
throw new FormatException($"The model {nameof(CodeInterpreterContainerConfiguration)} does not support writing '{options.Format}' format.");
101+
}
102+
}
103+
104+
CodeInterpreterContainerConfiguration IPersistableModel<CodeInterpreterContainerConfiguration>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
105+
106+
protected virtual CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
107+
{
108+
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterContainerConfiguration>)this).GetFormatFromOptions(options) : options.Format;
109+
switch (format)
110+
{
111+
case "J":
112+
using (JsonDocument document = JsonDocument.Parse(data))
113+
{
114+
return DeserializeCodeInterpreterContainerConfiguration(document.RootElement, options);
115+
}
116+
default:
117+
throw new FormatException($"The model {nameof(CodeInterpreterContainerConfiguration)} does not support reading '{options.Format}' format.");
118+
}
119+
}
120+
121+
string IPersistableModel<CodeInterpreterContainerConfiguration>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
122+
}
123+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics.CodeAnalysis;
8+
9+
namespace OpenAI.Responses
10+
{
11+
[Experimental("OPENAI001")]
12+
public partial class CodeInterpreterContainerConfiguration
13+
{
14+
private protected IDictionary<string, BinaryData> _additionalBinaryDataProperties;
15+
16+
private protected CodeInterpreterContainerConfiguration(CodeInterpreterContainerConfigurationType kind)
17+
{
18+
Kind = kind;
19+
}
20+
21+
internal CodeInterpreterContainerConfiguration(CodeInterpreterContainerConfigurationType kind, IDictionary<string, BinaryData> additionalBinaryDataProperties)
22+
{
23+
Kind = kind;
24+
_additionalBinaryDataProperties = additionalBinaryDataProperties;
25+
}
26+
27+
internal CodeInterpreterContainerConfigurationType Kind { get; set; }
28+
29+
internal IDictionary<string, BinaryData> SerializedAdditionalRawData
30+
{
31+
get => _additionalBinaryDataProperties;
32+
set => _additionalBinaryDataProperties = value;
33+
}
34+
}
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// <auto-generated/>
2+
3+
#nullable disable
4+
5+
using System;
6+
using System.ComponentModel;
7+
using OpenAI;
8+
9+
namespace OpenAI.Responses
10+
{
11+
internal readonly partial struct CodeInterpreterContainerConfigurationType : IEquatable<CodeInterpreterContainerConfigurationType>
12+
{
13+
private readonly string _value;
14+
private const string AutoValue = "auto";
15+
16+
public CodeInterpreterContainerConfigurationType(string value)
17+
{
18+
Argument.AssertNotNull(value, nameof(value));
19+
20+
_value = value;
21+
}
22+
23+
internal static CodeInterpreterContainerConfigurationType Auto { get; } = new CodeInterpreterContainerConfigurationType(AutoValue);
24+
25+
public static bool operator ==(CodeInterpreterContainerConfigurationType left, CodeInterpreterContainerConfigurationType right) => left.Equals(right);
26+
27+
public static bool operator !=(CodeInterpreterContainerConfigurationType left, CodeInterpreterContainerConfigurationType right) => !left.Equals(right);
28+
29+
public static implicit operator CodeInterpreterContainerConfigurationType(string value) => new CodeInterpreterContainerConfigurationType(value);
30+
31+
public static implicit operator CodeInterpreterContainerConfigurationType?(string value) => value == null ? null : new CodeInterpreterContainerConfigurationType(value);
32+
33+
[EditorBrowsable(EditorBrowsableState.Never)]
34+
public override bool Equals(object obj) => obj is CodeInterpreterContainerConfigurationType other && Equals(other);
35+
36+
public bool Equals(CodeInterpreterContainerConfigurationType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase);
37+
38+
[EditorBrowsable(EditorBrowsableState.Never)]
39+
public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0;
40+
41+
public override string ToString() => _value;
42+
}
43+
}

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

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ void IJsonModel<CodeInterpreterToolAuto>.Write(Utf8JsonWriter writer, ModelReade
1919
writer.WriteEndObject();
2020
}
2121

22-
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
22+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
2323
{
2424
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterToolAuto>)this).GetFormatFromOptions(options) : options.Format;
2525
if (format != "J")
2626
{
2727
throw new FormatException($"The model {nameof(CodeInterpreterToolAuto)} does not support writing '{format}' format.");
2828
}
29+
base.JsonModelWriteCore(writer, options);
2930
if (Optional.IsCollectionDefined(FileIds) && _additionalBinaryDataProperties?.ContainsKey("file_ids") != true)
3031
{
3132
writer.WritePropertyName("file_ids"u8);
@@ -41,31 +42,11 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit
4142
}
4243
writer.WriteEndArray();
4344
}
44-
// Plugin customization: remove options.Format != "W" check
45-
if (_additionalBinaryDataProperties != null)
46-
{
47-
foreach (var item in _additionalBinaryDataProperties)
48-
{
49-
if (ModelSerializationExtensions.IsSentinelValue(item.Value))
50-
{
51-
continue;
52-
}
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))
58-
{
59-
JsonSerializer.Serialize(writer, document.RootElement);
60-
}
61-
#endif
62-
}
63-
}
6445
}
6546

66-
CodeInterpreterToolAuto IJsonModel<CodeInterpreterToolAuto>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => JsonModelCreateCore(ref reader, options);
47+
CodeInterpreterToolAuto IJsonModel<CodeInterpreterToolAuto>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (CodeInterpreterToolAuto)JsonModelCreateCore(ref reader, options);
6748

68-
protected virtual CodeInterpreterToolAuto JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
49+
protected override CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
6950
{
7051
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterToolAuto>)this).GetFormatFromOptions(options) : options.Format;
7152
if (format != "J")
@@ -82,10 +63,16 @@ internal static CodeInterpreterToolAuto DeserializeCodeInterpreterToolAuto(JsonE
8263
{
8364
return null;
8465
}
85-
IList<string> fileIds = default;
66+
CodeInterpreterContainerConfigurationType kind = default;
8667
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
68+
IList<string> fileIds = default;
8769
foreach (var prop in element.EnumerateObject())
8870
{
71+
if (prop.NameEquals("type"u8))
72+
{
73+
kind = new CodeInterpreterContainerConfigurationType(prop.Value.GetString());
74+
continue;
75+
}
8976
if (prop.NameEquals("file_ids"u8))
9077
{
9178
if (prop.Value.ValueKind == JsonValueKind.Null)
@@ -110,12 +97,12 @@ internal static CodeInterpreterToolAuto DeserializeCodeInterpreterToolAuto(JsonE
11097
// Plugin customization: remove options.Format != "W" check
11198
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
11299
}
113-
return new CodeInterpreterToolAuto(fileIds ?? new ChangeTrackingList<string>(), additionalBinaryDataProperties);
100+
return new CodeInterpreterToolAuto(kind, additionalBinaryDataProperties, fileIds ?? new ChangeTrackingList<string>());
114101
}
115102

116103
BinaryData IPersistableModel<CodeInterpreterToolAuto>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
117104

118-
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
105+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
119106
{
120107
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterToolAuto>)this).GetFormatFromOptions(options) : options.Format;
121108
switch (format)
@@ -127,9 +114,9 @@ protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions
127114
}
128115
}
129116

130-
CodeInterpreterToolAuto IPersistableModel<CodeInterpreterToolAuto>.Create(BinaryData data, ModelReaderWriterOptions options) => PersistableModelCreateCore(data, options);
117+
CodeInterpreterToolAuto IPersistableModel<CodeInterpreterToolAuto>.Create(BinaryData data, ModelReaderWriterOptions options) => (CodeInterpreterToolAuto)PersistableModelCreateCore(data, options);
131118

132-
protected virtual CodeInterpreterToolAuto PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
119+
protected override CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
133120
{
134121
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterToolAuto>)this).GetFormatFromOptions(options) : options.Format;
135122
switch (format)

0 commit comments

Comments
 (0)