Skip to content

Commit 03aaeec

Browse files
committed
fb
1 parent 0fd66a5 commit 03aaeec

25 files changed

+2290
-2052
lines changed

api/OpenAI.net8.0.cs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4602,6 +4602,16 @@ public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistab
46024602
}
46034603
}
46044604
namespace OpenAI.Responses {
4605+
[Experimental("OPENAI001")]
4606+
public class AutomaticCodeInterpreterContainerConfiguration : CodeInterpreterContainerConfiguration, IJsonModel<AutomaticCodeInterpreterContainerConfiguration>, IPersistableModel<AutomaticCodeInterpreterContainerConfiguration> {
4607+
public AutomaticCodeInterpreterContainerConfiguration();
4608+
public AutomaticCodeInterpreterContainerConfiguration(IEnumerable<string> fileIds = null);
4609+
public IList<string> FileIds { get; }
4610+
protected override CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4611+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4612+
protected override CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4613+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4614+
}
46054615
[Experimental("OPENAI001")]
46064616
public class CodeInterpreterCallResponseItem : ResponseItem, IJsonModel<CodeInterpreterCallResponseItem>, IPersistableModel<CodeInterpreterCallResponseItem> {
46074617
public CodeInterpreterCallResponseItem(string code);
@@ -4621,39 +4631,35 @@ public enum CodeInterpreterCallStatus {
46214631
Incomplete = 3,
46224632
Failed = 4
46234633
}
4624-
public class CodeInterpreterContainer {
4634+
[Experimental("OPENAI001")]
4635+
public class CodeInterpreterContainer : IJsonModel<CodeInterpreterContainer>, IPersistableModel<CodeInterpreterContainer> {
46254636
public CodeInterpreterContainer(CodeInterpreterContainerConfiguration containerConfiguration);
46264637
public CodeInterpreterContainer(string containerId);
4627-
public CodeInterpreterContainerConfiguration ContainerConfiguration { get; }
4628-
public string ContainerId { get; }
4638+
public CodeInterpreterContainerConfiguration Container { get; set; }
4639+
public string ContainerId { get; set; }
4640+
protected virtual CodeInterpreterContainer JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4641+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4642+
protected virtual CodeInterpreterContainer PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4643+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
46294644
}
46304645
[Experimental("OPENAI001")]
46314646
public class CodeInterpreterContainerConfiguration : IJsonModel<CodeInterpreterContainerConfiguration>, IPersistableModel<CodeInterpreterContainerConfiguration> {
4632-
public static CodeInterpreterToolAuto CreateAutomaticConfiguration(IEnumerable<string> fileIds = null);
4647+
public static AutomaticCodeInterpreterContainerConfiguration CreateAutomaticConfiguration(IEnumerable<string> fileIds = null);
46334648
protected virtual CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
46344649
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
46354650
protected virtual CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
46364651
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
46374652
}
46384653
[Experimental("OPENAI001")]
46394654
public class CodeInterpreterTool : ResponseTool, IJsonModel<CodeInterpreterTool>, IPersistableModel<CodeInterpreterTool> {
4655+
public CodeInterpreterTool(CodeInterpreterContainer container);
46404656
public CodeInterpreterContainer Container { get; }
46414657
protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
46424658
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
46434659
protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
46444660
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
46454661
}
46464662
[Experimental("OPENAI001")]
4647-
public class CodeInterpreterToolAuto : CodeInterpreterContainerConfiguration, IJsonModel<CodeInterpreterToolAuto>, IPersistableModel<CodeInterpreterToolAuto> {
4648-
public CodeInterpreterToolAuto();
4649-
public CodeInterpreterToolAuto(IEnumerable<string> fileIds = null);
4650-
public IList<string> FileIds { get; }
4651-
protected override CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4652-
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4653-
protected override CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4654-
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4655-
}
4656-
[Experimental("OPENAI001")]
46574663
public class CodeInterpreterToolImageOutput : CodeInterpreterToolOutput, IJsonModel<CodeInterpreterToolImageOutput>, IPersistableModel<CodeInterpreterToolImageOutput> {
46584664
public CodeInterpreterToolImageOutput(Uri imageUri);
46594665
public Uri ImageUri { get; set; }

api/OpenAI.netstandard2.0.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4035,6 +4035,15 @@ public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistab
40354035
}
40364036
}
40374037
namespace OpenAI.Responses {
4038+
public class AutomaticCodeInterpreterContainerConfiguration : CodeInterpreterContainerConfiguration, IJsonModel<AutomaticCodeInterpreterContainerConfiguration>, IPersistableModel<AutomaticCodeInterpreterContainerConfiguration> {
4039+
public AutomaticCodeInterpreterContainerConfiguration();
4040+
public AutomaticCodeInterpreterContainerConfiguration(IEnumerable<string> fileIds = null);
4041+
public IList<string> FileIds { get; }
4042+
protected override CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4043+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4044+
protected override CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4045+
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4046+
}
40384047
public class CodeInterpreterCallResponseItem : ResponseItem, IJsonModel<CodeInterpreterCallResponseItem>, IPersistableModel<CodeInterpreterCallResponseItem> {
40394048
public CodeInterpreterCallResponseItem(string code);
40404049
public string Code { get; set; }
@@ -4053,35 +4062,31 @@ public enum CodeInterpreterCallStatus {
40534062
Incomplete = 3,
40544063
Failed = 4
40554064
}
4056-
public class CodeInterpreterContainer {
4065+
public class CodeInterpreterContainer : IJsonModel<CodeInterpreterContainer>, IPersistableModel<CodeInterpreterContainer> {
40574066
public CodeInterpreterContainer(CodeInterpreterContainerConfiguration containerConfiguration);
40584067
public CodeInterpreterContainer(string containerId);
4059-
public CodeInterpreterContainerConfiguration ContainerConfiguration { get; }
4060-
public string ContainerId { get; }
4068+
public CodeInterpreterContainerConfiguration Container { get; set; }
4069+
public string ContainerId { get; set; }
4070+
protected virtual CodeInterpreterContainer JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4071+
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4072+
protected virtual CodeInterpreterContainer PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4073+
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
40614074
}
40624075
public class CodeInterpreterContainerConfiguration : IJsonModel<CodeInterpreterContainerConfiguration>, IPersistableModel<CodeInterpreterContainerConfiguration> {
4063-
public static CodeInterpreterToolAuto CreateAutomaticConfiguration(IEnumerable<string> fileIds = null);
4076+
public static AutomaticCodeInterpreterContainerConfiguration CreateAutomaticConfiguration(IEnumerable<string> fileIds = null);
40644077
protected virtual CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
40654078
protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
40664079
protected virtual CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
40674080
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
40684081
}
40694082
public class CodeInterpreterTool : ResponseTool, IJsonModel<CodeInterpreterTool>, IPersistableModel<CodeInterpreterTool> {
4083+
public CodeInterpreterTool(CodeInterpreterContainer container);
40704084
public CodeInterpreterContainer Container { get; }
40714085
protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
40724086
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
40734087
protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
40744088
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
40754089
}
4076-
public class CodeInterpreterToolAuto : CodeInterpreterContainerConfiguration, IJsonModel<CodeInterpreterToolAuto>, IPersistableModel<CodeInterpreterToolAuto> {
4077-
public CodeInterpreterToolAuto();
4078-
public CodeInterpreterToolAuto(IEnumerable<string> fileIds = null);
4079-
public IList<string> FileIds { get; }
4080-
protected override CodeInterpreterContainerConfiguration JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
4081-
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
4082-
protected override CodeInterpreterContainerConfiguration PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
4083-
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
4084-
}
40854090
public class CodeInterpreterToolImageOutput : CodeInterpreterToolOutput, IJsonModel<CodeInterpreterToolImageOutput>, IPersistableModel<CodeInterpreterToolImageOutput> {
40864091
public CodeInterpreterToolImageOutput(Uri imageUri);
40874092
public Uri ImageUri { get; set; }

specification/client/models/responses.models.tsp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ union ResponseItemCollectionOrder {
3030
@access(Access.public)
3131
@usage(Usage.input)
3232
model ResponseItemCollectionOptions {
33-
...CollectionAfterQueryParameter,
34-
...CollectionBeforeQueryParameter,
35-
...CollectionLimitQueryParameter,
36-
...ResponseItemCollectionOrderQueryParameter,
33+
...CollectionAfterQueryParameter;
34+
...CollectionBeforeQueryParameter;
35+
...CollectionLimitQueryParameter;
36+
...ResponseItemCollectionOrderQueryParameter;
3737
}
3838

3939
@access(Access.public)
@@ -52,6 +52,7 @@ model DotNetCustomToolCallApprovalPolicy {
5252
/** List of tools that require approval. */
5353
tool_names?: string[];
5454
};
55+
5556
/** A list of tools that never require approval. */
5657
`never`?: {
5758
/** List of tools that do not require approval. */
@@ -61,7 +62,14 @@ model DotNetCustomToolCallApprovalPolicy {
6162

6263
@access(Access.public)
6364
@usage(Usage.input | Usage.output)
64-
model DotNetToolCallApprovalPolicy{
65+
model DotNetToolCallApprovalPolicy {
6566
global_policy?: DotNetGlobalToolCallApprovalPolicy;
6667
custom_policy?: DotNetCustomToolCallApprovalPolicy;
67-
}
68+
}
69+
70+
@access(Access.public)
71+
@usage(Usage.input | Usage.output)
72+
model DotNetCodeInterpreterContainer {
73+
container_id?: string;
74+
container?: CodeInterpreterContainerConfiguration;
75+
}

src/Custom/Responses/GeneratorStubs.cs

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

src/Custom/Responses/Internal/GeneratorStubs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace OpenAI.Responses;
22

3+
[CodeGenType("CodeInterpreterContainerConfigurationType")] internal readonly partial struct InternalCodeInterpreterContainerConfigurationType {}
34
[CodeGenType("ComparisonFilter")] internal partial class InternalComparisonFilter {}
45
[CodeGenType("ComparisonFilterEquals")] internal partial class InternalComparisonFilterEquals {}
56
[CodeGenType("ComparisonFilterGreaterThan")] internal partial class InternalComparisonFilterGreaterThan {}

src/Custom/Responses/Tools/CodeInterpreterContainer.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ namespace OpenAI.Responses;
66
/// <summary>
77
/// Represents a container for the code interpreter tool.
88
/// </summary>
9-
public class CodeInterpreterContainer
9+
[CodeGenType("DotNetCodeInterpreterContainer")]
10+
public partial class CodeInterpreterContainer
1011
{
12+
internal CodeInterpreterContainer()
13+
{
14+
}
15+
1116
/// <summary>
1217
/// Initializes a new instance of the <see cref="CodeInterpreterContainer"/> class.
1318
/// </summary>
@@ -23,24 +28,14 @@ public CodeInterpreterContainer(string containerId)
2328
/// <param name="containerConfiguration">The configuration of the container.</param>
2429
public CodeInterpreterContainer(CodeInterpreterContainerConfiguration containerConfiguration)
2530
{
26-
ContainerConfiguration = containerConfiguration;
31+
Container = containerConfiguration;
2732
}
2833

29-
/// <summary>
30-
/// Gets the ID of the container.
31-
/// </summary>
32-
public string ContainerId { get; }
33-
34-
/// <summary>
35-
/// Gets the configuration of the container.
36-
/// </summary>
37-
public CodeInterpreterContainerConfiguration ContainerConfiguration { get; }
38-
3934
internal BinaryData AsBinaryData()
4035
{
4136
return this.ContainerId != null
4237
? new BinaryData($"\"{ContainerId}\"")
43-
: ContainerConfiguration is AutomaticCodeInterpreterContainerConfiguration autoConfig && autoConfig.FileIds?.Any() == true ?
38+
: Container is AutomaticCodeInterpreterContainerConfiguration autoConfig && autoConfig.FileIds?.Any() == true ?
4439
new BinaryData($"{{\"type\": \"auto\", \"file_ids\": [{string.Join(", ", autoConfig.FileIds.Select(id => $"\"{id}\""))}]}}") :
4540
new BinaryData("{\"type\": \"auto\"}");
4641
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System;
2+
using System.ClientModel.Primitives;
3+
using System.Collections.Generic;
4+
using System.Text.Json;
5+
using OpenAI;
6+
7+
namespace OpenAI.Responses
8+
{
9+
public partial class CodeInterpreterTool : IJsonModel<CodeInterpreterTool>
10+
{
11+
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
12+
{
13+
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
14+
if (format != "J")
15+
{
16+
throw new FormatException($"The model {nameof(CodeInterpreterTool)} does not support writing '{format}' format.");
17+
}
18+
base.JsonModelWriteCore(writer, options);
19+
if (_additionalBinaryDataProperties?.ContainsKey("container") != true)
20+
{
21+
writer.WritePropertyName("container"u8);
22+
#if NET6_0_OR_GREATER
23+
writer.WriteRawValue(Container.AsBinaryData());
24+
#else
25+
using (JsonDocument document = JsonDocument.Parse(Container.AsBinaryData()))
26+
{
27+
JsonSerializer.Serialize(writer, document.RootElement);
28+
}
29+
#endif
30+
}
31+
}
32+
33+
internal static CodeInterpreterTool DeserializeCodeInterpreterTool(JsonElement element, ModelReaderWriterOptions options)
34+
{
35+
if (element.ValueKind == JsonValueKind.Null)
36+
{
37+
return null;
38+
}
39+
InternalToolType kind = default;
40+
IDictionary<string, BinaryData> additionalBinaryDataProperties = new ChangeTrackingDictionary<string, BinaryData>();
41+
CodeInterpreterContainer container = default;
42+
43+
foreach (var prop in element.EnumerateObject())
44+
{
45+
if (prop.NameEquals("type"u8))
46+
{
47+
kind = new InternalToolType(prop.Value.GetString());
48+
continue;
49+
}
50+
if (prop.NameEquals("container"u8))
51+
{
52+
container = CodeInterpreterContainer.DeserializeCodeInterpreterContainer(prop.Value, options);
53+
continue;
54+
}
55+
// Plugin customization: remove options.Format != "W" check
56+
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
57+
}
58+
return new CodeInterpreterTool(kind, additionalBinaryDataProperties, container);
59+
}
60+
}
61+
}

src/Custom/Responses/Tools/CodeInterpreterTool.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ namespace OpenAI.Responses;
44

55
// CUSTOM: correct namespace / customize Container property.
66
[CodeGenType("CodeInterpreterTool")]
7-
[CodeGenVisibility(nameof(CodeInterpreterTool), CodeGenVisibility.Internal, typeof(BinaryData))]
87
public partial class CodeInterpreterTool
98
{
109
[CodeGenMember("Container")]
11-
internal BinaryData InternalContainer { get; }
12-
1310
public CodeInterpreterContainer Container { get; }
1411
}

src/Custom/Responses/Tools/ResponseTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ public static CodeInterpreterTool CreateCodeInterpreterTool(CodeInterpreterConta
8787
return new CodeInterpreterTool(
8888
kind: InternalToolType.CodeInterpreter,
8989
additionalBinaryDataProperties: null,
90-
internalContainer: container.AsBinaryData());
90+
container: container);
9191
}
9292
}

src/Generated/Models/OpenAIContext.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ namespace OpenAI
6565
[ModelReaderWriterBuildable(typeof(ChatToolChoice))]
6666
[ModelReaderWriterBuildable(typeof(ChatWebSearchOptions))]
6767
[ModelReaderWriterBuildable(typeof(CodeInterpreterCallResponseItem))]
68+
[ModelReaderWriterBuildable(typeof(CodeInterpreterContainer))]
6869
[ModelReaderWriterBuildable(typeof(CodeInterpreterContainerConfiguration))]
6970
[ModelReaderWriterBuildable(typeof(CodeInterpreterTool))]
7071
[ModelReaderWriterBuildable(typeof(CodeInterpreterToolDefinition))]

0 commit comments

Comments
 (0)