Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/OpenAI.net8.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4590,6 +4590,15 @@ public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistab
}
}
namespace OpenAI.Responses {
[Experimental("OPENAI001")]
public class CodeInterpreterTool : ResponseTool, IJsonModel<CodeInterpreterTool>, IPersistableModel<CodeInterpreterTool> {
public CodeInterpreterTool(BinaryData container);
public BinaryData Container { get; set; }
protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
}
[Experimental("OPENAICUA001")]
public class ComputerCallAction : IJsonModel<ComputerCallAction>, IPersistableModel<ComputerCallAction> {
public Drawing.Point? ClickCoordinates { get; }
Expand Down Expand Up @@ -5475,6 +5484,8 @@ public class ResponseTokenUsage : IJsonModel<ResponseTokenUsage>, IPersistableMo
}
[Experimental("OPENAI001")]
public class ResponseTool : IJsonModel<ResponseTool>, IPersistableModel<ResponseTool> {
public static CodeInterpreterTool CreateCodeInterpreterTool(IEnumerable<string> fileIds = null);
public static CodeInterpreterTool CreateCodeInterpreterTool(string containerId);
[Experimental("OPENAICUA001")]
public static ComputerTool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth, int displayHeight);
public static FileSearchTool CreateFileSearchTool(IEnumerable<string> vectorStoreIds, int? maxResultCount = null, FileSearchToolRankingOptions rankingOptions = null, BinaryData filters = null);
Expand Down
10 changes: 10 additions & 0 deletions api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4023,6 +4023,14 @@ public class TurnDetectionOptions : IJsonModel<TurnDetectionOptions>, IPersistab
}
}
namespace OpenAI.Responses {
public class CodeInterpreterTool : ResponseTool, IJsonModel<CodeInterpreterTool>, IPersistableModel<CodeInterpreterTool> {
public CodeInterpreterTool(BinaryData container);
public BinaryData Container { get; set; }
protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options);
protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options);
protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
}
public class ComputerCallAction : IJsonModel<ComputerCallAction>, IPersistableModel<ComputerCallAction> {
public Drawing.Point? ClickCoordinates { get; }
public ComputerCallActionMouseButton? ClickMouseButton { get; }
Expand Down Expand Up @@ -4834,6 +4842,8 @@ public class ResponseTokenUsage : IJsonModel<ResponseTokenUsage>, IPersistableMo
protected virtual BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options);
}
public class ResponseTool : IJsonModel<ResponseTool>, IPersistableModel<ResponseTool> {
public static CodeInterpreterTool CreateCodeInterpreterTool(IEnumerable<string> fileIds = null);
public static CodeInterpreterTool CreateCodeInterpreterTool(string containerId);
public static ComputerTool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth, int displayHeight);
public static FileSearchTool CreateFileSearchTool(IEnumerable<string> vectorStoreIds, int? maxResultCount = null, FileSearchToolRankingOptions rankingOptions = null, BinaryData filters = null);
public static FunctionTool CreateFunctionTool(string functionName, BinaryData functionParameters, bool? strictModeEnabled, string functionDescription = null);
Expand Down
1 change: 0 additions & 1 deletion src/Custom/Responses/Internal/GeneratorStubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ namespace OpenAI.Responses;
[CodeGenType("CodeInterpreterToolCallItemResourceStatus")] internal readonly partial struct InternalCodeInterpreterToolCallItemResourceStatus {}
[CodeGenType("LocalShellToolCallItemResourceStatus")] internal readonly partial struct InternalLocalShellToolCallItemResourceStatus {}
[CodeGenType("LocalShellToolCallOutputItemResourceStatus")] internal readonly partial struct InternalLocalShellToolCallOutputItemResourceStatus {}
[CodeGenType("CodeInterpreterTool")] internal partial class InternalCodeInterpreterTool {}
[CodeGenType("CodeInterpreterToolAuto")] internal partial class InternalCodeInterpreterToolAuto {}
[CodeGenType("ImageGenTool")] internal partial class InternalImageGenTool {}
[CodeGenType("ImageGenToolInputImageMask")] internal partial class InternalImageGenToolInputImageMask {}
Expand Down
10 changes: 10 additions & 0 deletions src/Custom/Responses/Tools/CodeInterpreterTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace OpenAI.Responses;

// CUSTOM: correct namespace.
[CodeGenType("CodeInterpreterTool")]
public partial class CodeInterpreterTool
{
internal static BinaryData AutoContainer { get; } = BinaryData.FromString("""{"type": "auto"}""");
}
42 changes: 40 additions & 2 deletions src/Custom/Responses/Tools/ResponseTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public static FunctionTool CreateFunctionTool(string functionName, BinaryData fu

// CUSTOM: Added factory method a a convenience.
[Experimental("OPENAICUA001")]
public static ComputerTool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth,int displayHeight)
public static ComputerTool CreateComputerTool(ComputerToolEnvironment environment, int displayWidth, int displayHeight)
{
return new ComputerTool(
kind: InternalToolType.ComputerUsePreview,
additionalBinaryDataProperties: null,
environment: environment,
displayWidth: displayWidth,
displayHeight:displayHeight);
displayHeight: displayHeight);
}

// CUSTOM: Added factory method a a convenience.
Expand Down Expand Up @@ -74,4 +74,42 @@ public static McpTool CreateMcpTool(string serverLabel, Uri serverUri, IDictiona
allowedTools: allowedTools,
toolCallApprovalPolicy: toolCallApprovalPolicy);
}

// CUSTOM: Added factory method a a convenience.
/// <summary>
/// Creates a new instance of the <see cref="CodeInterpreterTool"/> class with an auto-generated container.
/// </summary>
/// <param name="fileIds">The file IDs to include in the container.</param>
/// <returns></returns>
public static CodeInterpreterTool CreateCodeInterpreterTool(IEnumerable<string> fileIds = null)
{
string containerJson = fileIds?.Any() == true ?
$"{{\"type\": \"auto\", \"file_ids\": [{string.Join(", ", fileIds.Select(id => $"\"{id}\""))}]}}" :
"{\"type\": \"auto\"}";

return new CodeInterpreterTool(
kind: InternalToolType.CodeInterpreter,
additionalBinaryDataProperties: null,
container: new BinaryData(containerJson));
}

// CUSTOM: Added factory method a a convenience.
/// <summary>
/// Creates a new instance of the <see cref="CodeInterpreterTool"/> class with a specified container ID.
/// </summary>
/// <param name="containerId">The Id of a previously created container</param>
/// <returns></returns>
public static CodeInterpreterTool CreateCodeInterpreterTool(string containerId)
{
Argument.AssertNotNull(containerId, nameof(containerId));

// Since the container field can be a string or an object, when it's a string (container ID),
// we need to serialize it as a JSON string value
string containerJson = $"\"{containerId}\"";

return new CodeInterpreterTool(
kind: InternalToolType.CodeInterpreter,
additionalBinaryDataProperties: null,
container: new BinaryData(containerJson));
}
}
2 changes: 1 addition & 1 deletion src/Generated/Models/OpenAIContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace OpenAI
[ModelReaderWriterBuildable(typeof(ChatToolCall))]
[ModelReaderWriterBuildable(typeof(ChatToolChoice))]
[ModelReaderWriterBuildable(typeof(ChatWebSearchOptions))]
[ModelReaderWriterBuildable(typeof(CodeInterpreterTool))]
[ModelReaderWriterBuildable(typeof(CodeInterpreterToolDefinition))]
[ModelReaderWriterBuildable(typeof(CodeInterpreterToolResources))]
[ModelReaderWriterBuildable(typeof(ComputerCallAction))]
Expand Down Expand Up @@ -188,7 +189,6 @@ namespace OpenAI
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterFileOutput))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterFileOutputFile))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterTextOutput))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterTool))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterToolAuto))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterToolCallItemParam))]
[ModelReaderWriterBuildable(typeof(InternalCodeInterpreterToolCallItemResource))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

namespace OpenAI.Responses
{
internal partial class InternalCodeInterpreterTool : IJsonModel<InternalCodeInterpreterTool>
public partial class CodeInterpreterTool : IJsonModel<CodeInterpreterTool>
{
internal InternalCodeInterpreterTool() : this(InternalToolType.CodeInterpreter, null, null)
internal CodeInterpreterTool() : this(InternalToolType.CodeInterpreter, null, null)
{
}

void IJsonModel<InternalCodeInterpreterTool>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
void IJsonModel<CodeInterpreterTool>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
JsonModelWriteCore(writer, options);
Expand All @@ -25,10 +25,10 @@ void IJsonModel<InternalCodeInterpreterTool>.Write(Utf8JsonWriter writer, ModelR

protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
string format = options.Format == "W" ? ((IPersistableModel<InternalCodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(InternalCodeInterpreterTool)} does not support writing '{format}' format.");
throw new FormatException($"The model {nameof(CodeInterpreterTool)} does not support writing '{format}' format.");
}
base.JsonModelWriteCore(writer, options);
if (_additionalBinaryDataProperties?.ContainsKey("container") != true)
Expand All @@ -45,20 +45,20 @@ protected override void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWri
}
}

InternalCodeInterpreterTool IJsonModel<InternalCodeInterpreterTool>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (InternalCodeInterpreterTool)JsonModelCreateCore(ref reader, options);
CodeInterpreterTool IJsonModel<CodeInterpreterTool>.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) => (CodeInterpreterTool)JsonModelCreateCore(ref reader, options);

protected override ResponseTool JsonModelCreateCore(ref Utf8JsonReader reader, ModelReaderWriterOptions options)
{
string format = options.Format == "W" ? ((IPersistableModel<InternalCodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
if (format != "J")
{
throw new FormatException($"The model {nameof(InternalCodeInterpreterTool)} does not support reading '{format}' format.");
throw new FormatException($"The model {nameof(CodeInterpreterTool)} does not support reading '{format}' format.");
}
using JsonDocument document = JsonDocument.ParseValue(ref reader);
return DeserializeInternalCodeInterpreterTool(document.RootElement, options);
return DeserializeCodeInterpreterTool(document.RootElement, options);
}

internal static InternalCodeInterpreterTool DeserializeInternalCodeInterpreterTool(JsonElement element, ModelReaderWriterOptions options)
internal static CodeInterpreterTool DeserializeCodeInterpreterTool(JsonElement element, ModelReaderWriterOptions options)
{
if (element.ValueKind == JsonValueKind.Null)
{
Expand All @@ -82,40 +82,40 @@ internal static InternalCodeInterpreterTool DeserializeInternalCodeInterpreterTo
// Plugin customization: remove options.Format != "W" check
additionalBinaryDataProperties.Add(prop.Name, BinaryData.FromString(prop.Value.GetRawText()));
}
return new InternalCodeInterpreterTool(kind, additionalBinaryDataProperties, container);
return new CodeInterpreterTool(kind, additionalBinaryDataProperties, container);
}

BinaryData IPersistableModel<InternalCodeInterpreterTool>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);
BinaryData IPersistableModel<CodeInterpreterTool>.Write(ModelReaderWriterOptions options) => PersistableModelWriteCore(options);

protected override BinaryData PersistableModelWriteCore(ModelReaderWriterOptions options)
{
string format = options.Format == "W" ? ((IPersistableModel<InternalCodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
return ModelReaderWriter.Write(this, options, OpenAIContext.Default);
default:
throw new FormatException($"The model {nameof(InternalCodeInterpreterTool)} does not support writing '{options.Format}' format.");
throw new FormatException($"The model {nameof(CodeInterpreterTool)} does not support writing '{options.Format}' format.");
}
}

InternalCodeInterpreterTool IPersistableModel<InternalCodeInterpreterTool>.Create(BinaryData data, ModelReaderWriterOptions options) => (InternalCodeInterpreterTool)PersistableModelCreateCore(data, options);
CodeInterpreterTool IPersistableModel<CodeInterpreterTool>.Create(BinaryData data, ModelReaderWriterOptions options) => (CodeInterpreterTool)PersistableModelCreateCore(data, options);

protected override ResponseTool PersistableModelCreateCore(BinaryData data, ModelReaderWriterOptions options)
{
string format = options.Format == "W" ? ((IPersistableModel<InternalCodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
string format = options.Format == "W" ? ((IPersistableModel<CodeInterpreterTool>)this).GetFormatFromOptions(options) : options.Format;
switch (format)
{
case "J":
using (JsonDocument document = JsonDocument.Parse(data))
{
return DeserializeInternalCodeInterpreterTool(document.RootElement, options);
return DeserializeCodeInterpreterTool(document.RootElement, options);
}
default:
throw new FormatException($"The model {nameof(InternalCodeInterpreterTool)} does not support reading '{options.Format}' format.");
throw new FormatException($"The model {nameof(CodeInterpreterTool)} does not support reading '{options.Format}' format.");
}
}

string IPersistableModel<InternalCodeInterpreterTool>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
string IPersistableModel<CodeInterpreterTool>.GetFormatFromOptions(ModelReaderWriterOptions options) => "J";
}
}
29 changes: 29 additions & 0 deletions src/Generated/Models/Responses/CodeInterpreterTool.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// <auto-generated/>

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using OpenAI;

namespace OpenAI.Responses
{
[Experimental("OPENAI001")]
public partial class CodeInterpreterTool : ResponseTool
{
public CodeInterpreterTool(BinaryData container) : base(InternalToolType.CodeInterpreter)
{
Argument.AssertNotNull(container, nameof(container));

Container = container;
}

internal CodeInterpreterTool(InternalToolType kind, IDictionary<string, BinaryData> additionalBinaryDataProperties, BinaryData container) : base(kind, additionalBinaryDataProperties)
{
Container = container;
}

public BinaryData Container { get; set; }
}
}
27 changes: 0 additions & 27 deletions src/Generated/Models/Responses/InternalCodeInterpreterTool.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal static ResponseTool DeserializeResponseTool(JsonElement element, ModelR
case "web_search_preview":
return WebSearchTool.DeserializeWebSearchTool(element, options);
case "code_interpreter":
return InternalCodeInterpreterTool.DeserializeInternalCodeInterpreterTool(element, options);
return CodeInterpreterTool.DeserializeCodeInterpreterTool(element, options);
case "image_generation":
return InternalImageGenTool.DeserializeInternalImageGenTool(element, options);
case "local_shell":
Expand Down
Loading