Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .dotnet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Bugs Fixed

- Corrected an internal deserialization issue that caused recent updates to Assistants `file_search` to fail when streaming a run. Strongly typed support for `ranking_options` is not included but will arrive soon. (commit_hash)
- Mitigated a .NET runtime issue that prevented `ChatResponseFormat` from serializing correct on targets including Unity. (commit_hash)

### Other Changes

Expand Down
21 changes: 11 additions & 10 deletions .dotnet/api/OpenAI.netstandard2.0.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public class CodeInterpreterToolDefinition : ToolDefinition, IJsonModel<CodeInte
CodeInterpreterToolDefinition IPersistableModel<CodeInterpreterToolDefinition>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<CodeInterpreterToolDefinition>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<CodeInterpreterToolDefinition>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class CodeInterpreterToolResources : IJsonModel<CodeInterpreterToolResources>, IPersistableModel<CodeInterpreterToolResources> {
public IList<string> FileIds { get; set; }
Expand All @@ -359,7 +359,7 @@ public class FileSearchToolDefinition : ToolDefinition, IJsonModel<FileSearchToo
FileSearchToolDefinition IPersistableModel<FileSearchToolDefinition>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<FileSearchToolDefinition>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<FileSearchToolDefinition>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class FileSearchToolResources : IJsonModel<FileSearchToolResources>, IPersistableModel<FileSearchToolResources> {
public IList<VectorStoreCreationHelper> NewVectorStores { get; }
Expand All @@ -382,7 +382,7 @@ public class FunctionToolDefinition : ToolDefinition, IJsonModel<FunctionToolDef
FunctionToolDefinition IPersistableModel<FunctionToolDefinition>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<FunctionToolDefinition>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<FunctionToolDefinition>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class MessageCollectionOptions {
public string AfterId { get; set; }
Expand Down Expand Up @@ -955,7 +955,7 @@ public abstract class ToolDefinition : IJsonModel<ToolDefinition>, IPersistableM
ToolDefinition IPersistableModel<ToolDefinition>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<ToolDefinition>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<ToolDefinition>.Write(ModelReaderWriterOptions options);
protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class ToolOutput : IJsonModel<ToolOutput>, IPersistableModel<ToolOutput> {
public ToolOutput();
Expand Down Expand Up @@ -1215,7 +1215,7 @@ public class AssistantChatMessage : ChatMessage, IJsonModel<AssistantChatMessage
AssistantChatMessage IPersistableModel<AssistantChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<AssistantChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<AssistantChatMessage>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class ChatClient {
protected ChatClient();
Expand Down Expand Up @@ -1347,7 +1347,7 @@ public abstract class ChatMessage : IJsonModel<ChatMessage>, IPersistableModel<C
ChatMessage IPersistableModel<ChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<ChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<ChatMessage>.Write(ModelReaderWriterOptions options);
protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class ChatMessageContentPart : IJsonModel<ChatMessageContentPart>, IPersistableModel<ChatMessageContentPart> {
public BinaryData ImageBytes { get; }
Expand Down Expand Up @@ -1415,6 +1415,7 @@ public abstract class ChatResponseFormat : IEquatable<ChatResponseFormat>, IJson
[EditorBrowsable(EditorBrowsableState.Never)]
bool IEquatable<ChatResponseFormat>.Equals(ChatResponseFormat other);
public override string ToString();
protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class ChatTokenLogProbabilityInfo : IJsonModel<ChatTokenLogProbabilityInfo>, IPersistableModel<ChatTokenLogProbabilityInfo> {
public float LogProbability { get; }
Expand Down Expand Up @@ -1522,7 +1523,7 @@ public class FunctionChatMessage : ChatMessage, IJsonModel<FunctionChatMessage>,
FunctionChatMessage IPersistableModel<FunctionChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<FunctionChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<FunctionChatMessage>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public readonly partial struct ImageChatMessageContentPartDetail : IEquatable<ImageChatMessageContentPartDetail> {
private readonly object _dummy;
Expand Down Expand Up @@ -1601,7 +1602,7 @@ public class SystemChatMessage : ChatMessage, IJsonModel<SystemChatMessage>, IPe
SystemChatMessage IPersistableModel<SystemChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<SystemChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<SystemChatMessage>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class ToolChatMessage : ChatMessage, IJsonModel<ToolChatMessage>, IPersistableModel<ToolChatMessage> {
public ToolChatMessage(string toolCallId, params ChatMessageContentPart[] contentParts);
Expand All @@ -1613,7 +1614,7 @@ public class ToolChatMessage : ChatMessage, IJsonModel<ToolChatMessage>, IPersis
ToolChatMessage IPersistableModel<ToolChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<ToolChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<ToolChatMessage>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
public class UserChatMessage : ChatMessage, IJsonModel<UserChatMessage>, IPersistableModel<UserChatMessage> {
public UserChatMessage(params ChatMessageContentPart[] content);
Expand All @@ -1625,7 +1626,7 @@ public class UserChatMessage : ChatMessage, IJsonModel<UserChatMessage>, IPersis
UserChatMessage IPersistableModel<UserChatMessage>.Create(BinaryData data, ModelReaderWriterOptions options);
string IPersistableModel<UserChatMessage>.GetFormatFromOptions(ModelReaderWriterOptions options);
BinaryData IPersistableModel<UserChatMessage>.Write(ModelReaderWriterOptions options);
protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
}
namespace OpenAI.Embeddings {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void IJsonModel<CodeInterpreterToolDefinition>.Write(Utf8JsonWriter writer, Mode
internal static void SerializeCodeInterpreterToolDefinition(CodeInterpreterToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void IJsonModel<FileSearchToolDefinition>.Write(Utf8JsonWriter writer, ModelRead
internal static void SerializeFileSearchToolDefinition(FileSearchToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void IJsonModel<FunctionToolDefinition>.Write(Utf8JsonWriter writer, ModelReader
internal static void SerializeFunctionToolDefinition(FunctionToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("function"u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void IJsonModel<ToolDefinition>.Write(Utf8JsonWriter writer, ModelReaderWriterOp
internal static void SerializeUnknownAssistantToolDefinition(UnknownAssistantToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("type"u8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ void IJsonModel<ToolDefinition>.Write(Utf8JsonWriter writer, ModelReaderWriterOp
internal static void WriteCore(ToolDefinition instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.ClientModel.Primitives;
using System.Collections;
using System.Collections.Generic;
using System.Text.Json;

namespace OpenAI.Chat;
Expand All @@ -14,7 +12,7 @@ void IJsonModel<AssistantChatMessage>.Write(Utf8JsonWriter writer, ModelReaderWr
internal static void SerializeAssistantChatMessage(AssistantChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("role"u8);
Expand Down
2 changes: 1 addition & 1 deletion .dotnet/src/Custom/Chat/ChatMessage.Serialization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ void IJsonModel<ChatMessage>.Write(Utf8JsonWriter writer, ModelReaderWriterOptio
internal static void WriteCore(ChatMessage instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
19 changes: 19 additions & 0 deletions .dotnet/src/Custom/Chat/ChatResponseFormat.Serialization.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.ClientModel.Primitives;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text.Json;

namespace OpenAI.Chat;

[CodeGenSuppress("global::System.ClientModel.Primitives.IJsonModel<OpenAI.Chat.ChatResponseFormat>.Write", typeof(Utf8JsonWriter), typeof(ModelReaderWriterOptions))]
public abstract partial class ChatResponseFormat : IJsonModel<ChatResponseFormat>
{
void IJsonModel<ChatResponseFormat>.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> CustomSerializationHelpers.SerializeInstance(this, WriteCore, writer, options);

internal static void WriteCore(ChatResponseFormat instance, Utf8JsonWriter writer, ModelReaderWriterOptions options)
=> instance.WriteCore(writer, options);

protected internal abstract void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options);
}
39 changes: 33 additions & 6 deletions .dotnet/src/Custom/Chat/ChatResponseFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,44 @@

namespace OpenAI.Chat;

/// <summary>
/// The format that the model should output.
/// <list>
/// <item>
/// Call <see cref="CreateTextFormat()"/> to create a <see cref="ChatResponseFormat"/> requesting plain
/// text.
/// </item>
/// <item>
/// Call <see cref="CreateJsonObjectFormat()"/> to create a <see cref="ChatResponseFormat"/> requesting
/// valid JSON, a.k.a. JSON mode.
/// </item>
/// <item>
/// Call <see cref="CreateJsonSchemaFormat(string, BinaryData, string, bool?)"/> to create a
/// <see cref="ChatResponseFormat"/> requesting adherence to the specified JSON schema,
/// a.k.a. structured outputs.
/// </item>
/// </list>
/// </summary>
[CodeGenModel("ChatResponseFormat")]
public abstract partial class ChatResponseFormat : IEquatable<ChatResponseFormat>
{
/// <summary> Creates a new <see cref="ChatResponseFormat"/> requesting plain text. </summary>
public static ChatResponseFormat Text { get; } = new InternalChatResponseFormatText();

/// <summary> Creates a new <see cref="ChatResponseFormat"/> requesting valid JSON, a.k.a. JSON mode. </summary>
public static ChatResponseFormat JsonObject { get; } = new InternalChatResponseFormatJsonObject();

/// <summary> Creates a new <see cref="ChatResponseFormat"/> requesting plain text. </summary>
public static ChatResponseFormat CreateTextFormat() => new InternalChatResponseFormatText();

/// <summary> Creates a new <see cref="ChatResponseFormat"/> requesting valid JSON, a.k.a. JSON mode. </summary>
public static ChatResponseFormat CreateJsonObjectFormat() => new InternalChatResponseFormatJsonObject();
public static ChatResponseFormat CreateJsonSchemaFormat(
string name,
BinaryData jsonSchema,
string description = null,
bool? strictSchemaEnabled = null)

/// <summary>
/// Creates a new <see cref="ChatResponseFormat"/> requesting adherence to the specified JSON schema,
/// a.k.a. structured outputs.
/// </summary>
public static ChatResponseFormat CreateJsonSchemaFormat(string name, BinaryData jsonSchema, string description = null, bool? strictSchemaEnabled = null)
{
Argument.AssertNotNullOrEmpty(name, nameof(name));
Argument.AssertNotNull(jsonSchema, nameof(jsonSchema));
Expand All @@ -27,7 +52,8 @@ public static ChatResponseFormat CreateJsonSchemaFormat(
name,
jsonSchema,
strictSchemaEnabled,
null);
serializedAdditionalRawData: null);

return new InternalChatResponseFormatJsonSchema(internalSchema);
}

Expand All @@ -38,6 +64,7 @@ public static ChatResponseFormat CreateJsonSchemaFormat(
{
return second is null;
}

return first.Equals(second);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal static void SerializeFunctionChatMessage(FunctionChatMessage instance,
instance.WriteCore(writer, options);
}

protected override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
protected internal override void WriteCore(Utf8JsonWriter writer, ModelReaderWriterOptions options)
{
writer.WriteStartObject();
writer.WritePropertyName("role"u8);
Expand Down
Loading