diff --git a/api/OpenAI.netstandard2.0.cs b/api/OpenAI.netstandard2.0.cs index 2af43868a..7f0e8779c 100644 --- a/api/OpenAI.netstandard2.0.cs +++ b/api/OpenAI.netstandard2.0.cs @@ -16,6 +16,7 @@ public class OpenAIClient { public virtual ModerationClient GetModerationClient(string model); public virtual OpenAIFileClient GetOpenAIFileClient(); public virtual OpenAIModelClient GetOpenAIModelClient(); + public virtual RealtimeConversation.RealtimeConversationClient GetRealtimeConversationClient(string model); public virtual VectorStoreClient GetVectorStoreClient(); } public class OpenAIClientOptions : ClientPipelineOptions { @@ -2208,6 +2209,708 @@ public static class OpenAIModerationsModelFactory { public static ModerationResultCollection ModerationResultCollection(string id = null, string model = null, IEnumerable items = null); } } +namespace OpenAI.RealtimeConversation { + public class ConversationAudioDeltaUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public BinaryData Delta { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationAudioDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationAudioDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationAudioDoneUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationAudioDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationAudioDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public readonly partial struct ConversationAudioFormat : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationAudioFormat(string value); + public static ConversationAudioFormat G711Alaw { get; } + public static ConversationAudioFormat G711Ulaw { get; } + public static ConversationAudioFormat Pcm16 { get; } + public readonly bool Equals(ConversationAudioFormat other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationAudioFormat left, ConversationAudioFormat right); + public static implicit operator ConversationAudioFormat(string value); + public static bool operator !=(ConversationAudioFormat left, ConversationAudioFormat right); + public override readonly string ToString(); + } + [Flags] + public enum ConversationContentModalities { + Text = 1, + Audio = 2 + } + public abstract class ConversationContentPart : IJsonModel, IPersistableModel { + public string AudioTranscriptValue { get; } + public ConversationContentPartKind Kind { get; } + public string TextValue { get; } + public static ConversationContentPart FromInputAudioTranscript(string transcript = null); + public static ConversationContentPart FromInputText(string text); + public static ConversationContentPart FromOutputAudioTranscript(string transcript = null); + public static ConversationContentPart FromOutputText(string text); + public static implicit operator ConversationContentPart(string text); + ConversationContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationContentPartFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string AudioTranscript { get; } + public int ContentIndex { get; } + public ConversationContentPartKind ContentKind { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + public string Text { get; } + ConversationContentPartFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationContentPartFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public readonly partial struct ConversationContentPartKind : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationContentPartKind(string value); + public static ConversationContentPartKind Audio { get; } + public static ConversationContentPartKind InputAudio { get; } + public static ConversationContentPartKind InputText { get; } + public static ConversationContentPartKind Text { get; } + public readonly bool Equals(ConversationContentPartKind other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationContentPartKind left, ConversationContentPartKind right); + public static implicit operator ConversationContentPartKind(string value); + public static bool operator !=(ConversationContentPartKind left, ConversationContentPartKind right); + public override readonly string ToString(); + } + public class ConversationContentPartStartedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string AudioTranscript { get; } + public int ContentIndex { get; } + public ConversationContentPartKind ContentKind { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + public string Text { get; } + ConversationContentPartStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationContentPartStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationErrorUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string ErrorCode { get; } + public string ErrorEventId { get; } + public string ErrorMessage { get; } + public string ErrorParameterName { get; } + ConversationErrorUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationErrorUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationFunctionCallArgumentsDeltaUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string CallId { get; } + public string Delta { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationFunctionCallArgumentsDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationFunctionCallArgumentsDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationFunctionCallArgumentsDoneUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string Arguments { get; } + public string CallId { get; } + public string ItemId { get; } + public string Name { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationFunctionCallArgumentsDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationFunctionCallArgumentsDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationFunctionTool : ConversationTool, IJsonModel, IPersistableModel { + public ConversationFunctionTool(); + public ConversationFunctionTool(string name); + public string Description { get; set; } + public required string Name { get; set; } + public BinaryData Parameters { get; set; } + ConversationFunctionTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationFunctionTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputAudioBufferClearedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + ConversationInputAudioBufferClearedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputAudioBufferClearedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputAudioBufferCommittedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string ItemId { get; } + public string PreviousItemId { get; } + ConversationInputAudioBufferCommittedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputAudioBufferCommittedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputSpeechFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int AudioEndMs { get; } + public string ItemId { get; } + ConversationInputSpeechFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputSpeechFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputSpeechStartedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int AudioStartMs { get; } + public string ItemId { get; } + ConversationInputSpeechStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputSpeechStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputTokenUsageDetails : IJsonModel, IPersistableModel { + public int AudioTokens { get; } + public int CachedTokens { get; } + public int TextTokens { get; } + ConversationInputTokenUsageDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputTokenUsageDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputTranscriptionFailedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string ErrorCode { get; } + public string ErrorMessage { get; } + public string ErrorParameterName { get; } + public string ItemId { get; } + ConversationInputTranscriptionFailedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputTranscriptionFailedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputTranscriptionFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string ItemId { get; } + public string Transcript { get; } + ConversationInputTranscriptionFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputTranscriptionFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationInputTranscriptionOptions : IJsonModel, IPersistableModel { + public ConversationTranscriptionModel? Model { get; set; } + ConversationInputTranscriptionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationInputTranscriptionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public abstract class ConversationItem : IJsonModel, IPersistableModel { + public string FunctionArguments { get; } + public string FunctionCallId { get; } + public string FunctionName { get; } + public string Id { get; set; } + public IReadOnlyList MessageContentParts { get; } + public ConversationMessageRole? MessageRole { get; } + public static ConversationItem CreateAssistantMessage(IEnumerable contentItems); + public static ConversationItem CreateFunctionCall(string name, string callId, string arguments); + public static ConversationItem CreateFunctionCallOutput(string callId, string output); + public static ConversationItem CreateSystemMessage(string toolCallId, IEnumerable contentItems); + public static ConversationItem CreateUserMessage(IEnumerable contentItems); + ConversationItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationItemAcknowledgedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public ConversationItem Item { get; } + ConversationItemAcknowledgedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItemAcknowledgedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationItemDeletedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string ItemId { get; } + ConversationItemDeletedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItemDeletedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationItemFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string FunctionCallArguments { get; } + public string FunctionCallId { get; } + public string FunctionCallOutput { get; } + public string FunctionName { get; } + public IReadOnlyList MessageContentParts { get; } + public ConversationMessageRole? MessageRole { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationItemFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItemFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationItemStartedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public string FunctionCallArguments { get; } + public string FunctionCallId { get; } + public string FunctionCallOutput { get; } + public string FunctionName { get; } + public IReadOnlyList MessageContentParts { get; } + public ConversationMessageRole? MessageRole { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationItemStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItemStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public readonly partial struct ConversationItemStatus : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationItemStatus(string value); + public static ConversationItemStatus Completed { get; } + public static ConversationItemStatus Incomplete { get; } + public static ConversationItemStatus InProgress { get; } + public readonly bool Equals(ConversationItemStatus other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationItemStatus left, ConversationItemStatus right); + public static implicit operator ConversationItemStatus(string value); + public static bool operator !=(ConversationItemStatus left, ConversationItemStatus right); + public override readonly string ToString(); + } + public class ConversationItemTruncatedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int AudioEndMs { get; } + public int Index { get; } + public string ItemId { get; } + ConversationItemTruncatedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationItemTruncatedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationMaxTokensChoice : IJsonModel, IPersistableModel { + public ConversationMaxTokensChoice(int numberValue); + public int? NumericValue { get; } + public static ConversationMaxTokensChoice CreateDefaultMaxTokensChoice(); + public static ConversationMaxTokensChoice CreateInfiniteMaxTokensChoice(); + public static ConversationMaxTokensChoice CreateNumericMaxTokensChoice(int maxTokens); + public static implicit operator ConversationMaxTokensChoice(int maxTokens); + ConversationMaxTokensChoice IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationMaxTokensChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public readonly partial struct ConversationMessageRole : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationMessageRole(string value); + public static ConversationMessageRole Assistant { get; } + public static ConversationMessageRole System { get; } + public static ConversationMessageRole User { get; } + public readonly bool Equals(ConversationMessageRole other); + [EditorBrowsable(global::EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(global::EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationMessageRole left, ConversationMessageRole right); + public static implicit operator ConversationMessageRole(string value); + public static bool operator !=(ConversationMessageRole left, ConversationMessageRole right); + public override readonly string ToString(); + } + public class ConversationOutputTokenUsageDetails : IJsonModel, IPersistableModel { + public int AudioTokens { get; } + public int TextTokens { get; } + ConversationOutputTokenUsageDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationOutputTokenUsageDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationOutputTranscriptionDeltaUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string Delta { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationOutputTranscriptionDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationOutputTranscriptionDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationOutputTranscriptionFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationOutputTranscriptionFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationOutputTranscriptionFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationRateLimitDetailsItem : IJsonModel, IPersistableModel { + public int Limit { get; } + public string Name { get; } + public int Remaining { get; } + public float ResetSeconds { get; } + ConversationRateLimitDetailsItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationRateLimitDetailsItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationRateLimitsUpdatedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public IReadOnlyList RateLimits { get; } + ConversationRateLimitsUpdatedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationRateLimitsUpdatedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationResponseFinishedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public IReadOnlyList CreatedItems { get; } + public string Id { get; } + public ConversationStatus? Status { get; } + ConversationResponseFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationResponseFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationResponseStartedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + ConversationResponseStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationResponseStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationSessionConfiguredUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public ConversationContentModalities ContentModalities { get; } + public ConversationAudioFormat InputAudioFormat { get; } + public string Instructions { get; } + public ConversationMaxTokensChoice MaxOutputTokens { get; } + public string Model { get; } + public ConversationAudioFormat OutputAudioFormat { get; } + public string SessionId { get; } + public float Temperature { get; } + public ConversationToolChoice ToolChoice { get; } + public IReadOnlyList Tools { get; } + public ConversationInputTranscriptionOptions TranscriptionSettings { get; } + public ConversationTurnDetectionOptions TurnDetectionSettings { get; } + public ConversationVoice Voice { get; } + ConversationSessionConfiguredUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationSessionConfiguredUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationSessionOptions : IJsonModel, IPersistableModel { + public ConversationContentModalities ContentModalities { get; set; } + public ConversationAudioFormat? InputAudioFormat { get; set; } + public ConversationInputTranscriptionOptions InputTranscriptionOptions { get; set; } + public string Instructions { get; set; } + public ConversationMaxTokensChoice MaxResponseOutputTokens { get; set; } + public string Model { get; set; } + public ConversationAudioFormat? OutputAudioFormat { get; set; } + public float? Temperature { get; set; } + public ConversationToolChoice ToolChoice { get; set; } + public IList Tools { get; } + public ConversationTurnDetectionOptions TurnDetectionOptions { get; set; } + public ConversationVoice? Voice { get; set; } + ConversationSessionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationSessionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationSessionStartedUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public ConversationContentModalities ContentModalities { get; } + public ConversationAudioFormat InputAudioFormat { get; } + public string Instructions { get; } + public ConversationMaxTokensChoice MaxOutputTokens { get; } + public string Model { get; } + public ConversationAudioFormat OutputAudioFormat { get; } + public string SessionId { get; } + public float Temperature { get; } + public ConversationToolChoice ToolChoice { get; } + public IReadOnlyList Tools { get; } + public ConversationInputTranscriptionOptions TranscriptionSettings { get; } + public ConversationTurnDetectionOptions TurnDetectionSettings { get; } + public ConversationVoice Voice { get; } + ConversationSessionStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationSessionStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public readonly partial struct ConversationStatus : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationStatus(string value); + public static ConversationStatus Cancelled { get; } + public static ConversationStatus Completed { get; } + public static ConversationStatus Failed { get; } + public static ConversationStatus Incomplete { get; } + public static ConversationStatus InProgress { get; } + public readonly bool Equals(ConversationStatus other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationStatus left, ConversationStatus right); + public static implicit operator ConversationStatus(string value); + public static bool operator !=(ConversationStatus left, ConversationStatus right); + public override readonly string ToString(); + } + public class ConversationTextDeltaUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string Delta { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + ConversationTextDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationTextDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationTextDoneUpdate : ConversationUpdate, IJsonModel, IPersistableModel { + public int ContentIndex { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string ResponseId { get; } + public string Value { get; } + ConversationTextDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationTextDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationTokenUsage : IJsonModel, IPersistableModel { + public ConversationInputTokenUsageDetails InputTokenDetails { get; } + public int InputTokens { get; } + public ConversationOutputTokenUsageDetails OutputTokenDetails { get; } + public int OutputTokens { get; } + public int TotalTokens { get; } + ConversationTokenUsage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationTokenUsage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public abstract class ConversationTool : IJsonModel, IPersistableModel { + public ConversationToolKind Kind { get; } + public static ConversationTool CreateFunctionTool(string name, string description = null, BinaryData parameters = null); + ConversationTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public class ConversationToolChoice : IJsonModel, IPersistableModel { + public string FunctionName { get; } + public ConversationToolChoiceKind Kind { get; } + public static ConversationToolChoice CreateAutoToolChoice(); + public static ConversationToolChoice CreateFunctionToolChoice(string functionName); + public static ConversationToolChoice CreateNoneToolChoice(); + public static ConversationToolChoice CreateRequiredToolChoice(); + ConversationToolChoice IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationToolChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public enum ConversationToolChoiceKind { + Auto = 0, + None = 1, + Required = 2, + Function = 3 + } + public readonly partial struct ConversationToolKind : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationToolKind(string value); + public static ConversationToolKind Function { get; } + public readonly bool Equals(ConversationToolKind other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationToolKind left, ConversationToolKind right); + public static implicit operator ConversationToolKind(string value); + public static bool operator !=(ConversationToolKind left, ConversationToolKind right); + public override readonly string ToString(); + } + public readonly partial struct ConversationTranscriptionModel : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationTranscriptionModel(string value); + public static ConversationTranscriptionModel Whisper1 { get; } + public readonly bool Equals(ConversationTranscriptionModel other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationTranscriptionModel left, ConversationTranscriptionModel right); + public static implicit operator ConversationTranscriptionModel(string value); + public static bool operator !=(ConversationTranscriptionModel left, ConversationTranscriptionModel right); + public override readonly string ToString(); + } + public enum ConversationTurnDetectionKind { + ServerVoiceActivityDetection = 0, + Disabled = 1 + } + public abstract class ConversationTurnDetectionOptions : IJsonModel, IPersistableModel { + public ConversationTurnDetectionKind Kind { get; protected internal set; } + public static ConversationTurnDetectionOptions CreateDisabledTurnDetectionOptions(); + public static ConversationTurnDetectionOptions CreateServerVoiceActivityTurnDetectionOptions(float? detectionThreshold = null, TimeSpan? prefixPaddingDuration = null, TimeSpan? silenceDuration = null); + ConversationTurnDetectionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationTurnDetectionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public abstract class ConversationUpdate : IJsonModel, IPersistableModel { + protected ConversationUpdate(string eventId); + public string EventId { get; } + public ConversationUpdateKind Kind { get; protected internal set; } + public BinaryData GetRawContent(); + ConversationUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options); + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options); + ConversationUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options); + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options); + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options); + } + public enum ConversationUpdateKind { + SessionStarted = 0, + SessionConfigured = 1, + ItemAcknowledged = 2, + ItemDeleted = 3, + ItemTruncated = 4, + ResponseStarted = 5, + ResponseFinished = 6, + RateLimitsUpdated = 7, + ItemStarted = 8, + ItemFinished = 9, + ContentPartStarted = 10, + ContentPartFinished = 11, + ResponseAudioDelta = 12, + ResponseAudioDone = 13, + ResponseAudioTranscriptDelta = 14, + ResponseAudioTranscriptDone = 15, + ResponseTextDelta = 16, + ResponseTextDone = 17, + ResponseFunctionCallArgumentsDelta = 18, + ResponseFunctionCallArgumentsDone = 19, + InputAudioBufferSpeechStarted = 20, + InputAudioBufferSpeechStopped = 21, + ItemInputAudioTranscriptionCompleted = 22, + ItemInputAudioTranscriptionFailed = 23, + InputAudioBufferCommitted = 24, + InputAudioBufferCleared = 25, + Error = 26 + } + public readonly partial struct ConversationVoice : IEquatable { + private readonly object _dummy; + private readonly int _dummyPrimitive; + public ConversationVoice(string value); + public static ConversationVoice Alloy { get; } + public static ConversationVoice Echo { get; } + public static ConversationVoice Shimmer { get; } + public readonly bool Equals(ConversationVoice other); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly bool Equals(object obj); + [EditorBrowsable(EditorBrowsableState.Never)] + public override readonly int GetHashCode(); + public static bool operator ==(ConversationVoice left, ConversationVoice right); + public static implicit operator ConversationVoice(string value); + public static bool operator !=(ConversationVoice left, ConversationVoice right); + public override readonly string ToString(); + } + public class RealtimeConversationClient { + protected RealtimeConversationClient(); + protected internal RealtimeConversationClient(ClientPipeline pipeline, OpenAIClientOptions options); + public RealtimeConversationClient(string model, ApiKeyCredential credential, OpenAIClientOptions options); + public RealtimeConversationClient(string model, ApiKeyCredential credential); + public virtual ClientPipeline Pipeline { get; } + public event EventHandler OnReceivingCommand { add; remove; } + public event EventHandler OnSendingCommand { add; remove; } + public RealtimeConversationSession StartConversationSession(CancellationToken cancellationToken = default); + public virtual Task StartConversationSessionAsync(RequestOptions options); + public virtual Task StartConversationSessionAsync(CancellationToken cancellationToken = default); + } + public class RealtimeConversationSession : IDisposable { + protected Net.WebSockets.ClientWebSocket _clientWebSocket; + protected internal RealtimeConversationSession(RealtimeConversationClient parentClient, Uri endpoint, ApiKeyCredential credential); + public Task AddItemAsync(ConversationItem item, string previousItemId, CancellationToken cancellationToken = default); + public Task AddItemAsync(ConversationItem item, CancellationToken cancellationToken = default); + public Task CancelResponseTurnAsync(CancellationToken cancellationToken = default); + public Task CommitPendingAudioAsync(CancellationToken cancellationToken = default); + public Task ConfigureSessionAsync(ConversationSessionOptions sessionOptions, CancellationToken cancellationToken = default); + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal virtual void Connect(RequestOptions options); + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal virtual Task ConnectAsync(RequestOptions options); + public Task DeleteItemAsync(string itemId, CancellationToken cancellationToken = default); + public void Dispose(); + public Task InterruptTurnAsync(CancellationToken cancellationToken = default); + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual IEnumerable ReceiveUpdates(RequestOptions options); + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual IAsyncEnumerable ReceiveUpdatesAsync(RequestOptions options); + public IAsyncEnumerable ReceiveUpdatesAsync(CancellationToken cancellationToken = default); + public Task SendAudioAsync(BinaryData audio, CancellationToken cancellationToken = default); + public Task SendAudioAsync(Stream audio, CancellationToken cancellationToken = default); + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void SendCommand(BinaryData data, RequestOptions options); + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual Task SendCommandAsync(BinaryData data, RequestOptions options); + public Task StartResponseTurnAsync(CancellationToken cancellationToken = default); + } +} namespace OpenAI.VectorStores { public class AddFileToVectorStoreOperation : OperationResult { public string FileId { get; } diff --git a/src/Custom/OpenAIClient.cs b/src/Custom/OpenAIClient.cs index 46c6fd743..32c92f89f 100644 --- a/src/Custom/OpenAIClient.cs +++ b/src/Custom/OpenAIClient.cs @@ -8,6 +8,7 @@ using OpenAI.Images; using OpenAI.Models; using OpenAI.Moderations; +using OpenAI.RealtimeConversation; using OpenAI.VectorStores; using System; using System.ClientModel; @@ -42,6 +43,7 @@ namespace OpenAI; [CodeGenSuppress("_cachedLegacyCompletionClient")] [CodeGenSuppress("_cachedOpenAIModelClient")] [CodeGenSuppress("_cachedModerationClient")] +[CodeGenSuppress("_cachedRealtimeConversationClient")] [CodeGenSuppress("_cachedVectorStoreClient")] [CodeGenSuppress("GetAssistantClient")] [CodeGenSuppress("GetAudioClient")] @@ -58,6 +60,7 @@ namespace OpenAI; [CodeGenSuppress("GetLegacyCompletionClient")] [CodeGenSuppress("GetModelClient")] [CodeGenSuppress("GetModerationClient")] +[CodeGenSuppress("GetRealtimeConversationClient")] [CodeGenSuppress("GetVectorStoreClient")] public partial class OpenAIClient { @@ -110,6 +113,7 @@ public OpenAIClient(ApiKeyCredential credential, OpenAIClientOptions options) Argument.AssertNotNull(credential, nameof(credential)); options ??= new OpenAIClientOptions(); + _keyCredential = credential; _pipeline = OpenAIClient.CreatePipeline(credential, options); _endpoint = OpenAIClient.GetEndpoint(options); _options = options; @@ -255,6 +259,9 @@ protected internal OpenAIClient(ClientPipeline pipeline, OpenAIClientOptions opt [Experimental("OPENAI001")] public virtual VectorStoreClient GetVectorStoreClient() => new(_pipeline, _options); + [Experimental("OPENAI002")] + public virtual RealtimeConversationClient GetRealtimeConversationClient(string model) => new(model, _keyCredential, _options); + internal static ClientPipeline CreatePipeline(ApiKeyCredential credential, OpenAIClientOptions options) { return ClientPipeline.Create( diff --git a/src/Custom/RealtimeConversation/AlphaDesignNotes.md b/src/Custom/RealtimeConversation/AlphaDesignNotes.md new file mode 100644 index 000000000..6add76a62 --- /dev/null +++ b/src/Custom/RealtimeConversation/AlphaDesignNotes.md @@ -0,0 +1,36 @@ +# Development notes for .NET `/realtime` -- alpha + +This document is intended to capture some of the exploratory design choices made when exposing the `/realtime` API in the .NET library. + +## Naming and structure + +"Realtime" does not describe "what" the capability does, but rather "how" it does it; `RealtimeClient`, while a faithful translation from REST, would not be descriptive or idiomatic. `AudioClient` has operations that let you send or receive audio; `ChatClient` is about all about getting chat (completion) responses; EmbeddingClient generates embeddings; `${NAME}Client` does *not* let you send or receive "realtimes." + +A number of names could work. `Conversation` was chosen as an expedient placeholder. + +Because the `/realtime` API involves simultaneously sending and receiving data on a single WebSocket, the primary logic vehicle is an `IDisposable` `ConversationSession` type -- this is configured by its originating `ConversationClient` and manages a `ClientWebSocket` instance. `ConversationClient` then provides task-based methods like `SendText` and `SubmitToolResponse` -- methods that allow the abstraction of client-originated request messages -- while exposing an `IAsyncEnumerable` collection of (response) `ConversationMessage` instances via `ReceiveMessagesAsync`. + +The initial design approach for `ConversationMessage` feature uses a "squish" strategy; the many variant concrete message types are internalized, then composed into the single wrapper that conditionally populates appropriate properties based on the underlying message. This is a reapplication of the general principles applied to Chat Completion and Assistants streaming, though it's a larger single-type "squish" than previously pursued. + +This is intended to facilitate a low barrier to entry, as explicit knowledge about different message types is not necessary to work with the operation. For example, a basic "hello world" may just do something like the following: + +```csharp +using ConversationSession conversation = await client.StartConversationAsync(); + +await conversation.SendTextAsync("Hello, world!"); + +await foreach (ConversationMessage message in client.ReceiveMessagesAsync()) +{ + Console.Write(message.Text); +} +``` + +## Turn-based data buffering + +A repeated piece of early alpha feedback was that a client-integrated mechanism to automatically accumulate incoming response data (not requiring manual, do-it-yourself accumulation) would be valuable. + +To explore accomplishing this, `ConversationSession` includes a pair of properties, `LastTurnFullResponseText` and `LastTurnFullResponseAudio`, that will automatically be populated with accumulated data when a `turn_finished` event is received. This is consistent with the "snapshot" mechanism used in several instances within Stainless SDK libraries, which likewise feature automatically accumulated data being populated into an appropriate location. + +As this requires visibility into the response body, automatic accumulation is only performed when using the convenience method variant of `ReceiveMessagesAsync`. + +Because this accumulated text and (especially) audio data can quickly grow in size to hundreds of kilobytes, a client-only property for `LastTurnResponseAccumulationEnabled` is inserted into `ConversationOptions`. In contexts with many parallel operations and high sensitive to memory footprint, the setting can thus opt out of the behavior. \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationContentModalities.Serialization.cs b/src/Custom/RealtimeConversation/ConversationContentModalities.Serialization.cs new file mode 100644 index 000000000..95478aa8a --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationContentModalities.Serialization.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +internal static partial class ConversationContentModalitiesExtensions +{ + internal static void ToInternalModalities(this ConversationContentModalities modalities, IList internalModalities) + { + internalModalities.Clear(); + if (modalities.HasFlag(ConversationContentModalities.Text)) + { + internalModalities.Add(InternalRealtimeRequestSessionUpdateCommandSessionModality.Text); + } + if (modalities.HasFlag(ConversationContentModalities.Audio)) + { + internalModalities.Add(InternalRealtimeRequestSessionUpdateCommandSessionModality.Audio); + } + } + + internal static ConversationContentModalities FromInternalModalities(IEnumerable internalModalities) + { + ConversationContentModalities result = 0; + foreach (InternalRealtimeRequestSessionUpdateCommandSessionModality internalModality in internalModalities ?? []) + { + if (internalModality == InternalRealtimeRequestSessionUpdateCommandSessionModality.Text) + { + result |= ConversationContentModalities.Text; + } + else if (internalModality == InternalRealtimeRequestSessionUpdateCommandSessionModality.Audio) + { + result |= ConversationContentModalities.Audio; + } + } + return result; + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationContentModalities.cs b/src/Custom/RealtimeConversation/ConversationContentModalities.cs new file mode 100644 index 000000000..4b7cecba6 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationContentModalities.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[Flags] +public enum ConversationContentModalities : int +{ + Text = 1 << 0, + Audio = 1 << 1, +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationContentPart.cs b/src/Custom/RealtimeConversation/ConversationContentPart.cs new file mode 100644 index 000000000..c1e20f9d5 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationContentPart.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeContentPart")] +public partial class ConversationContentPart +{ + [CodeGenMember("Type")] + internal ConversationContentPartKind Type; + + public ConversationContentPartKind Kind => Type; + + public string TextValue => + (this as InternalRealtimeRequestTextContentPart)?.Text + ?? (this as InternalRealtimeResponseTextContentPart)?.Text; + + public string AudioTranscriptValue => + (this as InternalRealtimeRequestAudioContentPart)?.Transcript + ?? (this as InternalRealtimeResponseAudioContentPart)?.Transcript; + + public static ConversationContentPart FromInputText(string text) + => new InternalRealtimeRequestTextContentPart(text); + public static ConversationContentPart FromInputAudioTranscript(string transcript = null) => new InternalRealtimeRequestAudioContentPart() + { + Transcript = transcript, + }; + public static ConversationContentPart FromOutputText(string text) + => new InternalRealtimeResponseTextContentPart(text); + public static ConversationContentPart FromOutputAudioTranscript(string transcript = null) + => new InternalRealtimeResponseAudioContentPart(transcript); + + public static implicit operator ConversationContentPart(string text) => FromInputText(text); +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationFunctionTool.cs b/src/Custom/RealtimeConversation/ConversationFunctionTool.cs new file mode 100644 index 000000000..dcb2621ee --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationFunctionTool.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeFunctionTool")] +public partial class ConversationFunctionTool : ConversationTool +{ + [CodeGenMember("Name")] + private string _name; + public required string Name + { + get => _name; + set => _name = value; + } + + [CodeGenMember("Description")] + private string _description; + + public string Description + { + get => _description; + set => _description = value; + } + + [CodeGenMember("Parameters")] + private BinaryData _parameters; + + public BinaryData Parameters + { + get => _parameters; + set => _parameters = value; + } + + public ConversationFunctionTool() : base(ConversationToolKind.Function, null) + { + } + + [SetsRequiredMembers] + public ConversationFunctionTool(string name) + : this(ConversationToolKind.Function, null, name, null, null) + { + Argument.AssertNotNull(name, nameof(name)); + } + + [SetsRequiredMembers] + internal ConversationFunctionTool(ConversationToolKind kind, IDictionary serializedAdditionalRawData, string name, string description, BinaryData parameters) : base(kind, serializedAdditionalRawData) + { + _name = name; + _description = description; + _parameters = parameters; + } +} diff --git a/src/Custom/RealtimeConversation/ConversationItem.cs b/src/Custom/RealtimeConversation/ConversationItem.cs new file mode 100644 index 000000000..03848f013 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationItem.cs @@ -0,0 +1,46 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Linq; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeRequestItem")] +public partial class ConversationItem +{ + public string FunctionCallId => (this as InternalRealtimeRequestFunctionCallItem)?.CallId; + public string FunctionName => (this as InternalRealtimeRequestFunctionCallItem)?.Name; + public string FunctionArguments => (this as InternalRealtimeRequestFunctionCallItem)?.Arguments; + + public IReadOnlyList MessageContentParts + => (this as InternalRealtimeRequestAssistantMessageItem)?.Content.ToList().AsReadOnly() + ?? (this as InternalRealtimeRequestSystemMessageItem)?.Content?.ToList().AsReadOnly() + ?? (this as InternalRealtimeRequestUserMessageItem)?.Content?.ToList().AsReadOnly(); + public ConversationMessageRole? MessageRole + => (this as InternalRealtimeRequestMessageItem)?.Role; + + public static ConversationItem CreateUserMessage(IEnumerable contentItems) + { + return new InternalRealtimeRequestUserMessageItem(contentItems); + } + + public static ConversationItem CreateSystemMessage(string toolCallId, IEnumerable contentItems) + { + return new InternalRealtimeRequestSystemMessageItem(contentItems); + } + + public static ConversationItem CreateAssistantMessage(IEnumerable contentItems) + { + return new InternalRealtimeRequestAssistantMessageItem(contentItems); + } + + public static ConversationItem CreateFunctionCall(string name, string callId, string arguments) + { + return new InternalRealtimeRequestFunctionCallItem(name, callId, arguments); + } + + public static ConversationItem CreateFunctionCallOutput(string callId, string output) + { + return new InternalRealtimeRequestFunctionCallOutputItem(callId, output); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.Serialization.cs b/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.Serialization.cs new file mode 100644 index 000000000..699d2020b --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.Serialization.cs @@ -0,0 +1,66 @@ +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation; + +public partial class ConversationMaxTokensChoice : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeConversationMaxTokensChoice, writer, options); + + ConversationMaxTokensChoice IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeConversationMaxTokensChoice, ref reader, options); + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, options); + + ConversationMaxTokensChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeConversationMaxTokensChoice, data, options); + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static void SerializeConversationMaxTokensChoice(ConversationMaxTokensChoice instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + if (instance._isDefaultNullValue == true) + { + writer.WriteNullValue(); + } + else if (instance._stringValue is not null) + { + writer.WriteStringValue(instance._stringValue); + } + else if (instance.NumericValue.HasValue) + { + writer.WriteNumberValue(instance.NumericValue.Value); + } + } + + internal static ConversationMaxTokensChoice DeserializeConversationMaxTokensChoice(JsonElement element, ModelReaderWriterOptions options = null) + { + if (element.ValueKind == JsonValueKind.Null) + { + return new ConversationMaxTokensChoice(isDefaultNullValue: true); + } + if (element.ValueKind == JsonValueKind.String) + { + return new ConversationMaxTokensChoice(stringValue: element.GetString()); + } + if (element.ValueKind == JsonValueKind.Number) + { + return new ConversationMaxTokensChoice(numberValue: element.GetInt32()); + } + return null; + } + + internal static ConversationMaxTokensChoice FromBinaryData(BinaryData bytes) + { + if (bytes is null) + { + return new ConversationMaxTokensChoice(isDefaultNullValue: true); + } + using JsonDocument document = JsonDocument.Parse(bytes); + return DeserializeConversationMaxTokensChoice(document.RootElement); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.cs b/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.cs new file mode 100644 index 000000000..5bc007139 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationMaxTokensChoice.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +public partial class ConversationMaxTokensChoice +{ + public int? NumericValue { get; } + private readonly bool? _isDefaultNullValue; + private readonly string _stringValue; + + public static ConversationMaxTokensChoice CreateInfiniteMaxTokensChoice() + => new("inf"); + public static ConversationMaxTokensChoice CreateDefaultMaxTokensChoice() + => new(isDefaultNullValue: true); + public static ConversationMaxTokensChoice CreateNumericMaxTokensChoice(int maxTokens) + => new(numberValue: maxTokens); + + public ConversationMaxTokensChoice(int numberValue) + { + NumericValue = numberValue; + } + + internal ConversationMaxTokensChoice(string stringValue) + { + _stringValue = stringValue; + } + + internal ConversationMaxTokensChoice(bool isDefaultNullValue) + { + _isDefaultNullValue = true; + } + + public static implicit operator ConversationMaxTokensChoice(int maxTokens) + => CreateNumericMaxTokensChoice(maxTokens); +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationSessionOptions.cs b/src/Custom/RealtimeConversation/ConversationSessionOptions.cs new file mode 100644 index 000000000..2d0290280 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationSessionOptions.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeRequestSessionUpdateCommandSession")] +public partial class ConversationSessionOptions +{ + [CodeGenMember("Model")] + public string Model { get; set; } + + [CodeGenMember("Modalities")] + private readonly IList _internalModalities + = new ChangeTrackingList(); + + public ConversationContentModalities ContentModalities + { + get => ConversationContentModalitiesExtensions.FromInternalModalities(_internalModalities); + set => value.ToInternalModalities(_internalModalities); + } + + [CodeGenMember("ToolChoice")] + private BinaryData _internalToolChoice; + + public ConversationToolChoice ToolChoice + { + get => ConversationToolChoice.FromBinaryData(_internalToolChoice); + set + { + _internalToolChoice = ModelReaderWriter.Write(value); + } + } + + [CodeGenMember("MaxResponseOutputTokens")] + private BinaryData _maxResponseOutputTokens; + + public ConversationMaxTokensChoice MaxResponseOutputTokens + { + get => ConversationMaxTokensChoice.FromBinaryData(_maxResponseOutputTokens); + set + { + _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + } + } + + [CodeGenMember("TurnDetection")] + public ConversationTurnDetectionOptions TurnDetectionOptions { get; set; } + + [CodeGenMember("InputAudioTranscription")] + public ConversationInputTranscriptionOptions InputTranscriptionOptions { get; set; } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationTool.cs b/src/Custom/RealtimeConversation/ConversationTool.cs new file mode 100644 index 000000000..be18996df --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationTool.cs @@ -0,0 +1,19 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeTool")] +public abstract partial class ConversationTool +{ + [CodeGenMember("Type")] + public ConversationToolKind Kind { get; } + + public static ConversationTool CreateFunctionTool(string name, string description = null, BinaryData parameters = null) + => new ConversationFunctionTool(name) + { + Description = description, + Parameters = parameters, + }; +} diff --git a/src/Custom/RealtimeConversation/ConversationToolChoice.Serialization.cs b/src/Custom/RealtimeConversation/ConversationToolChoice.Serialization.cs new file mode 100644 index 000000000..267f18f4a --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationToolChoice.Serialization.cs @@ -0,0 +1,68 @@ +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation; + +public partial class ConversationToolChoice : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeConversationToolChoice, writer, options); + + ConversationToolChoice IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeConversationToolChoice, ref reader, options); + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, options); + + ConversationToolChoice IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeConversationToolChoice, data, options); + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static void SerializeConversationToolChoice(ConversationToolChoice instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + if (instance._objectToolChoice is not null) + { + writer.WriteObjectValue(instance._objectToolChoice, options); + } + else + { + writer.WriteStringValue(instance.Kind.ToString()); + } + } + + internal static ConversationToolChoice DeserializeConversationToolChoice(JsonElement element, ModelReaderWriterOptions options = null) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.ValueKind == JsonValueKind.String) + { + return new ConversationToolChoice(element.GetString().ToConversationToolChoiceKind(), null); + } + if (element.ValueKind == JsonValueKind.Object) + { + InternalRealtimeToolChoiceObject choiceObject = InternalRealtimeToolChoiceObject + .DeserializeInternalRealtimeToolChoiceObject(element, options); + return choiceObject switch + { + InternalRealtimeToolChoiceFunctionObject => new(ConversationToolChoiceKind.Function, choiceObject), + _ => null, + }; + } + return null; + } + + internal static ConversationToolChoice FromBinaryData(BinaryData bytes) + { + if (bytes is null) + { + return null; + } + using JsonDocument document = JsonDocument.Parse(bytes); + return DeserializeConversationToolChoice(document.RootElement); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationToolChoice.cs b/src/Custom/RealtimeConversation/ConversationToolChoice.cs new file mode 100644 index 000000000..585085795 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationToolChoice.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +public partial class ConversationToolChoice +{ + public ConversationToolChoiceKind Kind { get; } + + public string FunctionName + => (_objectToolChoice as InternalRealtimeToolChoiceFunctionObject)?.Function?.Name; + + private readonly InternalRealtimeToolChoiceObject _objectToolChoice; + + public static ConversationToolChoice CreateAutoToolChoice() => new(ConversationToolChoiceKind.Auto, null); + public static ConversationToolChoice CreateNoneToolChoice() => new(ConversationToolChoiceKind.None, null); + public static ConversationToolChoice CreateRequiredToolChoice() => new(ConversationToolChoiceKind.Required, null); + + public static ConversationToolChoice CreateFunctionToolChoice(string functionName) + => new(ConversationToolChoiceKind.Function, new InternalRealtimeToolChoiceFunctionObject(new InternalRealtimeToolChoiceFunctionObjectFunction(functionName))); + + internal ConversationToolChoice(ConversationToolChoiceKind choiceKind, InternalRealtimeToolChoiceObject objectToolChoice) + { + Kind = choiceKind; + _objectToolChoice = objectToolChoice; + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationToolChoiceKind.cs b/src/Custom/RealtimeConversation/ConversationToolChoiceKind.cs new file mode 100644 index 000000000..ab6f431c5 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationToolChoiceKind.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeToolChoiceLiteral")] +public enum ConversationToolChoiceKind +{ + [CodeGenMember("Auto")] + Auto, + [CodeGenMember("None")] + None, + [CodeGenMember("Required")] + Required, + Function, +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationTurnDetectionKind.cs b/src/Custom/RealtimeConversation/ConversationTurnDetectionKind.cs new file mode 100644 index 000000000..6b0bcf117 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationTurnDetectionKind.cs @@ -0,0 +1,13 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeTurnDetectionType")] +public enum ConversationTurnDetectionKind +{ + [CodeGenMember("ServerVad")] + ServerVoiceActivityDetection, + Disabled, +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.Serialization.cs b/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.Serialization.cs new file mode 100644 index 000000000..726583841 --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.Serialization.cs @@ -0,0 +1,28 @@ +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation; + +[CodeGenSuppress(nameof(DeserializeConversationTurnDetectionOptions), typeof(JsonElement), typeof(ModelReaderWriterOptions))] +public partial class ConversationTurnDetectionOptions +{ + internal static ConversationTurnDetectionOptions DeserializeConversationTurnDetectionOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return InternalRealtimeNoTurnDetection.DeserializeInternalRealtimeNoTurnDetection(element, options); + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "server_vad": return InternalRealtimeServerVadTurnDetection.DeserializeInternalRealtimeServerVadTurnDetection(element, options); + } + } + return UnknownRealtimeTurnDetection.DeserializeUnknownRealtimeTurnDetection(element, options); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.cs b/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.cs new file mode 100644 index 000000000..efcb54a9d --- /dev/null +++ b/src/Custom/RealtimeConversation/ConversationTurnDetectionOptions.cs @@ -0,0 +1,30 @@ +using System; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeTurnDetection")] +public partial class ConversationTurnDetectionOptions +{ + [CodeGenMember("Kind")] + public ConversationTurnDetectionKind Kind { get; internal protected set; } + + public static ConversationTurnDetectionOptions CreateDisabledTurnDetectionOptions() + { + return new InternalRealtimeNoTurnDetection(); + } + + public static ConversationTurnDetectionOptions CreateServerVoiceActivityTurnDetectionOptions( + float? detectionThreshold = null, + TimeSpan? prefixPaddingDuration = null, + TimeSpan? silenceDuration = null) + { + return new InternalRealtimeServerVadTurnDetection() + { + Threshold = detectionThreshold, + PrefixPaddingMs = prefixPaddingDuration, + SilenceDurationMs = silenceDuration + }; + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/GeneratorStubs.cs b/src/Custom/RealtimeConversation/GeneratorStubs.cs new file mode 100644 index 000000000..38f6a5cf5 --- /dev/null +++ b/src/Custom/RealtimeConversation/GeneratorStubs.cs @@ -0,0 +1,33 @@ +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")][CodeGenModel("RealtimeAudioFormat")] public readonly partial struct ConversationAudioFormat { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeAudioInputTranscriptionModel")] public readonly partial struct ConversationTranscriptionModel { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeAudioInputTranscriptionSettings")] public partial class ConversationInputTranscriptionOptions { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeContentPartType")] public readonly partial struct ConversationContentPartKind { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeItemStatus")] public readonly partial struct ConversationItemStatus { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeMessageRole")] public readonly partial struct ConversationMessageRole { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseAudioDeltaCommand")] public partial class ConversationAudioDeltaUpdate{ } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseAudioDoneCommand")] public partial class ConversationAudioDoneUpdate{ } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseAudioTranscriptDeltaCommand")] public partial class ConversationOutputTranscriptionDeltaUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseAudioTranscriptDoneCommand")] public partial class ConversationOutputTranscriptionFinishedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseFunctionCallArgumentsDeltaCommand")] public partial class ConversationFunctionCallArgumentsDeltaUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseFunctionCallArgumentsDoneCommand")] public partial class ConversationFunctionCallArgumentsDoneUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseInputAudioBufferClearedCommand")] public partial class ConversationInputAudioBufferClearedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseInputAudioBufferCommittedCommand")] public partial class ConversationInputAudioBufferCommittedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseInputAudioBufferSpeechStartedCommand")] public partial class ConversationInputSpeechStartedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseInputAudioBufferSpeechStoppedCommand")] public partial class ConversationInputSpeechFinishedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseItemDeletedCommand")] public partial class ConversationItemDeletedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseItemInputAudioTranscriptionCompletedCommand")] public partial class ConversationInputTranscriptionFinishedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseItemTruncatedCommand")] public partial class ConversationItemTruncatedUpdate { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseRateLimitDetailsItem")] public partial class ConversationRateLimitDetailsItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseRateLimitsUpdatedCommand")] public partial class ConversationRateLimitsUpdatedUpdate{ } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseStatus")] public readonly partial struct ConversationStatus { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseTextDeltaCommand")] public partial class ConversationTextDeltaUpdate{ } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseTextDoneCommand")] public partial class ConversationTextDoneUpdate{ } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseUsage")] public partial class ConversationTokenUsage { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseUsageInputTokenDetails")] public partial class ConversationInputTokenUsageDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseUsageOutputTokenDetails")] public partial class ConversationOutputTokenUsageDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeToolType")] public readonly partial struct ConversationToolKind { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeVoice")] public readonly partial struct ConversationVoice { } diff --git a/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageCollectionResult.cs b/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageCollectionResult.cs new file mode 100644 index 000000000..439f977f2 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageCollectionResult.cs @@ -0,0 +1,48 @@ +using OpenAI.Chat; +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Net.ServerSentEvents; +using System.Net.WebSockets; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +internal partial class AsyncWebsocketMessageCollectionResult : AsyncCollectionResult +{ + private readonly ClientWebSocket _clientWebSocket; + private readonly CancellationToken _cancellationToken; + + public AsyncWebsocketMessageCollectionResult( + ClientWebSocket clientWebSocket, + CancellationToken cancellationToken) + { + Argument.AssertNotNull(clientWebSocket, nameof(clientWebSocket)); + + _clientWebSocket = clientWebSocket; + _cancellationToken = cancellationToken; + } + + public override ContinuationToken GetContinuationToken(ClientResult page) + + // Continuation is not supported for SSE streams. + => null; + + public override async IAsyncEnumerable GetRawPagesAsync() + { + await using IAsyncEnumerator enumerator = new AsyncWebsocketMessageResultEnumerator(_clientWebSocket, _cancellationToken); + while (await enumerator.MoveNextAsync().ConfigureAwait(false)) + { + yield return enumerator.Current; + } + } + + protected override async IAsyncEnumerable GetValuesFromPageAsync(ClientResult page) + { + await Task.FromResult(Task.CompletedTask); + yield return page; + } +} diff --git a/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageEnumerator.cs b/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageEnumerator.cs new file mode 100644 index 000000000..1d9edbe76 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/AsyncWebsocketMessageEnumerator.cs @@ -0,0 +1,53 @@ +using System; +using System.Buffers; +using System.ClientModel; +using System.Collections.Generic; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +internal partial class AsyncWebsocketMessageResultEnumerator : IAsyncEnumerator +{ + public ClientResult Current { get; private set; } + private readonly CancellationToken _cancellationToken; + private readonly ClientWebSocket _clientWebSocket; + private readonly byte[] _receiveBuffer; + + public AsyncWebsocketMessageResultEnumerator(ClientWebSocket clientWebSocket, CancellationToken cancellationToken) + { + _clientWebSocket = clientWebSocket; + // 18K buffer size based on traffic observation; the connection will appropriately negotiate and use + // fragmented messages if the buffer size is inadequate. + _receiveBuffer = ArrayPool.Shared.Rent(1024 * 18); + _cancellationToken = cancellationToken; + } + + public ValueTask DisposeAsync() + { + _clientWebSocket?.Dispose(); + return new ValueTask(Task.CompletedTask); + } + + public async ValueTask MoveNextAsync() + { + WebsocketPipelineResponse websocketPipelineResponse = new(); + for (int partialMessageCount = 1; !websocketPipelineResponse.IsComplete; partialMessageCount++) + { + WebSocketReceiveResult receiveResult = await _clientWebSocket.ReceiveAsync(new(_receiveBuffer), _cancellationToken); + if (receiveResult.CloseStatus.HasValue) + { + Current = null; + return false; + } + ReadOnlyMemory receivedBytes = _receiveBuffer.AsMemory(0, receiveResult.Count); + BinaryData receivedData = BinaryData.FromBytes(receivedBytes); + + websocketPipelineResponse.IngestReceivedResult(receiveResult, receivedData); + } + + Current = ClientResult.FromResponse(websocketPipelineResponse); + return true; + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/Internal/GeneratorStubs.cs b/src/Custom/RealtimeConversation/Internal/GeneratorStubs.cs new file mode 100644 index 000000000..12d44116e --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/GeneratorStubs.cs @@ -0,0 +1,52 @@ +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")][CodeGenModel("RealtimeItemType")] internal readonly partial struct InternalRealtimeRequestItemType { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestAudioContentPart")] internal partial class InternalRealtimeRequestAudioContentPart { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestCommand")] internal partial class InternalRealtimeRequestCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestCommandType")] internal readonly partial struct InternalRealtimeRequestCommandType { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestFunctionCallItem")] internal partial class InternalRealtimeRequestFunctionCallItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestFunctionCallOutputItem")] internal partial class InternalRealtimeRequestFunctionCallOutputItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestInputAudioBufferAppendCommand")] internal partial class InternalRealtimeRequestInputAudioBufferAppendCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestInputAudioBufferClearCommand")] internal partial class InternalRealtimeRequestInputAudioBufferClearCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestInputAudioBufferCommitCommand")] internal partial class InternalRealtimeRequestInputAudioBufferCommitCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestItemCreateCommand")] internal partial class InternalRealtimeRequestItemCreateCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestItemDeleteCommand")] internal partial class InternalRealtimeRequestItemDeleteCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestItemTruncateCommand")] internal partial class InternalRealtimeRequestItemTruncateCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestMessageItem")] internal partial class InternalRealtimeRequestMessageItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestModel")] internal readonly partial struct InternalRealtimeRequestModel { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestResponseCancelCommand")] internal partial class InternalRealtimeRequestResponseCancelCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestResponseCreateCommandResponse")] internal partial class InternalRealtimeRequestResponseCreateCommandResponse { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestSessionUpdateCommand")] internal partial class InternalRealtimeRequestSessionUpdateCommand { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestSessionUpdateCommandSessionModality")] internal readonly partial struct InternalRealtimeRequestSessionUpdateCommandSessionModality { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeRequestTextContentPart")] internal partial class InternalRealtimeRequestTextContentPart { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseApiError")] internal partial class InternalRealtimeResponseApiError { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseAudioContentPart")] internal partial class InternalRealtimeResponseAudioContentPart { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseCancelledStatusDetails")] internal partial class InternalRealtimeResponseCancelledStatusDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseCancelledStatusDetailsReason")] internal readonly partial struct InternalRealtimeResponseCancelledStatusDetailsReason { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseFailedStatusDetails")] internal partial class RealtimeResponseFailedStatusDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseFunctionCallItem")] internal partial class InternalRealtimeResponseFunctionCallItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseFunctionCallOutputItem")] internal partial class InternalRealtimeResponseFunctionCallOutputItem { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseIncompleteStatusDetails")] internal partial class InternalRealtimeResponseIncompleteStatusDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseIncompleteStatusDetailsReason")] internal readonly partial struct InternalRealtimeResponseIncompleteStatusDetailsReason { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseIncompleteStatusReason")] internal readonly partial struct InternalRealtimeResponseIncompleteStatusReason { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseItemObject")] internal readonly partial struct InternalRealtimeResponseItemObject { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseObject")] internal readonly partial struct InternalRealtimeResponseObject { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseSessionObject")] internal readonly partial struct InternalRealtimeResponseSessionObject { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseStatusDetails")] internal partial class InternalRealtimeResponseStatusDetails { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseStatusDetailsType")] internal readonly partial struct InternalRealtimeResponseStatusDetailsType { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseTextContentPart")] internal partial class InternalRealtimeResponseTextContentPart { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeToolChoiceFunctionObject")] internal partial class InternalRealtimeToolChoiceFunctionObject { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeToolChoiceFunctionObjectFunction")] internal partial class InternalRealtimeToolChoiceFunctionObjectFunction { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeToolChoiceObject")] internal partial class InternalRealtimeToolChoiceObject { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeContentPart")] internal partial class UnknownRealtimeContentPart { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeRequestCommand")] internal partial class UnknownRealtimeRequestCommand { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeRequestItem")] internal partial class UnknownRealtimeRequestItem { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeResponseCommand")] internal partial class UnknownRealtimeResponseCommand { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeResponseItem")] internal partial class UnknownRealtimeResponseItem { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeResponseStatusDetails")] internal partial class UnknownRealtimeResponseStatusDetails { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeTool")] internal partial class UnknownRealtimeTool { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeToolChoiceObject")] internal partial class UnknownRealtimeToolChoiceObject { } +[Experimental("OPENAI002")][CodeGenModel("UnknownRealtimeTurnDetection")] internal partial class UnknownRealtimeTurnDetection { } +[Experimental("OPENAI002")][CodeGenModel("RealtimeResponseError")] internal partial class InternalRealtimeResponseError { } diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.Serialization.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.Serialization.cs new file mode 100644 index 000000000..d5e6f7793 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.Serialization.cs @@ -0,0 +1,33 @@ +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation; + +internal partial class InternalRealtimeNoTurnDetection : IJsonModel +{ + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, SerializeInternalRealtimeNoTurnDetection, writer, options); + + InternalRealtimeNoTurnDetection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeInternalRealtimeNoTurnDetection, ref reader, options); + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + => CustomSerializationHelpers.SerializeInstance(this, options); + + InternalRealtimeNoTurnDetection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + => CustomSerializationHelpers.DeserializeNewInstance(this, DeserializeInternalRealtimeNoTurnDetection, data, options); + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static void SerializeInternalRealtimeNoTurnDetection(InternalRealtimeNoTurnDetection instance, Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + writer.WriteNullValue(); + } + + internal static InternalRealtimeNoTurnDetection DeserializeInternalRealtimeNoTurnDetection(JsonElement element, ModelReaderWriterOptions options = null) + { + return new(); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.cs new file mode 100644 index 000000000..436b0dac1 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeNoTurnDetection.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation; + +internal partial class InternalRealtimeNoTurnDetection : ConversationTurnDetectionOptions +{ + public InternalRealtimeNoTurnDetection() + : this(ConversationTurnDetectionKind.Disabled, null) + { } + + internal InternalRealtimeNoTurnDetection(ConversationTurnDetectionKind type, IDictionary serializedAdditionalRawData) + : base(type, serializedAdditionalRawData) + { } +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestAssistantMessageItem.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestAssistantMessageItem.cs new file mode 100644 index 000000000..4643b7099 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestAssistantMessageItem.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[CodeGenModel("RealtimeRequestAssistantMessageItem")] +[Experimental("OPENAI002")] +internal partial class InternalRealtimeRequestAssistantMessageItem +{ + [CodeGenMember("Content")] + public IList Content { get; } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestResponseCreateCommand.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestResponseCreateCommand.cs new file mode 100644 index 000000000..aa271a0ee --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestResponseCreateCommand.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeRequestResponseCreateCommand")] +internal partial class InternalRealtimeRequestResponseCreateCommand +{ + [CodeGenMember("MaxOutputTokens")] + private BinaryData _maxOutputTokens; + + public ConversationMaxTokensChoice MaxResponseOutputTokens + { + get => ConversationMaxTokensChoice.FromBinaryData(_maxOutputTokens); + set + { + _maxOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + } + } +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestSystemMessageItem.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestSystemMessageItem.cs new file mode 100644 index 000000000..9bff50458 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestSystemMessageItem.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeRequestSystemMessageItem")] +internal partial class InternalRealtimeRequestSystemMessageItem +{ + [CodeGenMember("Content")] + public IList Content { get; } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestUserMessageItem.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestUserMessageItem.cs new file mode 100644 index 000000000..26d440981 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeRequestUserMessageItem.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Linq; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeRequestUserMessageItem")] +internal partial class InternalRealtimeRequestUserMessageItem +{ + public InternalRealtimeRequestUserMessageItem(IEnumerable content) + { + Argument.AssertNotNull(content, nameof(content)); + + Type = InternalRealtimeRequestItemType.Message; + Role = ConversationMessageRole.User; + Content = content.ToList(); + } + + [CodeGenMember("Content")] + public IList Content { get; } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponse.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponse.cs new file mode 100644 index 000000000..0c26a8a28 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponse")] +internal partial class InternalRealtimeResponse +{ + [CodeGenMember("Output")] + public IReadOnlyList Output { get; } +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseItem.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseItem.cs new file mode 100644 index 000000000..147a22270 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseItem.cs @@ -0,0 +1,28 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseItem")] +internal partial class InternalRealtimeResponseItem +{ + public ConversationMessageRole? MessageRole => + (this as InternalRealtimeResponseMessageItem)?.Role; + + public IReadOnlyList MessageContentParts => + (this as InternalRealtimeResponseMessageItem)?.Content; + + public string FunctionName + => (this as InternalRealtimeResponseFunctionCallItem)?.Name; + + public string FunctionCallId => + (this as InternalRealtimeResponseFunctionCallItem)?.CallId + ?? (this as InternalRealtimeResponseFunctionCallOutputItem)?.CallId; + + public string FunctionCallArguments => + (this as InternalRealtimeResponseFunctionCallItem)?.Arguments; + + public string FunctionCallOutput => + (this as InternalRealtimeResponseFunctionCallOutputItem)?.Output; +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseMessageItem.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseMessageItem.cs new file mode 100644 index 000000000..a69346981 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseMessageItem.cs @@ -0,0 +1,11 @@ +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseMessageItem")] +internal partial class InternalRealtimeResponseMessageItem +{ + [CodeGenMember("Role")] + public ConversationMessageRole Role { get; } +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseSession.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseSession.cs new file mode 100644 index 000000000..4450188ef --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeResponseSession.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseSession")] +internal partial class InternalRealtimeResponseSession +{ + [CodeGenMember("MaxResponseOutputTokens")] + private BinaryData _maxResponseOutputTokens; + + public ConversationMaxTokensChoice MaxResponseOutputTokens + { + get => ConversationMaxTokensChoice.FromBinaryData(_maxResponseOutputTokens); + set + { + _maxResponseOutputTokens = value == null ? null : ModelReaderWriter.Write(value); + } + } +} diff --git a/src/Custom/RealtimeConversation/Internal/InternalRealtimeServerVadTurnDetection.Serialization.cs b/src/Custom/RealtimeConversation/Internal/InternalRealtimeServerVadTurnDetection.Serialization.cs new file mode 100644 index 000000000..98aeaa1b1 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/InternalRealtimeServerVadTurnDetection.Serialization.cs @@ -0,0 +1,44 @@ +using OpenAI.VectorStores; +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeServerVadTurnDetection")] +[CodeGenSerialization(nameof(PrefixPaddingMs), DeserializationValueHook = nameof(DeserializeMillisecondDuration), SerializationValueHook = nameof(SerializePrefixPaddingMs))] +[CodeGenSerialization(nameof(SilenceDurationMs), DeserializationValueHook = nameof(DeserializeMillisecondDuration), SerializationValueHook = nameof(SerializeSilenceDurationMs))] +internal partial class InternalRealtimeServerVadTurnDetection +{ + private static void DeserializeMillisecondDuration(JsonProperty property, ref TimeSpan? duration) + { + if (property.Value.ValueKind == JsonValueKind.Number) + { + duration = TimeSpan.FromMilliseconds(property.Value.GetInt32()); + } + } + + private void SerializePrefixPaddingMs(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + SerializeMillisecondDuration(writer, PrefixPaddingMs); + } + + private void SerializeSilenceDurationMs(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + SerializeMillisecondDuration(writer, SilenceDurationMs); + } + + private static void SerializeMillisecondDuration(Utf8JsonWriter writer, TimeSpan? duration) + { + if (duration.HasValue) + { + writer.WriteNumberValue((int)duration.Value.TotalMilliseconds); + } + else + { + writer.WriteNullValue(); + } + } +} diff --git a/src/Custom/RealtimeConversation/Internal/WebsocketPipelineResponse.cs b/src/Custom/RealtimeConversation/Internal/WebsocketPipelineResponse.cs new file mode 100644 index 000000000..31935f243 --- /dev/null +++ b/src/Custom/RealtimeConversation/Internal/WebsocketPipelineResponse.cs @@ -0,0 +1,91 @@ +using System; +using System.ClientModel.Primitives; +using System.IO; +using System.Net; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +/// +/// Represents a encapsulating the data from a WebSocket response message. +/// +/// +/// WebSocket messages can be split across multiple network receive operations and a single +/// may thus ingest and present data across several such operations. +/// +internal class WebsocketPipelineResponse : PipelineResponse +{ + public override int Status => _status; + private int _status; + + public override string ReasonPhrase => _reasonPhrase; + private string _reasonPhrase; + + public override Stream ContentStream + { + get => _contentStream ??= new MemoryStream(); + set => throw new NotImplementedException(); + } + private MemoryStream _contentStream; + + public override BinaryData Content => _content ??= new(_contentStream.ToArray()); + private BinaryData _content; + + public bool IsComplete { get; private set; } = false; + + protected override PipelineResponseHeaders HeadersCore => throw new NotImplementedException(); + + public WebsocketPipelineResponse() + { + } + + public void IngestReceivedResult(WebSocketReceiveResult receivedResult, BinaryData receivedBytes) + { + if (ContentStream.Length == 0) + { + _status = ConvertWebsocketCloseStatusToHttpStatus(receivedResult.CloseStatus ?? WebSocketCloseStatus.Empty); + _reasonPhrase = receivedResult.CloseStatusDescription + ?? (receivedResult.CloseStatus ?? WebSocketCloseStatus.Empty).ToString(); + } + else if (receivedResult.MessageType != WebSocketMessageType.Text) + { + throw new NotImplementedException($"{nameof(WebsocketPipelineResponse)} currently supports only text messages."); + } + byte[] rawReceivedBytes = receivedBytes.ToArray(); + _contentStream.Position = _contentStream.Length; + _contentStream.Write(rawReceivedBytes, 0, rawReceivedBytes.Length); + _contentStream.Position = 0; + IsComplete = receivedResult.EndOfMessage; + } + + public override BinaryData BufferContent(CancellationToken cancellationToken = default) + => Content; + + public override ValueTask BufferContentAsync(CancellationToken cancellationToken = default) + => new ValueTask(Task.FromResult(Content)); + + public override void Dispose() + { + ContentStream?.Dispose(); + } + + private static int ConvertWebsocketCloseStatusToHttpStatus(WebSocketCloseStatus closeStatus) + { + return closeStatus switch + { + WebSocketCloseStatus.Empty + or WebSocketCloseStatus.NormalClosure => (int)HttpStatusCode.OK, + WebSocketCloseStatus.EndpointUnavailable + or WebSocketCloseStatus.ProtocolError + or WebSocketCloseStatus.InvalidMessageType + or WebSocketCloseStatus.InvalidPayloadData + or WebSocketCloseStatus.PolicyViolation => (int)HttpStatusCode.BadRequest, + WebSocketCloseStatus.MessageTooBig => (int)HttpStatusCode.RequestEntityTooLarge, + WebSocketCloseStatus.MandatoryExtension => 418, // https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/418 + WebSocketCloseStatus.InternalServerError => (int)HttpStatusCode.InternalServerError, + _ => (int)HttpStatusCode.InternalServerError, + }; + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/RealtimeConversationClient.Protocol.cs b/src/Custom/RealtimeConversation/RealtimeConversationClient.Protocol.cs new file mode 100644 index 000000000..398d8a5c2 --- /dev/null +++ b/src/Custom/RealtimeConversation/RealtimeConversationClient.Protocol.cs @@ -0,0 +1,31 @@ +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +public partial class RealtimeConversationClient +{ + /// + /// [Protocol Method] + /// Creates a new realtime conversation operation instance, establishing the connection and optionally sending an + /// initial configuration message payload. + /// + /// + /// + public virtual async Task StartConversationSessionAsync(RequestOptions options) + { + RealtimeConversationSession provisionalSession = new(this, _endpoint, _credential); + try + { + await provisionalSession.ConnectAsync(options).ConfigureAwait(false); + RealtimeConversationSession result = provisionalSession; + provisionalSession = null; + return result; + } + finally + { + provisionalSession?.Dispose(); + } + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/RealtimeConversationClient.cs b/src/Custom/RealtimeConversation/RealtimeConversationClient.cs new file mode 100644 index 000000000..15665d03f --- /dev/null +++ b/src/Custom/RealtimeConversation/RealtimeConversationClient.cs @@ -0,0 +1,105 @@ +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +[CodeGenClient("Realtime")] +[CodeGenSuppress("StartRealtimeSessionAsync", typeof(IEnumerable))] +[CodeGenSuppress("StartRealtimeSessionAsync", typeof(BinaryContent), typeof(RequestOptions))] +[CodeGenSuppress("StartRealtimeSession", typeof(IEnumerable))] +[CodeGenSuppress("StartRealtimeSession", typeof(BinaryContent), typeof(RequestOptions))] +[CodeGenSuppress("CreateStartRealtimeSessionRequest", typeof(BinaryContent), typeof(RequestOptions))] +[Experimental("OPENAI002")] +public partial class RealtimeConversationClient +{ + public event EventHandler OnSendingCommand; + public event EventHandler OnReceivingCommand; + + private readonly Uri _endpoint; + private readonly ApiKeyCredential _credential; + + /// + /// Creates a new instance of using an API key for authentication. + /// + /// The API key to use for authentication. + public RealtimeConversationClient(string model, ApiKeyCredential credential) : this(model, credential, new OpenAIClientOptions()) + { + } + + /// + /// Creates a new instance of using an API key for authentication. + /// + /// The API key to use for authentication. + /// Additional options for configuring the client. + public RealtimeConversationClient(string model, ApiKeyCredential credential, OpenAIClientOptions options) + { + Argument.AssertNotNull(credential, nameof(credential)); + Argument.AssertNotNull(options, nameof(options)); + + _credential = credential; + _endpoint = GetEndpoint(model, options); + } + + protected internal RealtimeConversationClient(ClientPipeline pipeline, OpenAIClientOptions options) + { + throw new NotImplementedException("Pipeline-based initialization of WS-based client not available"); + } + + /// + /// Starts a new , optionally applying initial configuration to the session and + /// default conversation for the session. + /// + /// + /// The abstracts bidirectional communication between the caller and service, + /// simultaneously sending and receiving WebSocket messages. + /// + /// + /// A new, connected, configured instance of . + public virtual async Task StartConversationSessionAsync( + CancellationToken cancellationToken = default) + { + RequestOptions cancellationOptions = cancellationToken.ToRequestOptions(); + RealtimeConversationSession newOperation = await StartConversationSessionAsync(cancellationOptions).ConfigureAwait(false); + return newOperation; + } + + public RealtimeConversationSession StartConversationSession(CancellationToken cancellationToken = default) + { + return StartConversationSessionAsync(cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); + } + + private static Uri GetEndpoint(string model, OpenAIClientOptions options) + { + UriBuilder uriBuilder = new(options?.Endpoint ?? new("https://api.openai.com/v1")); + uriBuilder.Scheme = uriBuilder.Scheme.ToLowerInvariant() switch + { + "http" => "ws", + "https" => "wss", + _ => uriBuilder.Scheme + }; + uriBuilder.Query = ""; + if (!uriBuilder.Path.EndsWith("/realtime")) + { + uriBuilder.Path += uriBuilder.Path[uriBuilder.Path.Length - 1] == '/' ? "realtime" : "/realtime"; + } + + uriBuilder.Query = $"?model={model}"; + + return uriBuilder.Uri; + } + + internal void RaiseOnSendingCommand(RealtimeConversationSession session, BinaryData data) + { + OnSendingCommand?.Invoke(session, data); + } + + internal void RaiseOnReceivingCommand(RealtimeConversationSession session, BinaryData data) + { + OnReceivingCommand?.Invoke(session, data); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/RealtimeConversationSession.Protocol.cs b/src/Custom/RealtimeConversation/RealtimeConversationSession.Protocol.cs new file mode 100644 index 000000000..c7767fd77 --- /dev/null +++ b/src/Custom/RealtimeConversation/RealtimeConversationSession.Protocol.cs @@ -0,0 +1,90 @@ +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.ComponentModel; +using System.Net.WebSockets; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +public partial class RealtimeConversationSession +{ + protected ClientWebSocket _clientWebSocket; + private readonly SemaphoreSlim _clientSendSemaphore = new(initialCount: 1, maxCount: 1); + private readonly object _singleReceiveLock = new(); + private AsyncWebsocketMessageCollectionResult _receiveCollectionResult; + + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal virtual async Task ConnectAsync(RequestOptions options) + { + _clientWebSocket.Options.AddSubProtocol("realtime"); + await _clientWebSocket.ConnectAsync(_endpoint, options?.CancellationToken ?? default) + .ConfigureAwait(false); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + protected internal virtual void Connect(RequestOptions options) + { + ConnectAsync(options).Wait(); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async Task SendCommandAsync(BinaryData data, RequestOptions options) + { + Argument.AssertNotNull(data, nameof(data)); + + _parentClient?.RaiseOnSendingCommand(this, data); + + ArraySegment messageBytes = new(data.ToArray()); + + CancellationToken cancellationToken = options?.CancellationToken ?? default; + + await _clientSendSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); + try + { + await _clientWebSocket.SendAsync( + messageBytes, + WebSocketMessageType.Text, // TODO: extensibility for binary messages -- via "content"? + endOfMessage: true, + cancellationToken) + .ConfigureAwait(false); + } + finally + { + _clientSendSemaphore.Release(); + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual void SendCommand(BinaryData data, RequestOptions options) + { + // ClientWebSocket does **not** include a synchronous Send() + SendCommandAsync(data, options).Wait(); + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual async IAsyncEnumerable ReceiveUpdatesAsync(RequestOptions options) + { + lock (_singleReceiveLock) + { + _receiveCollectionResult ??= new(_clientWebSocket, options?.CancellationToken ?? default); + } + await foreach (ClientResult result in _receiveCollectionResult) + { + BinaryData incomingMessage = result?.GetRawResponse()?.Content; + if (incomingMessage is not null) + { + _parentClient?.RaiseOnReceivingCommand(this, incomingMessage); + } + yield return result; + } + } + + [EditorBrowsable(EditorBrowsableState.Never)] + public virtual IEnumerable ReceiveUpdates(RequestOptions options) + { + throw new NotImplementedException(); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/RealtimeConversationSession.cs b/src/Custom/RealtimeConversation/RealtimeConversationSession.cs new file mode 100644 index 000000000..9ecc09870 --- /dev/null +++ b/src/Custom/RealtimeConversation/RealtimeConversationSession.cs @@ -0,0 +1,180 @@ +using System; +using System.Buffers; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; +using System.IO; +using System.Net.WebSockets; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +public partial class RealtimeConversationSession : IDisposable +{ + private readonly RealtimeConversationClient _parentClient; + private readonly Uri _endpoint; + private readonly ApiKeyCredential _credential; + private readonly object _sendingAudioLock = new(); + private bool _isSendingAudio = false; + + internal bool ShouldBufferTurnResponseData { get; set; } + + protected internal RealtimeConversationSession( + RealtimeConversationClient parentClient, + Uri endpoint, + ApiKeyCredential credential) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + Argument.AssertNotNull(credential, nameof(credential)); + + _parentClient = parentClient; + _endpoint = endpoint; + _credential = credential; + _clientWebSocket = new ClientWebSocket(); + + _credential.Deconstruct(out string dangerousCredential); + _clientWebSocket.Options.SetRequestHeader("openai-beta", $"realtime=v1"); + _clientWebSocket.Options.SetRequestHeader("Authorization", $"Bearer {dangerousCredential}"); + } + + /// + /// Transmits audio data from a stream, ending the client turn once the stream is complete. + /// + /// The audio stream to transmit. + /// An optional cancellation token. + /// + public async Task SendAudioAsync(Stream audio, CancellationToken cancellationToken = default) + { + lock (_sendingAudioLock) + { + if (_isSendingAudio) + { + throw new InvalidOperationException($"Only one stream of audio may be sent at once."); + } + _isSendingAudio = true; + } + try + { + byte[] buffer = ArrayPool.Shared.Rent(1024 * 16); + while (true) + { + int bytesRead = await audio.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false); + if (bytesRead == 0) + { + break; + } + + ReadOnlyMemory audioMemory = buffer.AsMemory(0, bytesRead); + BinaryData audioData = BinaryData.FromBytes(audioMemory); + InternalRealtimeRequestInputAudioBufferAppendCommand internalCommand = new(audioData); + BinaryData requestData = ModelReaderWriter.Write(internalCommand); + await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + } + } + finally + { + lock (_sendingAudioLock) + { + _isSendingAudio = false; + } + } + } + + /// + /// Transmits a single chunk of audio. + /// + /// + /// + /// + /// + public async Task SendAudioAsync(BinaryData audio, CancellationToken cancellationToken = default) + { + lock (_sendingAudioLock) + { + if (_isSendingAudio) + { + throw new InvalidOperationException($"Cannot send a standalone audio chunk while a stream is already in progress."); + } + _isSendingAudio = true; + } + // TODO: consider automatically limiting/breaking size of chunk (as with streaming) + InternalRealtimeRequestInputAudioBufferAppendCommand internalCommand = new(audio); + BinaryData requestData = ModelReaderWriter.Write(internalCommand); + await SendCommandAsync(requestData, cancellationToken.ToRequestOptions()).ConfigureAwait(false); + } + + public async Task ConfigureSessionAsync(ConversationSessionOptions sessionOptions, CancellationToken cancellationToken = default) + { + InternalRealtimeRequestSessionUpdateCommand internalCommand = new(sessionOptions); + await SendCommandAsync(internalCommand, cancellationToken).ConfigureAwait(false); + } + + public async Task AddItemAsync(ConversationItem item, CancellationToken cancellationToken = default) + => await AddItemAsync(item, null, cancellationToken).ConfigureAwait(false); + + public async Task AddItemAsync(ConversationItem item, string previousItemId, CancellationToken cancellationToken = default) + { + InternalRealtimeRequestItemCreateCommand internalCommand = new(item) + { + PreviousItemId = previousItemId, + }; + await SendCommandAsync(internalCommand, cancellationToken).ConfigureAwait(false); + } + + public async Task DeleteItemAsync(string itemId, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + await SendCommandAsync(new InternalRealtimeRequestItemDeleteCommand(itemId), cancellationToken).ConfigureAwait(false); + } + + public async Task CommitPendingAudioAsync(CancellationToken cancellationToken = default) + { + await SendCommandAsync(new InternalRealtimeRequestInputAudioBufferCommitCommand(), cancellationToken).ConfigureAwait(false); + } + + public async Task InterruptTurnAsync(CancellationToken cancellationToken = default) + { + await SendCommandAsync(new InternalRealtimeRequestResponseCancelCommand(), cancellationToken).ConfigureAwait(false); + } + + public async Task StartResponseTurnAsync(CancellationToken cancellationToken = default) + { + InternalRealtimeRequestResponseCreateCommand internalCommand = new() + { + Response = new(commit: true, cancelPrevious: true) + }; + await SendCommandAsync(internalCommand, cancellationToken).ConfigureAwait(false); + } + + public async Task CancelResponseTurnAsync(CancellationToken cancellationToken = default) + { + InternalRealtimeRequestResponseCancelCommand internalCommand = new(); + await SendCommandAsync(internalCommand, cancellationToken).ConfigureAwait(false); + } + + internal virtual async Task SendCommandAsync(InternalRealtimeRequestCommand command, CancellationToken cancellationToken = default) + { + BinaryData requestData = ModelReaderWriter.Write(command); + RequestOptions cancellationOptions = cancellationToken.ToRequestOptions(); + await SendCommandAsync(requestData, cancellationOptions).ConfigureAwait(false); + } + + public async IAsyncEnumerable ReceiveUpdatesAsync([EnumeratorCancellation] CancellationToken cancellationToken = default) + { + await foreach (ClientResult protocolEvent in ReceiveUpdatesAsync(cancellationToken.ToRequestOptions())) + { + ConversationUpdate nextUpdate = ConversationUpdate.FromResponse(protocolEvent.GetRawResponse()); + yield return nextUpdate; + } + } + + public void Dispose() + { + _clientWebSocket?.Dispose(); + } +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartFinishedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartFinishedUpdate.cs new file mode 100644 index 000000000..c9c568cf5 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartFinishedUpdate.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseContentPartDoneCommand")] +public partial class ConversationContentPartFinishedUpdate +{ + [CodeGenMember("Part")] + private readonly ConversationContentPart _internalContentPart; + + public ConversationContentPartKind ContentKind => _internalContentPart switch + { + InternalRealtimeResponseTextContentPart => ConversationContentPartKind.InputText, + InternalRealtimeResponseAudioContentPart => ConversationContentPartKind.InputAudio, + _ => null, + }; + + public string Text => (_internalContentPart as InternalRealtimeResponseTextContentPart)?.Text; + public string AudioTranscript => (_internalContentPart as InternalRealtimeResponseAudioContentPart)?.Transcript; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartStartedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartStartedUpdate.cs new file mode 100644 index 000000000..5bd021df1 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationContentPartStartedUpdate.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseContentPartAddedCommand")] +public partial class ConversationContentPartStartedUpdate +{ + [CodeGenMember("Part")] + private readonly ConversationContentPart _internalContentPart; + + public ConversationContentPartKind ContentKind => _internalContentPart switch + { + InternalRealtimeResponseTextContentPart => ConversationContentPartKind.InputText, + InternalRealtimeResponseAudioContentPart => ConversationContentPartKind.InputAudio, + _ => null, + }; + + public string Text => (_internalContentPart as InternalRealtimeResponseTextContentPart)?.Text; + public string AudioTranscript => (_internalContentPart as InternalRealtimeResponseAudioContentPart)?.Transcript; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationErrorUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationErrorUpdate.cs new file mode 100644 index 000000000..2b1c09e8e --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationErrorUpdate.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseErrorCommand")] +public partial class ConversationErrorUpdate +{ + [CodeGenMember("Error")] + private readonly InternalRealtimeResponseError _error; + + public string ErrorCode => _error?.Code; + public string ErrorMessage => _error?.Message; + public string ErrorParameterName => _error?.Param; + public string ErrorEventId => _error?.EventId; +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationInputTranscriptionFailedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationInputTranscriptionFailedUpdate.cs new file mode 100644 index 000000000..a236af055 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationInputTranscriptionFailedUpdate.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.ClientModel.Primitives; +using System.Text.Json; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseItemInputAudioTranscriptionFailedCommand")] +public partial class ConversationInputTranscriptionFailedUpdate +{ + [CodeGenMember("Error")] + private readonly InternalRealtimeResponseApiError _error; + + public string ErrorCode => _error?.Code; + public string ErrorMessage => _error?.Message; + public string ErrorParameterName => _error?.Param; +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemAcknowledgedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemAcknowledgedUpdate.cs new file mode 100644 index 000000000..5a5f0953c --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemAcknowledgedUpdate.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseItemCreatedCommand")] +public partial class ConversationItemAcknowledgedUpdate +{ + [CodeGenMember("Item")] + public ConversationItem Item { get; } +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemFinishedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemFinishedUpdate.cs new file mode 100644 index 000000000..ee364a0f4 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemFinishedUpdate.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseOutputItemDoneCommand")] +public partial class ConversationItemFinishedUpdate +{ + [CodeGenMember("Item")] + private readonly InternalRealtimeResponseItem _internalItem; + + public ConversationMessageRole? MessageRole => _internalItem.MessageRole; + + public IReadOnlyList MessageContentParts => _internalItem.MessageContentParts; + + public string FunctionName => _internalItem.FunctionName; + + public string FunctionCallId => _internalItem.FunctionCallId; + + public string FunctionCallArguments => _internalItem.FunctionCallArguments; + + public string FunctionCallOutput => _internalItem.FunctionCallOutput; +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemStartedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemStartedUpdate.cs new file mode 100644 index 000000000..61e7fe374 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationItemStartedUpdate.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseOutputItemAddedCommand")] +public partial class ConversationItemStartedUpdate +{ + [CodeGenMember("Item")] + private readonly InternalRealtimeResponseItem _internalItem; + + public ConversationMessageRole? MessageRole => _internalItem.MessageRole; + + public IReadOnlyList MessageContentParts => _internalItem.MessageContentParts; + + public string FunctionName => _internalItem.FunctionName; + + public string FunctionCallId => _internalItem.FunctionCallId; + + public string FunctionCallArguments => _internalItem.FunctionCallArguments; + + public string FunctionCallOutput => _internalItem.FunctionCallOutput; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseFinishedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseFinishedUpdate.cs new file mode 100644 index 000000000..a37b4cab6 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseFinishedUpdate.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseDoneCommand")] +public partial class ConversationResponseFinishedUpdate +{ + [CodeGenMember("Response")] + internal readonly InternalRealtimeResponse _internalResponse; + + public string Id => _internalResponse?.Id; + public ConversationStatus? Status => _internalResponse?.Status; + + // TODO + internal InternalRealtimeResponseStatusDetails StatusDetails { get; } + + [CodeGenMember("Output")] + public IReadOnlyList CreatedItems => _internalResponse?.Output ?? []; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseStartedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseStartedUpdate.cs new file mode 100644 index 000000000..7fff76078 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationResponseStartedUpdate.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseCreatedCommand")] +public partial class ConversationResponseStartedUpdate +{ + [CodeGenMember("Response")] + internal readonly InternalRealtimeResponse _internalResponse; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionConfiguredUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionConfiguredUpdate.cs new file mode 100644 index 000000000..8ffcfb86c --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionConfiguredUpdate.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseSessionUpdatedCommand")] +public partial class ConversationSessionConfiguredUpdate +{ + [CodeGenMember("Session")] + internal readonly InternalRealtimeResponseSession _internalSession; + + public string SessionId => _internalSession.Id; + + public string Model => _internalSession.Model; + + public ConversationContentModalities ContentModalities + => ConversationContentModalitiesExtensions.FromInternalModalities(_internalSession.Modalities); + + public string Instructions => _internalSession.Instructions; + + public ConversationVoice Voice => _internalSession.Voice; + + public ConversationAudioFormat InputAudioFormat => _internalSession.InputAudioFormat; + public ConversationAudioFormat OutputAudioFormat => _internalSession.OutputAudioFormat; + + public ConversationInputTranscriptionOptions TranscriptionSettings => _internalSession.InputAudioTranscription; + public ConversationTurnDetectionOptions TurnDetectionSettings => _internalSession.TurnDetection; + public IReadOnlyList Tools => _internalSession.Tools; + public ConversationToolChoice ToolChoice => ConversationToolChoice.FromBinaryData(_internalSession.ToolChoice); + public float Temperature => _internalSession.Temperature; + public ConversationMaxTokensChoice MaxOutputTokens => _internalSession.MaxResponseOutputTokens; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionStartedUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionStartedUpdate.cs new file mode 100644 index 000000000..19def6f09 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationSessionStartedUpdate.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseSessionCreatedCommand")] +public partial class ConversationSessionStartedUpdate +{ + [CodeGenMember("Session")] + internal readonly InternalRealtimeResponseSession _internalSession; + + public string SessionId => _internalSession.Id; + + public string Model => _internalSession.Model; + + public ConversationContentModalities ContentModalities + => ConversationContentModalitiesExtensions.FromInternalModalities(_internalSession.Modalities); + + public string Instructions => _internalSession.Instructions; + + public ConversationVoice Voice => _internalSession.Voice; + + public ConversationAudioFormat InputAudioFormat => _internalSession.InputAudioFormat; + public ConversationAudioFormat OutputAudioFormat => _internalSession.OutputAudioFormat; + + public ConversationInputTranscriptionOptions TranscriptionSettings => _internalSession.InputAudioTranscription; + public ConversationTurnDetectionOptions TurnDetectionSettings => _internalSession.TurnDetection; + public IReadOnlyList Tools => _internalSession.Tools; + public ConversationToolChoice ToolChoice => ConversationToolChoice.FromBinaryData(_internalSession.ToolChoice); + public float Temperature => _internalSession.Temperature; + public ConversationMaxTokensChoice MaxOutputTokens => _internalSession.MaxResponseOutputTokens; +} diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdate.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdate.cs new file mode 100644 index 000000000..bd86dc2c2 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdate.cs @@ -0,0 +1,15 @@ +using System; +using System.ClientModel.Primitives; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseCommand")] +public partial class ConversationUpdate +{ + [CodeGenMember("Kind")] + public ConversationUpdateKind Kind { get; internal protected set; } + + public BinaryData GetRawContent() => ModelReaderWriter.Write(this); +} \ No newline at end of file diff --git a/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdateKind.cs b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdateKind.cs new file mode 100644 index 000000000..2ad123160 --- /dev/null +++ b/src/Custom/RealtimeConversation/ResponseUpdates/ConversationUpdateKind.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; + +namespace OpenAI.RealtimeConversation; + +[Experimental("OPENAI002")] +[CodeGenModel("RealtimeResponseCommandType")] +public enum ConversationUpdateKind +{ + /// + /// The session.created response command. + /// + [CodeGenMember("SessionCreated")] + SessionStarted, + /// + /// The session.updated response command. + /// + [CodeGenMember("SessionUpdated")] + SessionConfigured, + [CodeGenMember("ItemCreated")] + ItemAcknowledged, + /// + /// The conversation.item.deleted response command. + /// + [CodeGenMember("ItemDeleted")] + ItemDeleted, + /// + /// The conversation.item.truncated response command. + /// + [CodeGenMember("ItemTruncated")] + ItemTruncated, + /// + /// The response.created response command. + /// + [CodeGenMember("ResponseCreated")] + ResponseStarted, + /// + /// The response.done response command. + /// + [CodeGenMember("ResponseDone")] + ResponseFinished, + [CodeGenMember("RateLimitsUpdated")] + RateLimitsUpdated, + /// + /// The response.output_item.added response command. + /// + [CodeGenMember("ResponseOutputItemAdded")] + ItemStarted, + /// + /// The response.output_item.done response command. + /// + [CodeGenMember("ResponseOutputItemDone")] + ItemFinished, + /// + /// The response.content_part.added response command. + /// + [CodeGenMember("ResponseContentPartAdded")] + ContentPartStarted, + /// + /// The response.content_part.done response command. + /// + [CodeGenMember("ResponseContentPartDone")] + ContentPartFinished, + [CodeGenMember("ResponseAudioDelta")] + ResponseAudioDelta, + [CodeGenMember("ResponseAudioDone")] + ResponseAudioDone, + [CodeGenMember("ResponseAudioTranscriptDelta")] + ResponseAudioTranscriptDelta, + [CodeGenMember("ResponseAudioTranscriptDone")] + ResponseAudioTranscriptDone, + [CodeGenMember("ResponseTextDelta")] + ResponseTextDelta, + [CodeGenMember("ResponseTextDone")] + ResponseTextDone, + [CodeGenMember("ResponseFunctionCallArgumentsDelta")] + ResponseFunctionCallArgumentsDelta, + [CodeGenMember("ResponseFunctionCallArgumentsDone")] + ResponseFunctionCallArgumentsDone, + [CodeGenMember("InputAudioBufferSpeechStarted")] + InputAudioBufferSpeechStarted, + [CodeGenMember("InputAudioBufferSpeechStopped")] + InputAudioBufferSpeechStopped, + [CodeGenMember("ItemInputAudioTranscriptionCompleted")] + ItemInputAudioTranscriptionCompleted, + [CodeGenMember("ItemInputAudioTranscriptionFailed")] + ItemInputAudioTranscriptionFailed, + [CodeGenMember("InputAudioBufferCommitted")] + InputAudioBufferCommitted, + [CodeGenMember("InputAudioBufferCleared")] + InputAudioBufferCleared, + [CodeGenMember("Error")] + Error +} \ No newline at end of file diff --git a/src/Generated/Models/ConversationAudioDeltaUpdate.Serialization.cs b/src/Generated/Models/ConversationAudioDeltaUpdate.Serialization.cs new file mode 100644 index 000000000..e7b135323 --- /dev/null +++ b/src/Generated/Models/ConversationAudioDeltaUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationAudioDeltaUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationAudioDeltaUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("delta") != true) + { + writer.WritePropertyName("delta"u8); + writer.WriteBase64StringValue(Delta.ToArray(), "D"); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationAudioDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationAudioDeltaUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationAudioDeltaUpdate(document.RootElement, options); + } + + internal static ConversationAudioDeltaUpdate DeserializeConversationAudioDeltaUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + BinaryData delta = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("delta"u8)) + { + delta = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationAudioDeltaUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationAudioDeltaUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationAudioDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationAudioDeltaUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationAudioDeltaUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationAudioDeltaUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationAudioDeltaUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationAudioDeltaUpdate.cs b/src/Generated/Models/ConversationAudioDeltaUpdate.cs new file mode 100644 index 000000000..28a01035f --- /dev/null +++ b/src/Generated/Models/ConversationAudioDeltaUpdate.cs @@ -0,0 +1,45 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationAudioDeltaUpdate : ConversationUpdate + { + internal ConversationAudioDeltaUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, BinaryData delta) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(delta, nameof(delta)); + + Kind = ConversationUpdateKind.ResponseAudioDelta; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationAudioDeltaUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, BinaryData delta) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationAudioDeltaUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + public BinaryData Delta { get; } + } +} diff --git a/src/Generated/Models/ConversationAudioDoneUpdate.Serialization.cs b/src/Generated/Models/ConversationAudioDoneUpdate.Serialization.cs new file mode 100644 index 000000000..c3f9dba5a --- /dev/null +++ b/src/Generated/Models/ConversationAudioDoneUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationAudioDoneUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationAudioDoneUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationAudioDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationAudioDoneUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationAudioDoneUpdate(document.RootElement, options); + } + + internal static ConversationAudioDoneUpdate DeserializeConversationAudioDoneUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + ConversationUpdateKind type0 = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type0 = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationAudioDoneUpdate( + type0, + eventId, + serializedAdditionalRawData, + type, + responseId, + itemId, + outputIndex, + contentIndex); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationAudioDoneUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationAudioDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationAudioDoneUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationAudioDoneUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationAudioDoneUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationAudioDoneUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationAudioDoneUpdate.cs b/src/Generated/Models/ConversationAudioDoneUpdate.cs new file mode 100644 index 000000000..b05b2d28f --- /dev/null +++ b/src/Generated/Models/ConversationAudioDoneUpdate.cs @@ -0,0 +1,44 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationAudioDoneUpdate : ConversationUpdate + { + internal ConversationAudioDoneUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.ResponseAudioDone; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + } + + internal ConversationAudioDoneUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string type, string responseId, string itemId, int outputIndex, int contentIndex) : base(kind, eventId, serializedAdditionalRawData) + { + Type = type; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + } + + internal ConversationAudioDoneUpdate() + { + } + + internal string Type { get; set; } = "response.audio.done"; + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationAudioFormat.cs b/src/Generated/Models/ConversationAudioFormat.cs new file mode 100644 index 000000000..0af6d2cbd --- /dev/null +++ b/src/Generated/Models/ConversationAudioFormat.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationAudioFormat : IEquatable + { + private readonly string _value; + + public ConversationAudioFormat(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Pcm16Value = "pcm16"; + private const string G711UlawValue = "g711_ulaw"; + private const string G711AlawValue = "g711_alaw"; + + public static ConversationAudioFormat Pcm16 { get; } = new ConversationAudioFormat(Pcm16Value); + public static ConversationAudioFormat G711Ulaw { get; } = new ConversationAudioFormat(G711UlawValue); + public static ConversationAudioFormat G711Alaw { get; } = new ConversationAudioFormat(G711AlawValue); + public static bool operator ==(ConversationAudioFormat left, ConversationAudioFormat right) => left.Equals(right); + public static bool operator !=(ConversationAudioFormat left, ConversationAudioFormat right) => !left.Equals(right); + public static implicit operator ConversationAudioFormat(string value) => new ConversationAudioFormat(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationAudioFormat other && Equals(other); + public bool Equals(ConversationAudioFormat other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationContentPart.Serialization.cs b/src/Generated/Models/ConversationContentPart.Serialization.cs new file mode 100644 index 000000000..94b9103b2 --- /dev/null +++ b/src/Generated/Models/ConversationContentPart.Serialization.cs @@ -0,0 +1,126 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeContentPart))] + public partial class ConversationContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationContentPart(document.RootElement, options); + } + + internal static ConversationContentPart DeserializeConversationContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "audio": return InternalRealtimeResponseAudioContentPart.DeserializeInternalRealtimeResponseAudioContentPart(element, options); + case "input_audio": return InternalRealtimeRequestAudioContentPart.DeserializeInternalRealtimeRequestAudioContentPart(element, options); + case "input_text": return InternalRealtimeRequestTextContentPart.DeserializeInternalRealtimeRequestTextContentPart(element, options); + case "text": return InternalRealtimeResponseTextContentPart.DeserializeInternalRealtimeResponseTextContentPart(element, options); + } + } + return UnknownRealtimeContentPart.DeserializeUnknownRealtimeContentPart(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support writing '{options.Format}' format."); + } + } + + ConversationContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationContentPart(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationContentPart.cs b/src/Generated/Models/ConversationContentPart.cs new file mode 100644 index 000000000..1ee1dc7ea --- /dev/null +++ b/src/Generated/Models/ConversationContentPart.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public abstract partial class ConversationContentPart + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected ConversationContentPart() + { + } + + internal ConversationContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData) + { + Type = type; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + } +} diff --git a/src/Generated/Models/ConversationContentPartFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationContentPartFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..fec22b678 --- /dev/null +++ b/src/Generated/Models/ConversationContentPartFinishedUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationContentPartFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPartFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("part") != true) + { + writer.WritePropertyName("part"u8); + writer.WriteObjectValue(_internalContentPart, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationContentPartFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPartFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationContentPartFinishedUpdate(document.RootElement, options); + } + + internal static ConversationContentPartFinishedUpdate DeserializeConversationContentPartFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + ConversationContentPart part = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("part"u8)) + { + part = ConversationContentPart.DeserializeConversationContentPart(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationContentPartFinishedUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + part); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationContentPartFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationContentPartFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationContentPartFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationContentPartFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationContentPartFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationContentPartFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationContentPartFinishedUpdate.cs b/src/Generated/Models/ConversationContentPartFinishedUpdate.cs new file mode 100644 index 000000000..56640f237 --- /dev/null +++ b/src/Generated/Models/ConversationContentPartFinishedUpdate.cs @@ -0,0 +1,44 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationContentPartFinishedUpdate : ConversationUpdate + { + internal ConversationContentPartFinishedUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, ConversationContentPart internalContentPart) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(internalContentPart, nameof(internalContentPart)); + + Kind = ConversationUpdateKind.ContentPartFinished; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + _internalContentPart = internalContentPart; + } + + internal ConversationContentPartFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, ConversationContentPart internalContentPart) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + _internalContentPart = internalContentPart; + } + + internal ConversationContentPartFinishedUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationContentPartKind.cs b/src/Generated/Models/ConversationContentPartKind.cs new file mode 100644 index 000000000..a0052ae37 --- /dev/null +++ b/src/Generated/Models/ConversationContentPartKind.cs @@ -0,0 +1,40 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationContentPartKind : IEquatable + { + private readonly string _value; + + public ConversationContentPartKind(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InputTextValue = "input_text"; + private const string InputAudioValue = "input_audio"; + private const string TextValue = "text"; + private const string AudioValue = "audio"; + + public static ConversationContentPartKind InputText { get; } = new ConversationContentPartKind(InputTextValue); + public static ConversationContentPartKind InputAudio { get; } = new ConversationContentPartKind(InputAudioValue); + public static ConversationContentPartKind Text { get; } = new ConversationContentPartKind(TextValue); + public static ConversationContentPartKind Audio { get; } = new ConversationContentPartKind(AudioValue); + public static bool operator ==(ConversationContentPartKind left, ConversationContentPartKind right) => left.Equals(right); + public static bool operator !=(ConversationContentPartKind left, ConversationContentPartKind right) => !left.Equals(right); + public static implicit operator ConversationContentPartKind(string value) => new ConversationContentPartKind(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationContentPartKind other && Equals(other); + public bool Equals(ConversationContentPartKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationContentPartStartedUpdate.Serialization.cs b/src/Generated/Models/ConversationContentPartStartedUpdate.Serialization.cs new file mode 100644 index 000000000..413f4e78a --- /dev/null +++ b/src/Generated/Models/ConversationContentPartStartedUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationContentPartStartedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPartStartedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("part") != true) + { + writer.WritePropertyName("part"u8); + writer.WriteObjectValue(_internalContentPart, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationContentPartStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPartStartedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationContentPartStartedUpdate(document.RootElement, options); + } + + internal static ConversationContentPartStartedUpdate DeserializeConversationContentPartStartedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + ConversationContentPart part = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("part"u8)) + { + part = ConversationContentPart.DeserializeConversationContentPart(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationContentPartStartedUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + part); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationContentPartStartedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationContentPartStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationContentPartStartedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationContentPartStartedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationContentPartStartedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationContentPartStartedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationContentPartStartedUpdate.cs b/src/Generated/Models/ConversationContentPartStartedUpdate.cs new file mode 100644 index 000000000..e72b371ae --- /dev/null +++ b/src/Generated/Models/ConversationContentPartStartedUpdate.cs @@ -0,0 +1,44 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationContentPartStartedUpdate : ConversationUpdate + { + internal ConversationContentPartStartedUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, ConversationContentPart internalContentPart) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(internalContentPart, nameof(internalContentPart)); + + Kind = ConversationUpdateKind.ContentPartStarted; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + _internalContentPart = internalContentPart; + } + + internal ConversationContentPartStartedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, ConversationContentPart internalContentPart) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + _internalContentPart = internalContentPart; + } + + internal ConversationContentPartStartedUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationErrorUpdate.Serialization.cs b/src/Generated/Models/ConversationErrorUpdate.Serialization.cs new file mode 100644 index 000000000..cf0ff1418 --- /dev/null +++ b/src/Generated/Models/ConversationErrorUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationErrorUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationErrorUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("error") != true) + { + writer.WritePropertyName("error"u8); + writer.WriteObjectValue(_error, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationErrorUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationErrorUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationErrorUpdate(document.RootElement, options); + } + + internal static ConversationErrorUpdate DeserializeConversationErrorUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseError error = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("error"u8)) + { + error = InternalRealtimeResponseError.DeserializeInternalRealtimeResponseError(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationErrorUpdate(type, eventId, serializedAdditionalRawData, error); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationErrorUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationErrorUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationErrorUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationErrorUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationErrorUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationErrorUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationErrorUpdate.cs b/src/Generated/Models/ConversationErrorUpdate.cs new file mode 100644 index 000000000..1040232ff --- /dev/null +++ b/src/Generated/Models/ConversationErrorUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationErrorUpdate : ConversationUpdate + { + internal ConversationErrorUpdate(string eventId, InternalRealtimeResponseError error) : base(eventId) + { + Argument.AssertNotNull(error, nameof(error)); + + Kind = ConversationUpdateKind.Error; + _error = error; + } + + internal ConversationErrorUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeResponseError error) : base(kind, eventId, serializedAdditionalRawData) + { + _error = error; + } + + internal ConversationErrorUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.Serialization.cs b/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.Serialization.cs new file mode 100644 index 000000000..23e7058f6 --- /dev/null +++ b/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionCallArgumentsDeltaUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDeltaUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("delta") != true) + { + writer.WritePropertyName("delta"u8); + writer.WriteStringValue(Delta); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationFunctionCallArgumentsDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDeltaUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationFunctionCallArgumentsDeltaUpdate(document.RootElement, options); + } + + internal static ConversationFunctionCallArgumentsDeltaUpdate DeserializeConversationFunctionCallArgumentsDeltaUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + string callId = default; + string delta = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("delta"u8)) + { + delta = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationFunctionCallArgumentsDeltaUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + callId, + delta); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDeltaUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationFunctionCallArgumentsDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationFunctionCallArgumentsDeltaUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDeltaUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationFunctionCallArgumentsDeltaUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationFunctionCallArgumentsDeltaUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.cs b/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.cs new file mode 100644 index 000000000..b3e1fa0a6 --- /dev/null +++ b/src/Generated/Models/ConversationFunctionCallArgumentsDeltaUpdate.cs @@ -0,0 +1,46 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionCallArgumentsDeltaUpdate : ConversationUpdate + { + internal ConversationFunctionCallArgumentsDeltaUpdate(string eventId, string responseId, string itemId, int outputIndex, string callId, string delta) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(delta, nameof(delta)); + + Kind = ConversationUpdateKind.ResponseFunctionCallArgumentsDelta; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + CallId = callId; + Delta = delta; + } + + internal ConversationFunctionCallArgumentsDeltaUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, string callId, string delta) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + CallId = callId; + Delta = delta; + } + + internal ConversationFunctionCallArgumentsDeltaUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string CallId { get; } + public string Delta { get; } + } +} diff --git a/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.Serialization.cs b/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.Serialization.cs new file mode 100644 index 000000000..2c9da9915 --- /dev/null +++ b/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.Serialization.cs @@ -0,0 +1,231 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionCallArgumentsDoneUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDoneUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData?.ContainsKey("arguments") != true) + { + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationFunctionCallArgumentsDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDoneUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationFunctionCallArgumentsDoneUpdate(document.RootElement, options); + } + + internal static ConversationFunctionCallArgumentsDoneUpdate DeserializeConversationFunctionCallArgumentsDoneUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + string callId = default; + string name = default; + string arguments = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationFunctionCallArgumentsDoneUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + callId, + name, + arguments); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDoneUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationFunctionCallArgumentsDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationFunctionCallArgumentsDoneUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationFunctionCallArgumentsDoneUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationFunctionCallArgumentsDoneUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationFunctionCallArgumentsDoneUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.cs b/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.cs new file mode 100644 index 000000000..ba4684c6f --- /dev/null +++ b/src/Generated/Models/ConversationFunctionCallArgumentsDoneUpdate.cs @@ -0,0 +1,50 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionCallArgumentsDoneUpdate : ConversationUpdate + { + internal ConversationFunctionCallArgumentsDoneUpdate(string eventId, string responseId, string itemId, int outputIndex, string callId, string name, string arguments) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(arguments, nameof(arguments)); + + Kind = ConversationUpdateKind.ResponseFunctionCallArgumentsDone; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + CallId = callId; + Name = name; + Arguments = arguments; + } + + internal ConversationFunctionCallArgumentsDoneUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, string callId, string name, string arguments) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + CallId = callId; + Name = name; + Arguments = arguments; + } + + internal ConversationFunctionCallArgumentsDoneUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public string CallId { get; } + public string Name { get; } + public string Arguments { get; } + } +} diff --git a/src/Generated/Models/ConversationFunctionTool.Serialization.cs b/src/Generated/Models/ConversationFunctionTool.Serialization.cs new file mode 100644 index 000000000..8f7408123 --- /dev/null +++ b/src/Generated/Models/ConversationFunctionTool.Serialization.cs @@ -0,0 +1,177 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionTool : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionTool)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(_name); + } + if (SerializedAdditionalRawData?.ContainsKey("description") != true && Optional.IsDefined(_description)) + { + writer.WritePropertyName("description"u8); + writer.WriteStringValue(_description); + } + if (SerializedAdditionalRawData?.ContainsKey("parameters") != true && Optional.IsDefined(_parameters)) + { + writer.WritePropertyName("parameters"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(_parameters); +#else + using (JsonDocument document = JsonDocument.Parse(_parameters)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationFunctionTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationFunctionTool)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationFunctionTool(document.RootElement, options); + } + + internal static ConversationFunctionTool DeserializeConversationFunctionTool(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string description = default; + BinaryData parameters = default; + ConversationToolKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("description"u8)) + { + description = property.Value.GetString(); + continue; + } + if (property.NameEquals("parameters"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + parameters = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationToolKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationFunctionTool(type, serializedAdditionalRawData, name, description, parameters); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationFunctionTool)} does not support writing '{options.Format}' format."); + } + } + + ConversationFunctionTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationFunctionTool(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationFunctionTool)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationFunctionTool FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationFunctionTool(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationFunctionTool.cs b/src/Generated/Models/ConversationFunctionTool.cs new file mode 100644 index 000000000..e8fd7186c --- /dev/null +++ b/src/Generated/Models/ConversationFunctionTool.cs @@ -0,0 +1,13 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationFunctionTool : ConversationTool + { + } +} diff --git a/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.Serialization.cs new file mode 100644 index 000000000..94d7c421c --- /dev/null +++ b/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.Serialization.cs @@ -0,0 +1,156 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputAudioBufferClearedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputAudioBufferClearedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputAudioBufferClearedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputAudioBufferClearedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputAudioBufferClearedUpdate(document.RootElement, options); + } + + internal static ConversationInputAudioBufferClearedUpdate DeserializeConversationInputAudioBufferClearedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputAudioBufferClearedUpdate(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputAudioBufferClearedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputAudioBufferClearedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputAudioBufferClearedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputAudioBufferClearedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputAudioBufferClearedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputAudioBufferClearedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.cs b/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.cs new file mode 100644 index 000000000..f185bbba7 --- /dev/null +++ b/src/Generated/Models/ConversationInputAudioBufferClearedUpdate.cs @@ -0,0 +1,25 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputAudioBufferClearedUpdate : ConversationUpdate + { + internal ConversationInputAudioBufferClearedUpdate(string eventId) : base(eventId) + { + Kind = ConversationUpdateKind.InputAudioBufferCleared; + } + + internal ConversationInputAudioBufferClearedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + + internal ConversationInputAudioBufferClearedUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.Serialization.cs new file mode 100644 index 000000000..591b40f5c --- /dev/null +++ b/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.Serialization.cs @@ -0,0 +1,178 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputAudioBufferCommittedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputAudioBufferCommittedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("previous_item_id") != true && Optional.IsDefined(PreviousItemId)) + { + writer.WritePropertyName("previous_item_id"u8); + writer.WriteStringValue(PreviousItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputAudioBufferCommittedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputAudioBufferCommittedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputAudioBufferCommittedUpdate(document.RootElement, options); + } + + internal static ConversationInputAudioBufferCommittedUpdate DeserializeConversationInputAudioBufferCommittedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + string previousItemId = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("previous_item_id"u8)) + { + previousItemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputAudioBufferCommittedUpdate(type, eventId, serializedAdditionalRawData, itemId, previousItemId); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputAudioBufferCommittedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputAudioBufferCommittedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputAudioBufferCommittedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputAudioBufferCommittedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputAudioBufferCommittedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputAudioBufferCommittedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.cs b/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.cs new file mode 100644 index 000000000..255ee74e2 --- /dev/null +++ b/src/Generated/Models/ConversationInputAudioBufferCommittedUpdate.cs @@ -0,0 +1,33 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputAudioBufferCommittedUpdate : ConversationUpdate + { + internal ConversationInputAudioBufferCommittedUpdate(string eventId, string itemId) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.InputAudioBufferCommitted; + ItemId = itemId; + } + + internal ConversationInputAudioBufferCommittedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string itemId, string previousItemId) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + PreviousItemId = previousItemId; + } + + internal ConversationInputAudioBufferCommittedUpdate() + { + } + + public string ItemId { get; } + public string PreviousItemId { get; } + } +} diff --git a/src/Generated/Models/ConversationInputSpeechFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputSpeechFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..17563841e --- /dev/null +++ b/src/Generated/Models/ConversationInputSpeechFinishedUpdate.Serialization.cs @@ -0,0 +1,178 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputSpeechFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputSpeechFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("audio_end_ms") != true) + { + writer.WritePropertyName("audio_end_ms"u8); + writer.WriteNumberValue(AudioEndMs); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputSpeechFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputSpeechFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputSpeechFinishedUpdate(document.RootElement, options); + } + + internal static ConversationInputSpeechFinishedUpdate DeserializeConversationInputSpeechFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int audioEndMs = default; + string itemId = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("audio_end_ms"u8)) + { + audioEndMs = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputSpeechFinishedUpdate(type, eventId, serializedAdditionalRawData, audioEndMs, itemId); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputSpeechFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputSpeechFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputSpeechFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputSpeechFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputSpeechFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputSpeechFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputSpeechFinishedUpdate.cs b/src/Generated/Models/ConversationInputSpeechFinishedUpdate.cs new file mode 100644 index 000000000..890260322 --- /dev/null +++ b/src/Generated/Models/ConversationInputSpeechFinishedUpdate.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputSpeechFinishedUpdate : ConversationUpdate + { + internal ConversationInputSpeechFinishedUpdate(string eventId, int audioEndMs, string itemId) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.InputAudioBufferSpeechStopped; + AudioEndMs = audioEndMs; + ItemId = itemId; + } + + internal ConversationInputSpeechFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, int audioEndMs, string itemId) : base(kind, eventId, serializedAdditionalRawData) + { + AudioEndMs = audioEndMs; + ItemId = itemId; + } + + internal ConversationInputSpeechFinishedUpdate() + { + } + + public int AudioEndMs { get; } + public string ItemId { get; } + } +} diff --git a/src/Generated/Models/ConversationInputSpeechStartedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputSpeechStartedUpdate.Serialization.cs new file mode 100644 index 000000000..14fe6656e --- /dev/null +++ b/src/Generated/Models/ConversationInputSpeechStartedUpdate.Serialization.cs @@ -0,0 +1,178 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputSpeechStartedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputSpeechStartedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("audio_start_ms") != true) + { + writer.WritePropertyName("audio_start_ms"u8); + writer.WriteNumberValue(AudioStartMs); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputSpeechStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputSpeechStartedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputSpeechStartedUpdate(document.RootElement, options); + } + + internal static ConversationInputSpeechStartedUpdate DeserializeConversationInputSpeechStartedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int audioStartMs = default; + string itemId = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("audio_start_ms"u8)) + { + audioStartMs = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputSpeechStartedUpdate(type, eventId, serializedAdditionalRawData, audioStartMs, itemId); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputSpeechStartedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputSpeechStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputSpeechStartedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputSpeechStartedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputSpeechStartedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputSpeechStartedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputSpeechStartedUpdate.cs b/src/Generated/Models/ConversationInputSpeechStartedUpdate.cs new file mode 100644 index 000000000..8cf4492f3 --- /dev/null +++ b/src/Generated/Models/ConversationInputSpeechStartedUpdate.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputSpeechStartedUpdate : ConversationUpdate + { + internal ConversationInputSpeechStartedUpdate(string eventId, int audioStartMs, string itemId) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.InputAudioBufferSpeechStarted; + AudioStartMs = audioStartMs; + ItemId = itemId; + } + + internal ConversationInputSpeechStartedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, int audioStartMs, string itemId) : base(kind, eventId, serializedAdditionalRawData) + { + AudioStartMs = audioStartMs; + ItemId = itemId; + } + + internal ConversationInputSpeechStartedUpdate() + { + } + + public int AudioStartMs { get; } + public string ItemId { get; } + } +} diff --git a/src/Generated/Models/ConversationInputTokenUsageDetails.Serialization.cs b/src/Generated/Models/ConversationInputTokenUsageDetails.Serialization.cs new file mode 100644 index 000000000..f4a29a5b6 --- /dev/null +++ b/src/Generated/Models/ConversationInputTokenUsageDetails.Serialization.cs @@ -0,0 +1,155 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTokenUsageDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTokenUsageDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("cached_tokens") != true) + { + writer.WritePropertyName("cached_tokens"u8); + writer.WriteNumberValue(CachedTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("text_tokens") != true) + { + writer.WritePropertyName("text_tokens"u8); + writer.WriteNumberValue(TextTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("audio_tokens") != true) + { + writer.WritePropertyName("audio_tokens"u8); + writer.WriteNumberValue(AudioTokens); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputTokenUsageDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTokenUsageDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputTokenUsageDetails(document.RootElement, options); + } + + internal static ConversationInputTokenUsageDetails DeserializeConversationInputTokenUsageDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int cachedTokens = default; + int textTokens = default; + int audioTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("cached_tokens"u8)) + { + cachedTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("text_tokens"u8)) + { + textTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("audio_tokens"u8)) + { + audioTokens = property.Value.GetInt32(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputTokenUsageDetails(cachedTokens, textTokens, audioTokens, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputTokenUsageDetails)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputTokenUsageDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputTokenUsageDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputTokenUsageDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationInputTokenUsageDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputTokenUsageDetails(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputTokenUsageDetails.cs b/src/Generated/Models/ConversationInputTokenUsageDetails.cs new file mode 100644 index 000000000..72bee755f --- /dev/null +++ b/src/Generated/Models/ConversationInputTokenUsageDetails.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTokenUsageDetails + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal ConversationInputTokenUsageDetails(int cachedTokens, int textTokens, int audioTokens) + { + CachedTokens = cachedTokens; + TextTokens = textTokens; + AudioTokens = audioTokens; + } + + internal ConversationInputTokenUsageDetails(int cachedTokens, int textTokens, int audioTokens, IDictionary serializedAdditionalRawData) + { + CachedTokens = cachedTokens; + TextTokens = textTokens; + AudioTokens = audioTokens; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationInputTokenUsageDetails() + { + } + + public int CachedTokens { get; } + public int TextTokens { get; } + public int AudioTokens { get; } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.Serialization.cs new file mode 100644 index 000000000..d9d89b35b --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionFailedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFailedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("error") != true) + { + writer.WritePropertyName("error"u8); + writer.WriteObjectValue(_error, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputTranscriptionFailedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFailedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputTranscriptionFailedUpdate(document.RootElement, options); + } + + internal static ConversationInputTranscriptionFailedUpdate DeserializeConversationInputTranscriptionFailedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + int contentIndex = default; + InternalRealtimeResponseApiError error = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("error"u8)) + { + error = InternalRealtimeResponseApiError.DeserializeInternalRealtimeResponseApiError(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputTranscriptionFailedUpdate( + type, + eventId, + serializedAdditionalRawData, + itemId, + contentIndex, + error); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFailedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputTranscriptionFailedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputTranscriptionFailedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFailedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputTranscriptionFailedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputTranscriptionFailedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.cs b/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.cs new file mode 100644 index 000000000..824472383 --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionFailedUpdate.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionFailedUpdate : ConversationUpdate + { + internal ConversationInputTranscriptionFailedUpdate(string eventId, string itemId, int contentIndex, InternalRealtimeResponseApiError error) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(error, nameof(error)); + + Kind = ConversationUpdateKind.ItemInputAudioTranscriptionFailed; + ItemId = itemId; + ContentIndex = contentIndex; + _error = error; + } + + internal ConversationInputTranscriptionFailedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string itemId, int contentIndex, InternalRealtimeResponseApiError error) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + ContentIndex = contentIndex; + _error = error; + } + + internal ConversationInputTranscriptionFailedUpdate() + { + } + + public string ItemId { get; } + public int ContentIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..4a6c1ea65 --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("transcript") != true) + { + writer.WritePropertyName("transcript"u8); + writer.WriteStringValue(Transcript); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputTranscriptionFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputTranscriptionFinishedUpdate(document.RootElement, options); + } + + internal static ConversationInputTranscriptionFinishedUpdate DeserializeConversationInputTranscriptionFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + int contentIndex = default; + string transcript = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("transcript"u8)) + { + transcript = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputTranscriptionFinishedUpdate( + type, + eventId, + serializedAdditionalRawData, + itemId, + contentIndex, + transcript); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputTranscriptionFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputTranscriptionFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationInputTranscriptionFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputTranscriptionFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.cs b/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.cs new file mode 100644 index 000000000..0960c8032 --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionFinishedUpdate.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionFinishedUpdate : ConversationUpdate + { + internal ConversationInputTranscriptionFinishedUpdate(string eventId, string itemId, int contentIndex, string transcript) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(transcript, nameof(transcript)); + + Kind = ConversationUpdateKind.ItemInputAudioTranscriptionCompleted; + ItemId = itemId; + ContentIndex = contentIndex; + Transcript = transcript; + } + + internal ConversationInputTranscriptionFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string itemId, int contentIndex, string transcript) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + ContentIndex = contentIndex; + Transcript = transcript; + } + + internal ConversationInputTranscriptionFinishedUpdate() + { + } + + public string ItemId { get; } + public int ContentIndex { get; } + public string Transcript { get; } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionOptions.Serialization.cs b/src/Generated/Models/ConversationInputTranscriptionOptions.Serialization.cs new file mode 100644 index 000000000..d16f29d9d --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionOptions.Serialization.cs @@ -0,0 +1,137 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionOptions : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionOptions)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("model") != true && Optional.IsDefined(Model)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model.Value.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationInputTranscriptionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationInputTranscriptionOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationInputTranscriptionOptions(document.RootElement, options); + } + + internal static ConversationInputTranscriptionOptions DeserializeConversationInputTranscriptionOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationTranscriptionModel? model = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("model"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + model = new ConversationTranscriptionModel(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationInputTranscriptionOptions(model, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionOptions)} does not support writing '{options.Format}' format."); + } + } + + ConversationInputTranscriptionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationInputTranscriptionOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationInputTranscriptionOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationInputTranscriptionOptions FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationInputTranscriptionOptions(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationInputTranscriptionOptions.cs b/src/Generated/Models/ConversationInputTranscriptionOptions.cs new file mode 100644 index 000000000..33797601d --- /dev/null +++ b/src/Generated/Models/ConversationInputTranscriptionOptions.cs @@ -0,0 +1,25 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationInputTranscriptionOptions + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public ConversationInputTranscriptionOptions() + { + } + + internal ConversationInputTranscriptionOptions(ConversationTranscriptionModel? model, IDictionary serializedAdditionalRawData) + { + Model = model; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + public ConversationTranscriptionModel? Model { get; set; } + } +} diff --git a/src/Generated/Models/ConversationItem.Serialization.cs b/src/Generated/Models/ConversationItem.Serialization.cs new file mode 100644 index 000000000..91a947606 --- /dev/null +++ b/src/Generated/Models/ConversationItem.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeRequestItem))] + public partial class ConversationItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItem(document.RootElement, options); + } + + internal static ConversationItem DeserializeConversationItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "assistant": return InternalRealtimeRequestAssistantMessageItem.DeserializeInternalRealtimeRequestAssistantMessageItem(element, options); + case "function_call": return InternalRealtimeRequestFunctionCallItem.DeserializeInternalRealtimeRequestFunctionCallItem(element, options); + case "function_call_output": return InternalRealtimeRequestFunctionCallOutputItem.DeserializeInternalRealtimeRequestFunctionCallOutputItem(element, options); + case "message": return InternalRealtimeRequestMessageItem.DeserializeInternalRealtimeRequestMessageItem(element, options); + case "system": return InternalRealtimeRequestSystemMessageItem.DeserializeInternalRealtimeRequestSystemMessageItem(element, options); + case "user": return InternalRealtimeRequestUserMessageItem.DeserializeInternalRealtimeRequestUserMessageItem(element, options); + } + } + return UnknownRealtimeRequestItem.DeserializeUnknownRealtimeRequestItem(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItem)} does not support writing '{options.Format}' format."); + } + } + + ConversationItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItem(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItem.cs b/src/Generated/Models/ConversationItem.cs new file mode 100644 index 000000000..dd157049a --- /dev/null +++ b/src/Generated/Models/ConversationItem.cs @@ -0,0 +1,27 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public abstract partial class ConversationItem + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected ConversationItem() + { + } + + internal ConversationItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData) + { + Type = type; + Id = id; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeRequestItemType Type { get; set; } + public string Id { get; set; } + } +} diff --git a/src/Generated/Models/ConversationItemAcknowledgedUpdate.Serialization.cs b/src/Generated/Models/ConversationItemAcknowledgedUpdate.Serialization.cs new file mode 100644 index 000000000..4cbe4f2d4 --- /dev/null +++ b/src/Generated/Models/ConversationItemAcknowledgedUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemAcknowledgedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemAcknowledgedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item") != true) + { + writer.WritePropertyName("item"u8); + writer.WriteObjectValue(Item, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItemAcknowledgedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemAcknowledgedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItemAcknowledgedUpdate(document.RootElement, options); + } + + internal static ConversationItemAcknowledgedUpdate DeserializeConversationItemAcknowledgedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationItem item = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item"u8)) + { + item = ConversationItem.DeserializeConversationItem(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationItemAcknowledgedUpdate(type, eventId, serializedAdditionalRawData, item); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItemAcknowledgedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationItemAcknowledgedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItemAcknowledgedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItemAcknowledgedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationItemAcknowledgedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItemAcknowledgedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItemAcknowledgedUpdate.cs b/src/Generated/Models/ConversationItemAcknowledgedUpdate.cs new file mode 100644 index 000000000..64894df82 --- /dev/null +++ b/src/Generated/Models/ConversationItemAcknowledgedUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemAcknowledgedUpdate : ConversationUpdate + { + internal ConversationItemAcknowledgedUpdate(string eventId, ConversationItem item) : base(eventId) + { + Argument.AssertNotNull(item, nameof(item)); + + Kind = ConversationUpdateKind.ItemAcknowledged; + Item = item; + } + + internal ConversationItemAcknowledgedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, ConversationItem item) : base(kind, eventId, serializedAdditionalRawData) + { + Item = item; + } + + internal ConversationItemAcknowledgedUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationItemDeletedUpdate.Serialization.cs b/src/Generated/Models/ConversationItemDeletedUpdate.Serialization.cs new file mode 100644 index 000000000..671ea9883 --- /dev/null +++ b/src/Generated/Models/ConversationItemDeletedUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemDeletedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemDeletedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItemDeletedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemDeletedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItemDeletedUpdate(document.RootElement, options); + } + + internal static ConversationItemDeletedUpdate DeserializeConversationItemDeletedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationItemDeletedUpdate(type, eventId, serializedAdditionalRawData, itemId); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItemDeletedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationItemDeletedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItemDeletedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItemDeletedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationItemDeletedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItemDeletedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItemDeletedUpdate.cs b/src/Generated/Models/ConversationItemDeletedUpdate.cs new file mode 100644 index 000000000..e178d7fee --- /dev/null +++ b/src/Generated/Models/ConversationItemDeletedUpdate.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemDeletedUpdate : ConversationUpdate + { + internal ConversationItemDeletedUpdate(string eventId, string itemId) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.ItemDeleted; + ItemId = itemId; + } + + internal ConversationItemDeletedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string itemId) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + } + + internal ConversationItemDeletedUpdate() + { + } + + public string ItemId { get; } + } +} diff --git a/src/Generated/Models/ConversationItemFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationItemFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..3000ba990 --- /dev/null +++ b/src/Generated/Models/ConversationItemFinishedUpdate.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("item") != true) + { + writer.WritePropertyName("item"u8); + writer.WriteObjectValue(_internalItem, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItemFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItemFinishedUpdate(document.RootElement, options); + } + + internal static ConversationItemFinishedUpdate DeserializeConversationItemFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + int outputIndex = default; + InternalRealtimeResponseItem item = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("item"u8)) + { + item = InternalRealtimeResponseItem.DeserializeInternalRealtimeResponseItem(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationItemFinishedUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + outputIndex, + item); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItemFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationItemFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItemFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItemFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationItemFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItemFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItemFinishedUpdate.cs b/src/Generated/Models/ConversationItemFinishedUpdate.cs new file mode 100644 index 000000000..009eb2e40 --- /dev/null +++ b/src/Generated/Models/ConversationItemFinishedUpdate.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemFinishedUpdate : ConversationUpdate + { + internal ConversationItemFinishedUpdate(string eventId, string responseId, int outputIndex, InternalRealtimeResponseItem internalItem) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(internalItem, nameof(internalItem)); + + Kind = ConversationUpdateKind.ItemFinished; + ResponseId = responseId; + OutputIndex = outputIndex; + _internalItem = internalItem; + } + + internal ConversationItemFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, int outputIndex, InternalRealtimeResponseItem internalItem) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + OutputIndex = outputIndex; + _internalItem = internalItem; + } + + internal ConversationItemFinishedUpdate() + { + } + + public string ResponseId { get; } + public int OutputIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationItemStartedUpdate.Serialization.cs b/src/Generated/Models/ConversationItemStartedUpdate.Serialization.cs new file mode 100644 index 000000000..c4495f964 --- /dev/null +++ b/src/Generated/Models/ConversationItemStartedUpdate.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemStartedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemStartedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("item") != true) + { + writer.WritePropertyName("item"u8); + writer.WriteObjectValue(_internalItem, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItemStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemStartedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItemStartedUpdate(document.RootElement, options); + } + + internal static ConversationItemStartedUpdate DeserializeConversationItemStartedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + int outputIndex = default; + InternalRealtimeResponseItem item = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("item"u8)) + { + item = InternalRealtimeResponseItem.DeserializeInternalRealtimeResponseItem(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationItemStartedUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + outputIndex, + item); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItemStartedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationItemStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItemStartedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItemStartedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationItemStartedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItemStartedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItemStartedUpdate.cs b/src/Generated/Models/ConversationItemStartedUpdate.cs new file mode 100644 index 000000000..7c28d6671 --- /dev/null +++ b/src/Generated/Models/ConversationItemStartedUpdate.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemStartedUpdate : ConversationUpdate + { + internal ConversationItemStartedUpdate(string eventId, string responseId, int outputIndex, InternalRealtimeResponseItem internalItem) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(internalItem, nameof(internalItem)); + + Kind = ConversationUpdateKind.ItemStarted; + ResponseId = responseId; + OutputIndex = outputIndex; + _internalItem = internalItem; + } + + internal ConversationItemStartedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, int outputIndex, InternalRealtimeResponseItem internalItem) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + OutputIndex = outputIndex; + _internalItem = internalItem; + } + + internal ConversationItemStartedUpdate() + { + } + + public string ResponseId { get; } + public int OutputIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationItemStatus.cs b/src/Generated/Models/ConversationItemStatus.cs new file mode 100644 index 000000000..c99155d0b --- /dev/null +++ b/src/Generated/Models/ConversationItemStatus.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationItemStatus : IEquatable + { + private readonly string _value; + + public ConversationItemStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + private const string IncompleteValue = "incomplete"; + + public static ConversationItemStatus InProgress { get; } = new ConversationItemStatus(InProgressValue); + public static ConversationItemStatus Completed { get; } = new ConversationItemStatus(CompletedValue); + public static ConversationItemStatus Incomplete { get; } = new ConversationItemStatus(IncompleteValue); + public static bool operator ==(ConversationItemStatus left, ConversationItemStatus right) => left.Equals(right); + public static bool operator !=(ConversationItemStatus left, ConversationItemStatus right) => !left.Equals(right); + public static implicit operator ConversationItemStatus(string value) => new ConversationItemStatus(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationItemStatus other && Equals(other); + public bool Equals(ConversationItemStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationItemTruncatedUpdate.Serialization.cs b/src/Generated/Models/ConversationItemTruncatedUpdate.Serialization.cs new file mode 100644 index 000000000..8836e7489 --- /dev/null +++ b/src/Generated/Models/ConversationItemTruncatedUpdate.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemTruncatedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemTruncatedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("audio_end_ms") != true) + { + writer.WritePropertyName("audio_end_ms"u8); + writer.WriteNumberValue(AudioEndMs); + } + if (SerializedAdditionalRawData?.ContainsKey("index") != true) + { + writer.WritePropertyName("index"u8); + writer.WriteNumberValue(Index); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItemTruncatedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItemTruncatedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItemTruncatedUpdate(document.RootElement, options); + } + + internal static ConversationItemTruncatedUpdate DeserializeConversationItemTruncatedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + int audioEndMs = default; + int index = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("audio_end_ms"u8)) + { + audioEndMs = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("index"u8)) + { + index = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationItemTruncatedUpdate( + type, + eventId, + serializedAdditionalRawData, + itemId, + audioEndMs, + index); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItemTruncatedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationItemTruncatedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItemTruncatedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItemTruncatedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationItemTruncatedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationItemTruncatedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationItemTruncatedUpdate.cs b/src/Generated/Models/ConversationItemTruncatedUpdate.cs new file mode 100644 index 000000000..2f24d6834 --- /dev/null +++ b/src/Generated/Models/ConversationItemTruncatedUpdate.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationItemTruncatedUpdate : ConversationUpdate + { + internal ConversationItemTruncatedUpdate(string eventId, string itemId, int audioEndMs, int index) : base(eventId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.ItemTruncated; + ItemId = itemId; + AudioEndMs = audioEndMs; + Index = index; + } + + internal ConversationItemTruncatedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string itemId, int audioEndMs, int index) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + AudioEndMs = audioEndMs; + Index = index; + } + + internal ConversationItemTruncatedUpdate() + { + } + + public string ItemId { get; } + public int AudioEndMs { get; } + public int Index { get; } + } +} diff --git a/src/Generated/Models/ConversationMessageRole.cs b/src/Generated/Models/ConversationMessageRole.cs new file mode 100644 index 000000000..b5cd90fd4 --- /dev/null +++ b/src/Generated/Models/ConversationMessageRole.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationMessageRole : IEquatable + { + private readonly string _value; + + public ConversationMessageRole(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SystemValue = "system"; + private const string UserValue = "user"; + private const string AssistantValue = "assistant"; + + public static ConversationMessageRole System { get; } = new ConversationMessageRole(SystemValue); + public static ConversationMessageRole User { get; } = new ConversationMessageRole(UserValue); + public static ConversationMessageRole Assistant { get; } = new ConversationMessageRole(AssistantValue); + public static bool operator ==(ConversationMessageRole left, ConversationMessageRole right) => left.Equals(right); + public static bool operator !=(ConversationMessageRole left, ConversationMessageRole right) => !left.Equals(right); + public static implicit operator ConversationMessageRole(string value) => new ConversationMessageRole(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationMessageRole other && Equals(other); + public bool Equals(ConversationMessageRole other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationOutputTokenUsageDetails.Serialization.cs b/src/Generated/Models/ConversationOutputTokenUsageDetails.Serialization.cs new file mode 100644 index 000000000..7aa592b03 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTokenUsageDetails.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTokenUsageDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTokenUsageDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("text_tokens") != true) + { + writer.WritePropertyName("text_tokens"u8); + writer.WriteNumberValue(TextTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("audio_tokens") != true) + { + writer.WritePropertyName("audio_tokens"u8); + writer.WriteNumberValue(AudioTokens); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationOutputTokenUsageDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTokenUsageDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationOutputTokenUsageDetails(document.RootElement, options); + } + + internal static ConversationOutputTokenUsageDetails DeserializeConversationOutputTokenUsageDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int textTokens = default; + int audioTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text_tokens"u8)) + { + textTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("audio_tokens"u8)) + { + audioTokens = property.Value.GetInt32(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationOutputTokenUsageDetails(textTokens, audioTokens, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationOutputTokenUsageDetails)} does not support writing '{options.Format}' format."); + } + } + + ConversationOutputTokenUsageDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationOutputTokenUsageDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationOutputTokenUsageDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationOutputTokenUsageDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationOutputTokenUsageDetails(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationOutputTokenUsageDetails.cs b/src/Generated/Models/ConversationOutputTokenUsageDetails.cs new file mode 100644 index 000000000..e6c4b4172 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTokenUsageDetails.cs @@ -0,0 +1,33 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTokenUsageDetails + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal ConversationOutputTokenUsageDetails(int textTokens, int audioTokens) + { + TextTokens = textTokens; + AudioTokens = audioTokens; + } + + internal ConversationOutputTokenUsageDetails(int textTokens, int audioTokens, IDictionary serializedAdditionalRawData) + { + TextTokens = textTokens; + AudioTokens = audioTokens; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationOutputTokenUsageDetails() + { + } + + public int TextTokens { get; } + public int AudioTokens { get; } + } +} diff --git a/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.Serialization.cs b/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.Serialization.cs new file mode 100644 index 000000000..e8bc14ac3 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTranscriptionDeltaUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionDeltaUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("delta") != true) + { + writer.WritePropertyName("delta"u8); + writer.WriteStringValue(Delta); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationOutputTranscriptionDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionDeltaUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationOutputTranscriptionDeltaUpdate(document.RootElement, options); + } + + internal static ConversationOutputTranscriptionDeltaUpdate DeserializeConversationOutputTranscriptionDeltaUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + string delta = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("delta"u8)) + { + delta = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationOutputTranscriptionDeltaUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionDeltaUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationOutputTranscriptionDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationOutputTranscriptionDeltaUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionDeltaUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationOutputTranscriptionDeltaUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationOutputTranscriptionDeltaUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.cs b/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.cs new file mode 100644 index 000000000..56ed591c4 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTranscriptionDeltaUpdate.cs @@ -0,0 +1,45 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTranscriptionDeltaUpdate : ConversationUpdate + { + internal ConversationOutputTranscriptionDeltaUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, string delta) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(delta, nameof(delta)); + + Kind = ConversationUpdateKind.ResponseAudioTranscriptDelta; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationOutputTranscriptionDeltaUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, string delta) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationOutputTranscriptionDeltaUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + public string Delta { get; } + } +} diff --git a/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..b94744341 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.Serialization.cs @@ -0,0 +1,207 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTranscriptionFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationOutputTranscriptionFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationOutputTranscriptionFinishedUpdate(document.RootElement, options); + } + + internal static ConversationOutputTranscriptionFinishedUpdate DeserializeConversationOutputTranscriptionFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationOutputTranscriptionFinishedUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationOutputTranscriptionFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationOutputTranscriptionFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationOutputTranscriptionFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationOutputTranscriptionFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationOutputTranscriptionFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.cs b/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.cs new file mode 100644 index 000000000..066dc2f39 --- /dev/null +++ b/src/Generated/Models/ConversationOutputTranscriptionFinishedUpdate.cs @@ -0,0 +1,41 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationOutputTranscriptionFinishedUpdate : ConversationUpdate + { + internal ConversationOutputTranscriptionFinishedUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = ConversationUpdateKind.ResponseAudioTranscriptDone; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + } + + internal ConversationOutputTranscriptionFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + } + + internal ConversationOutputTranscriptionFinishedUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + } +} diff --git a/src/Generated/Models/ConversationRateLimitDetailsItem.Serialization.cs b/src/Generated/Models/ConversationRateLimitDetailsItem.Serialization.cs new file mode 100644 index 000000000..83d8e6d67 --- /dev/null +++ b/src/Generated/Models/ConversationRateLimitDetailsItem.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationRateLimitDetailsItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationRateLimitDetailsItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData?.ContainsKey("limit") != true) + { + writer.WritePropertyName("limit"u8); + writer.WriteNumberValue(Limit); + } + if (SerializedAdditionalRawData?.ContainsKey("remaining") != true) + { + writer.WritePropertyName("remaining"u8); + writer.WriteNumberValue(Remaining); + } + if (SerializedAdditionalRawData?.ContainsKey("reset_seconds") != true) + { + writer.WritePropertyName("reset_seconds"u8); + writer.WriteNumberValue(ResetSeconds); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationRateLimitDetailsItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationRateLimitDetailsItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationRateLimitDetailsItem(document.RootElement, options); + } + + internal static ConversationRateLimitDetailsItem DeserializeConversationRateLimitDetailsItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + int limit = default; + int remaining = default; + float resetSeconds = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("limit"u8)) + { + limit = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("remaining"u8)) + { + remaining = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("reset_seconds"u8)) + { + resetSeconds = property.Value.GetSingle(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationRateLimitDetailsItem(name, limit, remaining, resetSeconds, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationRateLimitDetailsItem)} does not support writing '{options.Format}' format."); + } + } + + ConversationRateLimitDetailsItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationRateLimitDetailsItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationRateLimitDetailsItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationRateLimitDetailsItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationRateLimitDetailsItem(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationRateLimitDetailsItem.cs b/src/Generated/Models/ConversationRateLimitDetailsItem.cs new file mode 100644 index 000000000..f3f4235b4 --- /dev/null +++ b/src/Generated/Models/ConversationRateLimitDetailsItem.cs @@ -0,0 +1,41 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationRateLimitDetailsItem + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal ConversationRateLimitDetailsItem(string name, int limit, int remaining, float resetSeconds) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + Limit = limit; + Remaining = remaining; + ResetSeconds = resetSeconds; + } + + internal ConversationRateLimitDetailsItem(string name, int limit, int remaining, float resetSeconds, IDictionary serializedAdditionalRawData) + { + Name = name; + Limit = limit; + Remaining = remaining; + ResetSeconds = resetSeconds; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationRateLimitDetailsItem() + { + } + + public string Name { get; } + public int Limit { get; } + public int Remaining { get; } + public float ResetSeconds { get; } + } +} diff --git a/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.Serialization.cs b/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.Serialization.cs new file mode 100644 index 000000000..c8fae2d6b --- /dev/null +++ b/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.Serialization.cs @@ -0,0 +1,177 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationRateLimitsUpdatedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationRateLimitsUpdatedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("rate_limits") != true) + { + writer.WritePropertyName("rate_limits"u8); + writer.WriteStartArray(); + foreach (var item in RateLimits) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationRateLimitsUpdatedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationRateLimitsUpdatedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationRateLimitsUpdatedUpdate(document.RootElement, options); + } + + internal static ConversationRateLimitsUpdatedUpdate DeserializeConversationRateLimitsUpdatedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IReadOnlyList rateLimits = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("rate_limits"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationRateLimitDetailsItem.DeserializeConversationRateLimitDetailsItem(item, options)); + } + rateLimits = array; + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationRateLimitsUpdatedUpdate(type, eventId, serializedAdditionalRawData, rateLimits); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationRateLimitsUpdatedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationRateLimitsUpdatedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationRateLimitsUpdatedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationRateLimitsUpdatedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationRateLimitsUpdatedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationRateLimitsUpdatedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.cs b/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.cs new file mode 100644 index 000000000..881a004f5 --- /dev/null +++ b/src/Generated/Models/ConversationRateLimitsUpdatedUpdate.cs @@ -0,0 +1,32 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationRateLimitsUpdatedUpdate : ConversationUpdate + { + internal ConversationRateLimitsUpdatedUpdate(string eventId, IEnumerable rateLimits) : base(eventId) + { + Argument.AssertNotNull(rateLimits, nameof(rateLimits)); + + Kind = ConversationUpdateKind.RateLimitsUpdated; + RateLimits = rateLimits.ToList(); + } + + internal ConversationRateLimitsUpdatedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, IReadOnlyList rateLimits) : base(kind, eventId, serializedAdditionalRawData) + { + RateLimits = rateLimits; + } + + internal ConversationRateLimitsUpdatedUpdate() + { + } + + public IReadOnlyList RateLimits { get; } + } +} diff --git a/src/Generated/Models/ConversationResponseFinishedUpdate.Serialization.cs b/src/Generated/Models/ConversationResponseFinishedUpdate.Serialization.cs new file mode 100644 index 000000000..eeeeb0aad --- /dev/null +++ b/src/Generated/Models/ConversationResponseFinishedUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationResponseFinishedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationResponseFinishedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response") != true) + { + writer.WritePropertyName("response"u8); + writer.WriteObjectValue(_internalResponse, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationResponseFinishedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationResponseFinishedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationResponseFinishedUpdate(document.RootElement, options); + } + + internal static ConversationResponseFinishedUpdate DeserializeConversationResponseFinishedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponse response = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response"u8)) + { + response = InternalRealtimeResponse.DeserializeInternalRealtimeResponse(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationResponseFinishedUpdate(type, eventId, serializedAdditionalRawData, response); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationResponseFinishedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationResponseFinishedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationResponseFinishedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationResponseFinishedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationResponseFinishedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationResponseFinishedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationResponseFinishedUpdate.cs b/src/Generated/Models/ConversationResponseFinishedUpdate.cs new file mode 100644 index 000000000..db3e6422b --- /dev/null +++ b/src/Generated/Models/ConversationResponseFinishedUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationResponseFinishedUpdate : ConversationUpdate + { + internal ConversationResponseFinishedUpdate(string eventId, InternalRealtimeResponse internalResponse) : base(eventId) + { + Argument.AssertNotNull(internalResponse, nameof(internalResponse)); + + Kind = ConversationUpdateKind.ResponseFinished; + _internalResponse = internalResponse; + } + + internal ConversationResponseFinishedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeResponse internalResponse) : base(kind, eventId, serializedAdditionalRawData) + { + _internalResponse = internalResponse; + } + + internal ConversationResponseFinishedUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationResponseStartedUpdate.Serialization.cs b/src/Generated/Models/ConversationResponseStartedUpdate.Serialization.cs new file mode 100644 index 000000000..42f6599a3 --- /dev/null +++ b/src/Generated/Models/ConversationResponseStartedUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationResponseStartedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationResponseStartedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response") != true) + { + writer.WritePropertyName("response"u8); + writer.WriteObjectValue(_internalResponse, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationResponseStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationResponseStartedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationResponseStartedUpdate(document.RootElement, options); + } + + internal static ConversationResponseStartedUpdate DeserializeConversationResponseStartedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponse response = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response"u8)) + { + response = InternalRealtimeResponse.DeserializeInternalRealtimeResponse(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationResponseStartedUpdate(type, eventId, serializedAdditionalRawData, response); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationResponseStartedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationResponseStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationResponseStartedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationResponseStartedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationResponseStartedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationResponseStartedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationResponseStartedUpdate.cs b/src/Generated/Models/ConversationResponseStartedUpdate.cs new file mode 100644 index 000000000..fbd5f476b --- /dev/null +++ b/src/Generated/Models/ConversationResponseStartedUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationResponseStartedUpdate : ConversationUpdate + { + internal ConversationResponseStartedUpdate(string eventId, InternalRealtimeResponse internalResponse) : base(eventId) + { + Argument.AssertNotNull(internalResponse, nameof(internalResponse)); + + Kind = ConversationUpdateKind.ResponseStarted; + _internalResponse = internalResponse; + } + + internal ConversationResponseStartedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeResponse internalResponse) : base(kind, eventId, serializedAdditionalRawData) + { + _internalResponse = internalResponse; + } + + internal ConversationResponseStartedUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationSessionConfiguredUpdate.Serialization.cs b/src/Generated/Models/ConversationSessionConfiguredUpdate.Serialization.cs new file mode 100644 index 000000000..8e615fd9b --- /dev/null +++ b/src/Generated/Models/ConversationSessionConfiguredUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionConfiguredUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionConfiguredUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("session") != true) + { + writer.WritePropertyName("session"u8); + writer.WriteObjectValue(_internalSession, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationSessionConfiguredUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionConfiguredUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationSessionConfiguredUpdate(document.RootElement, options); + } + + internal static ConversationSessionConfiguredUpdate DeserializeConversationSessionConfiguredUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseSession session = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("session"u8)) + { + session = InternalRealtimeResponseSession.DeserializeInternalRealtimeResponseSession(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationSessionConfiguredUpdate(type, eventId, serializedAdditionalRawData, session); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationSessionConfiguredUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationSessionConfiguredUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationSessionConfiguredUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationSessionConfiguredUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationSessionConfiguredUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationSessionConfiguredUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationSessionConfiguredUpdate.cs b/src/Generated/Models/ConversationSessionConfiguredUpdate.cs new file mode 100644 index 000000000..81f99fa26 --- /dev/null +++ b/src/Generated/Models/ConversationSessionConfiguredUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionConfiguredUpdate : ConversationUpdate + { + internal ConversationSessionConfiguredUpdate(string eventId, InternalRealtimeResponseSession internalSession) : base(eventId) + { + Argument.AssertNotNull(internalSession, nameof(internalSession)); + + Kind = ConversationUpdateKind.SessionConfigured; + _internalSession = internalSession; + } + + internal ConversationSessionConfiguredUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeResponseSession internalSession) : base(kind, eventId, serializedAdditionalRawData) + { + _internalSession = internalSession; + } + + internal ConversationSessionConfiguredUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationSessionOptions.Serialization.cs b/src/Generated/Models/ConversationSessionOptions.Serialization.cs new file mode 100644 index 000000000..9f00e93a1 --- /dev/null +++ b/src/Generated/Models/ConversationSessionOptions.Serialization.cs @@ -0,0 +1,341 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionOptions : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionOptions)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("model") != true && Optional.IsDefined(Model)) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + } + if (SerializedAdditionalRawData?.ContainsKey("modalities") != true && Optional.IsCollectionDefined(_internalModalities)) + { + writer.WritePropertyName("modalities"u8); + writer.WriteStartArray(); + foreach (var item in _internalModalities) + { + writer.WriteStringValue(item.ToString()); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("voice") != true && Optional.IsDefined(Voice)) + { + writer.WritePropertyName("voice"u8); + writer.WriteStringValue(Voice.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("instructions") != true && Optional.IsDefined(Instructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + if (SerializedAdditionalRawData?.ContainsKey("input_audio_format") != true && Optional.IsDefined(InputAudioFormat)) + { + writer.WritePropertyName("input_audio_format"u8); + writer.WriteStringValue(InputAudioFormat.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("output_audio_format") != true && Optional.IsDefined(OutputAudioFormat)) + { + writer.WritePropertyName("output_audio_format"u8); + writer.WriteStringValue(OutputAudioFormat.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("input_audio_transcription") != true && Optional.IsDefined(InputTranscriptionOptions)) + { + writer.WritePropertyName("input_audio_transcription"u8); + writer.WriteObjectValue(InputTranscriptionOptions, options); + } + if (SerializedAdditionalRawData?.ContainsKey("turn_detection") != true && Optional.IsDefined(TurnDetectionOptions)) + { + writer.WritePropertyName("turn_detection"u8); + writer.WriteObjectValue(TurnDetectionOptions, options); + } + if (SerializedAdditionalRawData?.ContainsKey("tools") != true && Optional.IsCollectionDefined(Tools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("tool_choice") != true && Optional.IsDefined(_internalToolChoice)) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(_internalToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(_internalToolChoice)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("temperature") != true && Optional.IsDefined(Temperature)) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + if (SerializedAdditionalRawData?.ContainsKey("max_response_output_tokens") != true && Optional.IsDefined(_maxResponseOutputTokens)) + { + writer.WritePropertyName("max_response_output_tokens"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(_maxResponseOutputTokens); +#else + using (JsonDocument document = JsonDocument.Parse(_maxResponseOutputTokens)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationSessionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationSessionOptions(document.RootElement, options); + } + + internal static ConversationSessionOptions DeserializeConversationSessionOptions(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string model = default; + IList modalities = default; + ConversationVoice? voice = default; + string instructions = default; + ConversationAudioFormat? inputAudioFormat = default; + ConversationAudioFormat? outputAudioFormat = default; + ConversationInputTranscriptionOptions inputAudioTranscription = default; + ConversationTurnDetectionOptions turnDetection = default; + IList tools = default; + BinaryData toolChoice = default; + float? temperature = default; + BinaryData maxResponseOutputTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("modalities"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(new InternalRealtimeRequestSessionUpdateCommandSessionModality(item.GetString())); + } + modalities = array; + continue; + } + if (property.NameEquals("voice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + voice = new ConversationVoice(property.Value.GetString()); + continue; + } + if (property.NameEquals("instructions"u8)) + { + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("input_audio_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inputAudioFormat = new ConversationAudioFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("output_audio_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + outputAudioFormat = new ConversationAudioFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("input_audio_transcription"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + inputAudioTranscription = ConversationInputTranscriptionOptions.DeserializeConversationInputTranscriptionOptions(property.Value, options); + continue; + } + if (property.NameEquals("turn_detection"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + turnDetection = ConversationTurnDetectionOptions.DeserializeConversationTurnDetectionOptions(property.Value, options); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationTool.DeserializeConversationTool(item, options)); + } + tools = array; + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_response_output_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + maxResponseOutputTokens = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationSessionOptions( + model, + modalities ?? new ChangeTrackingList(), + voice, + instructions, + inputAudioFormat, + outputAudioFormat, + inputAudioTranscription, + turnDetection, + tools ?? new ChangeTrackingList(), + toolChoice, + temperature, + maxResponseOutputTokens, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationSessionOptions)} does not support writing '{options.Format}' format."); + } + } + + ConversationSessionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationSessionOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationSessionOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationSessionOptions FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationSessionOptions(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationSessionOptions.cs b/src/Generated/Models/ConversationSessionOptions.cs new file mode 100644 index 000000000..e5e5d1ad8 --- /dev/null +++ b/src/Generated/Models/ConversationSessionOptions.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionOptions + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public ConversationSessionOptions() + { + _internalModalities = new ChangeTrackingList(); + Tools = new ChangeTrackingList(); + } + + internal ConversationSessionOptions(string model, IList internalModalities, ConversationVoice? voice, string instructions, ConversationAudioFormat? inputAudioFormat, ConversationAudioFormat? outputAudioFormat, ConversationInputTranscriptionOptions inputTranscriptionOptions, ConversationTurnDetectionOptions turnDetectionOptions, IList tools, BinaryData internalToolChoice, float? temperature, BinaryData maxResponseOutputTokens, IDictionary serializedAdditionalRawData) + { + Model = model; + _internalModalities = internalModalities; + Voice = voice; + Instructions = instructions; + InputAudioFormat = inputAudioFormat; + OutputAudioFormat = outputAudioFormat; + InputTranscriptionOptions = inputTranscriptionOptions; + TurnDetectionOptions = turnDetectionOptions; + Tools = tools; + _internalToolChoice = internalToolChoice; + Temperature = temperature; + _maxResponseOutputTokens = maxResponseOutputTokens; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + public ConversationVoice? Voice { get; set; } + public string Instructions { get; set; } + public ConversationAudioFormat? InputAudioFormat { get; set; } + public ConversationAudioFormat? OutputAudioFormat { get; set; } + public IList Tools { get; } + public float? Temperature { get; set; } + } +} diff --git a/src/Generated/Models/ConversationSessionStartedUpdate.Serialization.cs b/src/Generated/Models/ConversationSessionStartedUpdate.Serialization.cs new file mode 100644 index 000000000..118d79383 --- /dev/null +++ b/src/Generated/Models/ConversationSessionStartedUpdate.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionStartedUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionStartedUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("session") != true) + { + writer.WritePropertyName("session"u8); + writer.WriteObjectValue(_internalSession, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationSessionStartedUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationSessionStartedUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationSessionStartedUpdate(document.RootElement, options); + } + + internal static ConversationSessionStartedUpdate DeserializeConversationSessionStartedUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseSession session = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("session"u8)) + { + session = InternalRealtimeResponseSession.DeserializeInternalRealtimeResponseSession(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationSessionStartedUpdate(type, eventId, serializedAdditionalRawData, session); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationSessionStartedUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationSessionStartedUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationSessionStartedUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationSessionStartedUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationSessionStartedUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationSessionStartedUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationSessionStartedUpdate.cs b/src/Generated/Models/ConversationSessionStartedUpdate.cs new file mode 100644 index 000000000..400466995 --- /dev/null +++ b/src/Generated/Models/ConversationSessionStartedUpdate.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationSessionStartedUpdate : ConversationUpdate + { + internal ConversationSessionStartedUpdate(string eventId, InternalRealtimeResponseSession internalSession) : base(eventId) + { + Argument.AssertNotNull(internalSession, nameof(internalSession)); + + Kind = ConversationUpdateKind.SessionStarted; + _internalSession = internalSession; + } + + internal ConversationSessionStartedUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeResponseSession internalSession) : base(kind, eventId, serializedAdditionalRawData) + { + _internalSession = internalSession; + } + + internal ConversationSessionStartedUpdate() + { + } + } +} diff --git a/src/Generated/Models/ConversationStatus.cs b/src/Generated/Models/ConversationStatus.cs new file mode 100644 index 000000000..7de858fc2 --- /dev/null +++ b/src/Generated/Models/ConversationStatus.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationStatus : IEquatable + { + private readonly string _value; + + public ConversationStatus(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string InProgressValue = "in_progress"; + private const string CompletedValue = "completed"; + private const string CancelledValue = "cancelled"; + private const string IncompleteValue = "incomplete"; + private const string FailedValue = "failed"; + + public static ConversationStatus InProgress { get; } = new ConversationStatus(InProgressValue); + public static ConversationStatus Completed { get; } = new ConversationStatus(CompletedValue); + public static ConversationStatus Cancelled { get; } = new ConversationStatus(CancelledValue); + public static ConversationStatus Incomplete { get; } = new ConversationStatus(IncompleteValue); + public static ConversationStatus Failed { get; } = new ConversationStatus(FailedValue); + public static bool operator ==(ConversationStatus left, ConversationStatus right) => left.Equals(right); + public static bool operator !=(ConversationStatus left, ConversationStatus right) => !left.Equals(right); + public static implicit operator ConversationStatus(string value) => new ConversationStatus(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationStatus other && Equals(other); + public bool Equals(ConversationStatus other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationTextDeltaUpdate.Serialization.cs b/src/Generated/Models/ConversationTextDeltaUpdate.Serialization.cs new file mode 100644 index 000000000..fd954c5d1 --- /dev/null +++ b/src/Generated/Models/ConversationTextDeltaUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTextDeltaUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTextDeltaUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("delta") != true) + { + writer.WritePropertyName("delta"u8); + writer.WriteStringValue(Delta); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTextDeltaUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTextDeltaUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTextDeltaUpdate(document.RootElement, options); + } + + internal static ConversationTextDeltaUpdate DeserializeConversationTextDeltaUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + string delta = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("delta"u8)) + { + delta = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationTextDeltaUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTextDeltaUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationTextDeltaUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTextDeltaUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTextDeltaUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationTextDeltaUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationTextDeltaUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationTextDeltaUpdate.cs b/src/Generated/Models/ConversationTextDeltaUpdate.cs new file mode 100644 index 000000000..70deec37a --- /dev/null +++ b/src/Generated/Models/ConversationTextDeltaUpdate.cs @@ -0,0 +1,45 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTextDeltaUpdate : ConversationUpdate + { + internal ConversationTextDeltaUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, string delta) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(delta, nameof(delta)); + + Kind = ConversationUpdateKind.ResponseTextDelta; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationTextDeltaUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, string delta) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Delta = delta; + } + + internal ConversationTextDeltaUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + public string Delta { get; } + } +} diff --git a/src/Generated/Models/ConversationTextDoneUpdate.Serialization.cs b/src/Generated/Models/ConversationTextDoneUpdate.Serialization.cs new file mode 100644 index 000000000..0c3fc276b --- /dev/null +++ b/src/Generated/Models/ConversationTextDoneUpdate.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTextDoneUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTextDoneUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response_id") != true) + { + writer.WritePropertyName("response_id"u8); + writer.WriteStringValue(ResponseId); + } + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("output_index") != true) + { + writer.WritePropertyName("output_index"u8); + writer.WriteNumberValue(OutputIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("value") != true) + { + writer.WritePropertyName("value"u8); + writer.WriteStringValue(Value); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTextDoneUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTextDoneUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTextDoneUpdate(document.RootElement, options); + } + + internal static ConversationTextDoneUpdate DeserializeConversationTextDoneUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string responseId = default; + string itemId = default; + int outputIndex = default; + int contentIndex = default; + string value = default; + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response_id"u8)) + { + responseId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output_index"u8)) + { + outputIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("value"u8)) + { + value = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationTextDoneUpdate( + type, + eventId, + serializedAdditionalRawData, + responseId, + itemId, + outputIndex, + contentIndex, + value); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTextDoneUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationTextDoneUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTextDoneUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTextDoneUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new ConversationTextDoneUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationTextDoneUpdate(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationTextDoneUpdate.cs b/src/Generated/Models/ConversationTextDoneUpdate.cs new file mode 100644 index 000000000..8761a3b61 --- /dev/null +++ b/src/Generated/Models/ConversationTextDoneUpdate.cs @@ -0,0 +1,45 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTextDoneUpdate : ConversationUpdate + { + internal ConversationTextDoneUpdate(string eventId, string responseId, string itemId, int outputIndex, int contentIndex, string value) : base(eventId) + { + Argument.AssertNotNull(responseId, nameof(responseId)); + Argument.AssertNotNull(itemId, nameof(itemId)); + Argument.AssertNotNull(value, nameof(value)); + + Kind = ConversationUpdateKind.ResponseTextDone; + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Value = value; + } + + internal ConversationTextDoneUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData, string responseId, string itemId, int outputIndex, int contentIndex, string value) : base(kind, eventId, serializedAdditionalRawData) + { + ResponseId = responseId; + ItemId = itemId; + OutputIndex = outputIndex; + ContentIndex = contentIndex; + Value = value; + } + + internal ConversationTextDoneUpdate() + { + } + + public string ResponseId { get; } + public string ItemId { get; } + public int OutputIndex { get; } + public int ContentIndex { get; } + public string Value { get; } + } +} diff --git a/src/Generated/Models/ConversationTokenUsage.Serialization.cs b/src/Generated/Models/ConversationTokenUsage.Serialization.cs new file mode 100644 index 000000000..4485af275 --- /dev/null +++ b/src/Generated/Models/ConversationTokenUsage.Serialization.cs @@ -0,0 +1,183 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTokenUsage : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTokenUsage)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("total_tokens") != true) + { + writer.WritePropertyName("total_tokens"u8); + writer.WriteNumberValue(TotalTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("input_tokens") != true) + { + writer.WritePropertyName("input_tokens"u8); + writer.WriteNumberValue(InputTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("output_tokens") != true) + { + writer.WritePropertyName("output_tokens"u8); + writer.WriteNumberValue(OutputTokens); + } + if (SerializedAdditionalRawData?.ContainsKey("input_token_details") != true) + { + writer.WritePropertyName("input_token_details"u8); + writer.WriteObjectValue(InputTokenDetails, options); + } + if (SerializedAdditionalRawData?.ContainsKey("output_token_details") != true) + { + writer.WritePropertyName("output_token_details"u8); + writer.WriteObjectValue(OutputTokenDetails, options); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTokenUsage IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTokenUsage)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTokenUsage(document.RootElement, options); + } + + internal static ConversationTokenUsage DeserializeConversationTokenUsage(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int totalTokens = default; + int inputTokens = default; + int outputTokens = default; + ConversationInputTokenUsageDetails inputTokenDetails = default; + ConversationOutputTokenUsageDetails outputTokenDetails = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("total_tokens"u8)) + { + totalTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("input_tokens"u8)) + { + inputTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("output_tokens"u8)) + { + outputTokens = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("input_token_details"u8)) + { + inputTokenDetails = ConversationInputTokenUsageDetails.DeserializeConversationInputTokenUsageDetails(property.Value, options); + continue; + } + if (property.NameEquals("output_token_details"u8)) + { + outputTokenDetails = ConversationOutputTokenUsageDetails.DeserializeConversationOutputTokenUsageDetails(property.Value, options); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new ConversationTokenUsage( + totalTokens, + inputTokens, + outputTokens, + inputTokenDetails, + outputTokenDetails, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTokenUsage)} does not support writing '{options.Format}' format."); + } + } + + ConversationTokenUsage IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTokenUsage(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTokenUsage)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationTokenUsage FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationTokenUsage(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationTokenUsage.cs b/src/Generated/Models/ConversationTokenUsage.cs new file mode 100644 index 000000000..d8047f775 --- /dev/null +++ b/src/Generated/Models/ConversationTokenUsage.cs @@ -0,0 +1,45 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public partial class ConversationTokenUsage + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal ConversationTokenUsage(int totalTokens, int inputTokens, int outputTokens, ConversationInputTokenUsageDetails inputTokenDetails, ConversationOutputTokenUsageDetails outputTokenDetails) + { + Argument.AssertNotNull(inputTokenDetails, nameof(inputTokenDetails)); + Argument.AssertNotNull(outputTokenDetails, nameof(outputTokenDetails)); + + TotalTokens = totalTokens; + InputTokens = inputTokens; + OutputTokens = outputTokens; + InputTokenDetails = inputTokenDetails; + OutputTokenDetails = outputTokenDetails; + } + + internal ConversationTokenUsage(int totalTokens, int inputTokens, int outputTokens, ConversationInputTokenUsageDetails inputTokenDetails, ConversationOutputTokenUsageDetails outputTokenDetails, IDictionary serializedAdditionalRawData) + { + TotalTokens = totalTokens; + InputTokens = inputTokens; + OutputTokens = outputTokens; + InputTokenDetails = inputTokenDetails; + OutputTokenDetails = outputTokenDetails; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationTokenUsage() + { + } + + public int TotalTokens { get; } + public int InputTokens { get; } + public int OutputTokens { get; } + public ConversationInputTokenUsageDetails InputTokenDetails { get; } + public ConversationOutputTokenUsageDetails OutputTokenDetails { get; } + } +} diff --git a/src/Generated/Models/ConversationTool.Serialization.cs b/src/Generated/Models/ConversationTool.Serialization.cs new file mode 100644 index 000000000..c7d7dd0cb --- /dev/null +++ b/src/Generated/Models/ConversationTool.Serialization.cs @@ -0,0 +1,123 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeTool))] + public partial class ConversationTool : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTool)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTool)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTool(document.RootElement, options); + } + + internal static ConversationTool DeserializeConversationTool(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function": return ConversationFunctionTool.DeserializeConversationFunctionTool(element, options); + } + } + return UnknownRealtimeTool.DeserializeUnknownRealtimeTool(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTool)} does not support writing '{options.Format}' format."); + } + } + + ConversationTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTool(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTool)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationTool FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationTool(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationTool.cs b/src/Generated/Models/ConversationTool.cs new file mode 100644 index 000000000..fb66af814 --- /dev/null +++ b/src/Generated/Models/ConversationTool.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public abstract partial class ConversationTool + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected ConversationTool() + { + } + + internal ConversationTool(ConversationToolKind kind, IDictionary serializedAdditionalRawData) + { + Kind = kind; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + } +} diff --git a/src/Generated/Models/ConversationToolChoiceKind.Serialization.cs b/src/Generated/Models/ConversationToolChoiceKind.Serialization.cs new file mode 100644 index 000000000..880cf9f3c --- /dev/null +++ b/src/Generated/Models/ConversationToolChoiceKind.Serialization.cs @@ -0,0 +1,27 @@ +// + +#nullable disable + +using System; + +namespace OpenAI.RealtimeConversation +{ + internal static partial class ConversationToolChoiceKindExtensions + { + public static string ToSerialString(this ConversationToolChoiceKind value) => value switch + { + ConversationToolChoiceKind.Auto => "auto", + ConversationToolChoiceKind.None => "none", + ConversationToolChoiceKind.Required => "required", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationToolChoiceKind value.") + }; + + public static ConversationToolChoiceKind ToConversationToolChoiceKind(this string value) + { + if (StringComparer.OrdinalIgnoreCase.Equals(value, "auto")) return ConversationToolChoiceKind.Auto; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "none")) return ConversationToolChoiceKind.None; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "required")) return ConversationToolChoiceKind.Required; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationToolChoiceKind value."); + } + } +} diff --git a/src/Generated/Models/ConversationToolKind.cs b/src/Generated/Models/ConversationToolKind.cs new file mode 100644 index 000000000..acb65bef4 --- /dev/null +++ b/src/Generated/Models/ConversationToolKind.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationToolKind : IEquatable + { + private readonly string _value; + + public ConversationToolKind(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string FunctionValue = "function"; + + public static ConversationToolKind Function { get; } = new ConversationToolKind(FunctionValue); + public static bool operator ==(ConversationToolKind left, ConversationToolKind right) => left.Equals(right); + public static bool operator !=(ConversationToolKind left, ConversationToolKind right) => !left.Equals(right); + public static implicit operator ConversationToolKind(string value) => new ConversationToolKind(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationToolKind other && Equals(other); + public bool Equals(ConversationToolKind other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationTranscriptionModel.cs b/src/Generated/Models/ConversationTranscriptionModel.cs new file mode 100644 index 000000000..37d47426a --- /dev/null +++ b/src/Generated/Models/ConversationTranscriptionModel.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationTranscriptionModel : IEquatable + { + private readonly string _value; + + public ConversationTranscriptionModel(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Whisper1Value = "whisper-1"; + + public static ConversationTranscriptionModel Whisper1 { get; } = new ConversationTranscriptionModel(Whisper1Value); + public static bool operator ==(ConversationTranscriptionModel left, ConversationTranscriptionModel right) => left.Equals(right); + public static bool operator !=(ConversationTranscriptionModel left, ConversationTranscriptionModel right) => !left.Equals(right); + public static implicit operator ConversationTranscriptionModel(string value) => new ConversationTranscriptionModel(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationTranscriptionModel other && Equals(other); + public bool Equals(ConversationTranscriptionModel other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/ConversationTurnDetectionKind.Serialization.cs b/src/Generated/Models/ConversationTurnDetectionKind.Serialization.cs new file mode 100644 index 000000000..c2efd47d7 --- /dev/null +++ b/src/Generated/Models/ConversationTurnDetectionKind.Serialization.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System; + +namespace OpenAI.RealtimeConversation +{ + internal static partial class ConversationTurnDetectionKindExtensions + { + public static string ToSerialString(this ConversationTurnDetectionKind value) => value switch + { + ConversationTurnDetectionKind.ServerVoiceActivityDetection => "server_vad", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationTurnDetectionKind value.") + }; + + public static ConversationTurnDetectionKind ToConversationTurnDetectionKind(this string value) + { + if (StringComparer.OrdinalIgnoreCase.Equals(value, "server_vad")) return ConversationTurnDetectionKind.ServerVoiceActivityDetection; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationTurnDetectionKind value."); + } + } +} diff --git a/src/Generated/Models/ConversationTurnDetectionOptions.Serialization.cs b/src/Generated/Models/ConversationTurnDetectionOptions.Serialization.cs new file mode 100644 index 000000000..649f6f784 --- /dev/null +++ b/src/Generated/Models/ConversationTurnDetectionOptions.Serialization.cs @@ -0,0 +1,105 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeTurnDetection))] + public partial class ConversationTurnDetectionOptions : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTurnDetectionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTurnDetectionOptions(document.RootElement, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support writing '{options.Format}' format."); + } + } + + ConversationTurnDetectionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTurnDetectionOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationTurnDetectionOptions FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationTurnDetectionOptions(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationTurnDetectionOptions.cs b/src/Generated/Models/ConversationTurnDetectionOptions.cs new file mode 100644 index 000000000..1349c2772 --- /dev/null +++ b/src/Generated/Models/ConversationTurnDetectionOptions.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public abstract partial class ConversationTurnDetectionOptions + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected ConversationTurnDetectionOptions() + { + } + + internal ConversationTurnDetectionOptions(ConversationTurnDetectionKind kind, IDictionary serializedAdditionalRawData) + { + Kind = kind; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + } +} diff --git a/src/Generated/Models/ConversationUpdate.Serialization.cs b/src/Generated/Models/ConversationUpdate.Serialization.cs new file mode 100644 index 000000000..ac5eff099 --- /dev/null +++ b/src/Generated/Models/ConversationUpdate.Serialization.cs @@ -0,0 +1,161 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeResponseCommand))] + public partial class ConversationUpdate : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationUpdate(document.RootElement, options); + } + + internal static ConversationUpdate DeserializeConversationUpdate(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "conversation.item.created": return ConversationItemAcknowledgedUpdate.DeserializeConversationItemAcknowledgedUpdate(element, options); + case "conversation.item.deleted": return ConversationItemDeletedUpdate.DeserializeConversationItemDeletedUpdate(element, options); + case "conversation.item.input_audio_transcription.completed": return ConversationInputTranscriptionFinishedUpdate.DeserializeConversationInputTranscriptionFinishedUpdate(element, options); + case "conversation.item.input_audio_transcription.failed": return ConversationInputTranscriptionFailedUpdate.DeserializeConversationInputTranscriptionFailedUpdate(element, options); + case "conversation.item.truncated": return ConversationItemTruncatedUpdate.DeserializeConversationItemTruncatedUpdate(element, options); + case "error": return ConversationErrorUpdate.DeserializeConversationErrorUpdate(element, options); + case "input_audio_buffer.cleared": return ConversationInputAudioBufferClearedUpdate.DeserializeConversationInputAudioBufferClearedUpdate(element, options); + case "input_audio_buffer.committed": return ConversationInputAudioBufferCommittedUpdate.DeserializeConversationInputAudioBufferCommittedUpdate(element, options); + case "input_audio_buffer.speech_started": return ConversationInputSpeechStartedUpdate.DeserializeConversationInputSpeechStartedUpdate(element, options); + case "input_audio_buffer.speech_stopped": return ConversationInputSpeechFinishedUpdate.DeserializeConversationInputSpeechFinishedUpdate(element, options); + case "rate_limits.updated": return ConversationRateLimitsUpdatedUpdate.DeserializeConversationRateLimitsUpdatedUpdate(element, options); + case "response.audio_transcript.delta": return ConversationOutputTranscriptionDeltaUpdate.DeserializeConversationOutputTranscriptionDeltaUpdate(element, options); + case "response.audio_transcript.done": return ConversationOutputTranscriptionFinishedUpdate.DeserializeConversationOutputTranscriptionFinishedUpdate(element, options); + case "response.audio.delta": return ConversationAudioDeltaUpdate.DeserializeConversationAudioDeltaUpdate(element, options); + case "response.audio.done": return ConversationAudioDoneUpdate.DeserializeConversationAudioDoneUpdate(element, options); + case "response.content_part.added": return ConversationContentPartStartedUpdate.DeserializeConversationContentPartStartedUpdate(element, options); + case "response.content_part.done": return ConversationContentPartFinishedUpdate.DeserializeConversationContentPartFinishedUpdate(element, options); + case "response.created": return ConversationResponseStartedUpdate.DeserializeConversationResponseStartedUpdate(element, options); + case "response.done": return ConversationResponseFinishedUpdate.DeserializeConversationResponseFinishedUpdate(element, options); + case "response.function_call_arguments.delta": return ConversationFunctionCallArgumentsDeltaUpdate.DeserializeConversationFunctionCallArgumentsDeltaUpdate(element, options); + case "response.function_call_arguments.done": return ConversationFunctionCallArgumentsDoneUpdate.DeserializeConversationFunctionCallArgumentsDoneUpdate(element, options); + case "response.output_item.added": return ConversationItemStartedUpdate.DeserializeConversationItemStartedUpdate(element, options); + case "response.output_item.done": return ConversationItemFinishedUpdate.DeserializeConversationItemFinishedUpdate(element, options); + case "response.text.delta": return ConversationTextDeltaUpdate.DeserializeConversationTextDeltaUpdate(element, options); + case "response.text.done": return ConversationTextDoneUpdate.DeserializeConversationTextDoneUpdate(element, options); + case "session.created": return ConversationSessionStartedUpdate.DeserializeConversationSessionStartedUpdate(element, options); + case "session.updated": return ConversationSessionConfiguredUpdate.DeserializeConversationSessionConfiguredUpdate(element, options); + } + } + return UnknownRealtimeResponseCommand.DeserializeUnknownRealtimeResponseCommand(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static ConversationUpdate FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeConversationUpdate(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/ConversationUpdate.cs b/src/Generated/Models/ConversationUpdate.cs new file mode 100644 index 000000000..850f16480 --- /dev/null +++ b/src/Generated/Models/ConversationUpdate.cs @@ -0,0 +1,30 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + public abstract partial class ConversationUpdate + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected ConversationUpdate(string eventId) + { + EventId = eventId; + } + + internal ConversationUpdate(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData) + { + Kind = kind; + EventId = eventId; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationUpdate() + { + } + public string EventId { get; } + } +} diff --git a/src/Generated/Models/ConversationUpdateKind.Serialization.cs b/src/Generated/Models/ConversationUpdateKind.Serialization.cs new file mode 100644 index 000000000..1bffcec88 --- /dev/null +++ b/src/Generated/Models/ConversationUpdateKind.Serialization.cs @@ -0,0 +1,75 @@ +// + +#nullable disable + +using System; + +namespace OpenAI.RealtimeConversation +{ + internal static partial class ConversationUpdateKindExtensions + { + public static string ToSerialString(this ConversationUpdateKind value) => value switch + { + ConversationUpdateKind.SessionStarted => "session.created", + ConversationUpdateKind.SessionConfigured => "session.updated", + ConversationUpdateKind.ItemAcknowledged => "conversation.item.created", + ConversationUpdateKind.ItemDeleted => "conversation.item.deleted", + ConversationUpdateKind.ItemTruncated => "conversation.item.truncated", + ConversationUpdateKind.ResponseStarted => "response.created", + ConversationUpdateKind.ResponseFinished => "response.done", + ConversationUpdateKind.RateLimitsUpdated => "rate_limits.updated", + ConversationUpdateKind.ItemStarted => "response.output_item.added", + ConversationUpdateKind.ItemFinished => "response.output_item.done", + ConversationUpdateKind.ContentPartStarted => "response.content_part.added", + ConversationUpdateKind.ContentPartFinished => "response.content_part.done", + ConversationUpdateKind.ResponseAudioDelta => "response.audio.delta", + ConversationUpdateKind.ResponseAudioDone => "response.audio.done", + ConversationUpdateKind.ResponseAudioTranscriptDelta => "response.audio_transcript.delta", + ConversationUpdateKind.ResponseAudioTranscriptDone => "response.audio_transcript.done", + ConversationUpdateKind.ResponseTextDelta => "response.text.delta", + ConversationUpdateKind.ResponseTextDone => "response.text.done", + ConversationUpdateKind.ResponseFunctionCallArgumentsDelta => "response.function_call_arguments.delta", + ConversationUpdateKind.ResponseFunctionCallArgumentsDone => "response.function_call_arguments.done", + ConversationUpdateKind.InputAudioBufferSpeechStarted => "input_audio_buffer.speech_started", + ConversationUpdateKind.InputAudioBufferSpeechStopped => "input_audio_buffer.speech_stopped", + ConversationUpdateKind.ItemInputAudioTranscriptionCompleted => "conversation.item.input_audio_transcription.completed", + ConversationUpdateKind.ItemInputAudioTranscriptionFailed => "conversation.item.input_audio_transcription.failed", + ConversationUpdateKind.InputAudioBufferCommitted => "input_audio_buffer.committed", + ConversationUpdateKind.InputAudioBufferCleared => "input_audio_buffer.cleared", + ConversationUpdateKind.Error => "error", + _ => throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationUpdateKind value.") + }; + + public static ConversationUpdateKind ToConversationUpdateKind(this string value) + { + if (StringComparer.OrdinalIgnoreCase.Equals(value, "session.created")) return ConversationUpdateKind.SessionStarted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "session.updated")) return ConversationUpdateKind.SessionConfigured; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "conversation.item.created")) return ConversationUpdateKind.ItemAcknowledged; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "conversation.item.deleted")) return ConversationUpdateKind.ItemDeleted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "conversation.item.truncated")) return ConversationUpdateKind.ItemTruncated; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.created")) return ConversationUpdateKind.ResponseStarted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.done")) return ConversationUpdateKind.ResponseFinished; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "rate_limits.updated")) return ConversationUpdateKind.RateLimitsUpdated; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.output_item.added")) return ConversationUpdateKind.ItemStarted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.output_item.done")) return ConversationUpdateKind.ItemFinished; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.content_part.added")) return ConversationUpdateKind.ContentPartStarted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.content_part.done")) return ConversationUpdateKind.ContentPartFinished; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.audio.delta")) return ConversationUpdateKind.ResponseAudioDelta; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.audio.done")) return ConversationUpdateKind.ResponseAudioDone; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.audio_transcript.delta")) return ConversationUpdateKind.ResponseAudioTranscriptDelta; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.audio_transcript.done")) return ConversationUpdateKind.ResponseAudioTranscriptDone; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.text.delta")) return ConversationUpdateKind.ResponseTextDelta; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.text.done")) return ConversationUpdateKind.ResponseTextDone; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.function_call_arguments.delta")) return ConversationUpdateKind.ResponseFunctionCallArgumentsDelta; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "response.function_call_arguments.done")) return ConversationUpdateKind.ResponseFunctionCallArgumentsDone; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "input_audio_buffer.speech_started")) return ConversationUpdateKind.InputAudioBufferSpeechStarted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "input_audio_buffer.speech_stopped")) return ConversationUpdateKind.InputAudioBufferSpeechStopped; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "conversation.item.input_audio_transcription.completed")) return ConversationUpdateKind.ItemInputAudioTranscriptionCompleted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "conversation.item.input_audio_transcription.failed")) return ConversationUpdateKind.ItemInputAudioTranscriptionFailed; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "input_audio_buffer.committed")) return ConversationUpdateKind.InputAudioBufferCommitted; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "input_audio_buffer.cleared")) return ConversationUpdateKind.InputAudioBufferCleared; + if (StringComparer.OrdinalIgnoreCase.Equals(value, "error")) return ConversationUpdateKind.Error; + throw new ArgumentOutOfRangeException(nameof(value), value, "Unknown ConversationUpdateKind value."); + } + } +} diff --git a/src/Generated/Models/ConversationVoice.cs b/src/Generated/Models/ConversationVoice.cs new file mode 100644 index 000000000..1c845699c --- /dev/null +++ b/src/Generated/Models/ConversationVoice.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + public readonly partial struct ConversationVoice : IEquatable + { + private readonly string _value; + + public ConversationVoice(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string AlloyValue = "alloy"; + private const string ShimmerValue = "shimmer"; + private const string EchoValue = "echo"; + + public static ConversationVoice Alloy { get; } = new ConversationVoice(AlloyValue); + public static ConversationVoice Shimmer { get; } = new ConversationVoice(ShimmerValue); + public static ConversationVoice Echo { get; } = new ConversationVoice(EchoValue); + public static bool operator ==(ConversationVoice left, ConversationVoice right) => left.Equals(right); + public static bool operator !=(ConversationVoice left, ConversationVoice right) => !left.Equals(right); + public static implicit operator ConversationVoice(string value) => new ConversationVoice(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is ConversationVoice other && Equals(other); + public bool Equals(ConversationVoice other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.Serialization.cs new file mode 100644 index 000000000..a06386951 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.Serialization.cs @@ -0,0 +1,197 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestAssistantMessageItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestAssistantMessageItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("content") != true) + { + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("role") != true) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true && Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestAssistantMessageItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestAssistantMessageItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestAssistantMessageItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestAssistantMessageItem DeserializeInternalRealtimeRequestAssistantMessageItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList content = default; + ConversationMessageRole role = default; + ConversationItemStatus? status = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationContentPart.DeserializeConversationContentPart(item, options)); + } + content = array; + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ConversationMessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestAssistantMessageItem( + type, + id, + serializedAdditionalRawData, + role, + status, + content); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestAssistantMessageItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestAssistantMessageItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestAssistantMessageItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestAssistantMessageItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestAssistantMessageItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestAssistantMessageItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.cs b/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.cs new file mode 100644 index 000000000..dd9526ceb --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestAssistantMessageItem.cs @@ -0,0 +1,30 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestAssistantMessageItem : InternalRealtimeRequestMessageItem + { + public InternalRealtimeRequestAssistantMessageItem(IEnumerable content) + { + Argument.AssertNotNull(content, nameof(content)); + + Role = ConversationMessageRole.Assistant; + Content = content.ToList(); + } + + internal InternalRealtimeRequestAssistantMessageItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, ConversationMessageRole role, ConversationItemStatus? status, IList content) : base(type, id, serializedAdditionalRawData, role, status) + { + Content = content; + } + + internal InternalRealtimeRequestAssistantMessageItem() + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestAudioContentPart.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestAudioContentPart.Serialization.cs new file mode 100644 index 000000000..b70b1c935 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestAudioContentPart.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestAudioContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestAudioContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("transcript") != true && Optional.IsDefined(Transcript)) + { + writer.WritePropertyName("transcript"u8); + writer.WriteStringValue(Transcript); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestAudioContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestAudioContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestAudioContentPart(document.RootElement, options); + } + + internal static InternalRealtimeRequestAudioContentPart DeserializeInternalRealtimeRequestAudioContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string transcript = default; + ConversationContentPartKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("transcript"u8)) + { + transcript = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationContentPartKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestAudioContentPart(type, serializedAdditionalRawData, transcript); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestAudioContentPart)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestAudioContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestAudioContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestAudioContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestAudioContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestAudioContentPart(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestAudioContentPart.cs b/src/Generated/Models/InternalRealtimeRequestAudioContentPart.cs new file mode 100644 index 000000000..06f2636b2 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestAudioContentPart.cs @@ -0,0 +1,24 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestAudioContentPart : ConversationContentPart + { + public InternalRealtimeRequestAudioContentPart() + { + Type = ConversationContentPartKind.InputAudio; + } + + internal InternalRealtimeRequestAudioContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData, string transcript) : base(type, serializedAdditionalRawData) + { + Transcript = transcript; + } + + public string Transcript { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestCommand.Serialization.cs new file mode 100644 index 000000000..c07105652 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestCommand.Serialization.cs @@ -0,0 +1,136 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeRequestCommand))] + internal partial class InternalRealtimeRequestCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestCommand DeserializeInternalRealtimeRequestCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "conversation.item.create": return InternalRealtimeRequestItemCreateCommand.DeserializeInternalRealtimeRequestItemCreateCommand(element, options); + case "conversation.item.delete": return InternalRealtimeRequestItemDeleteCommand.DeserializeInternalRealtimeRequestItemDeleteCommand(element, options); + case "conversation.item.truncate": return InternalRealtimeRequestItemTruncateCommand.DeserializeInternalRealtimeRequestItemTruncateCommand(element, options); + case "input_audio_buffer.append": return InternalRealtimeRequestInputAudioBufferAppendCommand.DeserializeInternalRealtimeRequestInputAudioBufferAppendCommand(element, options); + case "input_audio_buffer.clear": return InternalRealtimeRequestInputAudioBufferClearCommand.DeserializeInternalRealtimeRequestInputAudioBufferClearCommand(element, options); + case "input_audio_buffer.commit": return InternalRealtimeRequestInputAudioBufferCommitCommand.DeserializeInternalRealtimeRequestInputAudioBufferCommitCommand(element, options); + case "response.cancel": return InternalRealtimeRequestResponseCancelCommand.DeserializeInternalRealtimeRequestResponseCancelCommand(element, options); + case "response.create": return InternalRealtimeRequestResponseCreateCommand.DeserializeInternalRealtimeRequestResponseCreateCommand(element, options); + case "session.update": return InternalRealtimeRequestSessionUpdateCommand.DeserializeInternalRealtimeRequestSessionUpdateCommand(element, options); + } + } + return UnknownRealtimeRequestCommand.DeserializeUnknownRealtimeRequestCommand(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeRequestCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestCommand(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestCommand.cs b/src/Generated/Models/InternalRealtimeRequestCommand.cs new file mode 100644 index 000000000..9fd7fbd6b --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestCommand.cs @@ -0,0 +1,27 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal abstract partial class InternalRealtimeRequestCommand + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected InternalRealtimeRequestCommand() + { + } + + internal InternalRealtimeRequestCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData) + { + Kind = kind; + EventId = eventId; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeRequestCommandType Kind { get; set; } + public string EventId { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestCommandType.cs b/src/Generated/Models/InternalRealtimeRequestCommandType.cs new file mode 100644 index 000000000..b6e75ce49 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestCommandType.cs @@ -0,0 +1,50 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeRequestCommandType : IEquatable + { + private readonly string _value; + + public InternalRealtimeRequestCommandType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string SessionUpdateValue = "session.update"; + private const string InputAudioBufferAppendValue = "input_audio_buffer.append"; + private const string InputAudioBufferCommitValue = "input_audio_buffer.commit"; + private const string InputAudioBufferClearValue = "input_audio_buffer.clear"; + private const string ItemCreateValue = "conversation.item.create"; + private const string ItemDeleteValue = "conversation.item.delete"; + private const string ItemTruncateValue = "conversation.item.truncate"; + private const string ResponseCreateValue = "response.create"; + private const string ResponseCancelValue = "response.cancel"; + + public static InternalRealtimeRequestCommandType SessionUpdate { get; } = new InternalRealtimeRequestCommandType(SessionUpdateValue); + public static InternalRealtimeRequestCommandType InputAudioBufferAppend { get; } = new InternalRealtimeRequestCommandType(InputAudioBufferAppendValue); + public static InternalRealtimeRequestCommandType InputAudioBufferCommit { get; } = new InternalRealtimeRequestCommandType(InputAudioBufferCommitValue); + public static InternalRealtimeRequestCommandType InputAudioBufferClear { get; } = new InternalRealtimeRequestCommandType(InputAudioBufferClearValue); + public static InternalRealtimeRequestCommandType ItemCreate { get; } = new InternalRealtimeRequestCommandType(ItemCreateValue); + public static InternalRealtimeRequestCommandType ItemDelete { get; } = new InternalRealtimeRequestCommandType(ItemDeleteValue); + public static InternalRealtimeRequestCommandType ItemTruncate { get; } = new InternalRealtimeRequestCommandType(ItemTruncateValue); + public static InternalRealtimeRequestCommandType ResponseCreate { get; } = new InternalRealtimeRequestCommandType(ResponseCreateValue); + public static InternalRealtimeRequestCommandType ResponseCancel { get; } = new InternalRealtimeRequestCommandType(ResponseCancelValue); + public static bool operator ==(InternalRealtimeRequestCommandType left, InternalRealtimeRequestCommandType right) => left.Equals(right); + public static bool operator !=(InternalRealtimeRequestCommandType left, InternalRealtimeRequestCommandType right) => !left.Equals(right); + public static implicit operator InternalRealtimeRequestCommandType(string value) => new InternalRealtimeRequestCommandType(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeRequestCommandType other && Equals(other); + public bool Equals(InternalRealtimeRequestCommandType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.Serialization.cs new file mode 100644 index 000000000..b51551291 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.Serialization.cs @@ -0,0 +1,199 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestFunctionCallItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("arguments") != true) + { + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true && Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestFunctionCallItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestFunctionCallItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestFunctionCallItem DeserializeInternalRealtimeRequestFunctionCallItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string callId = default; + string arguments = default; + ConversationItemStatus? status = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestFunctionCallItem( + type, + id, + serializedAdditionalRawData, + name, + callId, + arguments, + status); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestFunctionCallItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestFunctionCallItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestFunctionCallItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestFunctionCallItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.cs b/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.cs new file mode 100644 index 000000000..74276e8fe --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestFunctionCallItem.cs @@ -0,0 +1,41 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestFunctionCallItem : ConversationItem + { + public InternalRealtimeRequestFunctionCallItem(string name, string callId, string arguments) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(arguments, nameof(arguments)); + + Type = InternalRealtimeRequestItemType.FunctionCall; + Name = name; + CallId = callId; + Arguments = arguments; + } + + internal InternalRealtimeRequestFunctionCallItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, string name, string callId, string arguments, ConversationItemStatus? status) : base(type, id, serializedAdditionalRawData) + { + Name = name; + CallId = callId; + Arguments = arguments; + Status = status; + } + + internal InternalRealtimeRequestFunctionCallItem() + { + } + + public string Name { get; } + public string CallId { get; } + public string Arguments { get; } + public ConversationItemStatus? Status { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.Serialization.cs new file mode 100644 index 000000000..9ec36d1d1 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestFunctionCallOutputItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallOutputItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("output") != true) + { + writer.WritePropertyName("output"u8); + writer.WriteStringValue(Output); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestFunctionCallOutputItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallOutputItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestFunctionCallOutputItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestFunctionCallOutputItem DeserializeInternalRealtimeRequestFunctionCallOutputItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string callId = default; + string output = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output"u8)) + { + output = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestFunctionCallOutputItem(type, id, serializedAdditionalRawData, callId, output); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallOutputItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestFunctionCallOutputItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestFunctionCallOutputItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestFunctionCallOutputItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestFunctionCallOutputItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestFunctionCallOutputItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.cs b/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.cs new file mode 100644 index 000000000..263d8d388 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestFunctionCallOutputItem.cs @@ -0,0 +1,35 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestFunctionCallOutputItem : ConversationItem + { + public InternalRealtimeRequestFunctionCallOutputItem(string callId, string output) + { + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(output, nameof(output)); + + Type = InternalRealtimeRequestItemType.FunctionCallOutput; + CallId = callId; + Output = output; + } + + internal InternalRealtimeRequestFunctionCallOutputItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, string callId, string output) : base(type, id, serializedAdditionalRawData) + { + CallId = callId; + Output = output; + } + + internal InternalRealtimeRequestFunctionCallOutputItem() + { + } + + public string CallId { get; } + public string Output { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.Serialization.cs new file mode 100644 index 000000000..ccf6cdaae --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.Serialization.cs @@ -0,0 +1,155 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferAppendCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferAppendCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("audio") != true) + { + writer.WritePropertyName("audio"u8); + writer.WriteBase64StringValue(Audio.ToArray(), "D"); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestInputAudioBufferAppendCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferAppendCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestInputAudioBufferAppendCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestInputAudioBufferAppendCommand DeserializeInternalRealtimeRequestInputAudioBufferAppendCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + BinaryData audio = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("audio"u8)) + { + audio = BinaryData.FromBytes(property.Value.GetBytesFromBase64("D")); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestInputAudioBufferAppendCommand(type, eventId, serializedAdditionalRawData, audio); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferAppendCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestInputAudioBufferAppendCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestInputAudioBufferAppendCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferAppendCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestInputAudioBufferAppendCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestInputAudioBufferAppendCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.cs new file mode 100644 index 000000000..1def2c84c --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferAppendCommand.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferAppendCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestInputAudioBufferAppendCommand(BinaryData audio) + { + Argument.AssertNotNull(audio, nameof(audio)); + + Kind = InternalRealtimeRequestCommandType.InputAudioBufferAppend; + Audio = audio; + } + + internal InternalRealtimeRequestInputAudioBufferAppendCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, BinaryData audio) : base(kind, eventId, serializedAdditionalRawData) + { + Audio = audio; + } + + internal InternalRealtimeRequestInputAudioBufferAppendCommand() + { + } + + public BinaryData Audio { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.Serialization.cs new file mode 100644 index 000000000..62cde6232 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferClearCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferClearCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestInputAudioBufferClearCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferClearCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestInputAudioBufferClearCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestInputAudioBufferClearCommand DeserializeInternalRealtimeRequestInputAudioBufferClearCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestInputAudioBufferClearCommand(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferClearCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestInputAudioBufferClearCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestInputAudioBufferClearCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferClearCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestInputAudioBufferClearCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestInputAudioBufferClearCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.cs new file mode 100644 index 000000000..8502e98a8 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferClearCommand.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferClearCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestInputAudioBufferClearCommand() + { + Kind = InternalRealtimeRequestCommandType.InputAudioBufferClear; + } + + internal InternalRealtimeRequestInputAudioBufferClearCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.Serialization.cs new file mode 100644 index 000000000..eff8f8871 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferCommitCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferCommitCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestInputAudioBufferCommitCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferCommitCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestInputAudioBufferCommitCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestInputAudioBufferCommitCommand DeserializeInternalRealtimeRequestInputAudioBufferCommitCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestInputAudioBufferCommitCommand(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferCommitCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestInputAudioBufferCommitCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestInputAudioBufferCommitCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestInputAudioBufferCommitCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestInputAudioBufferCommitCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestInputAudioBufferCommitCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.cs b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.cs new file mode 100644 index 000000000..5ed8421a0 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestInputAudioBufferCommitCommand.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestInputAudioBufferCommitCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestInputAudioBufferCommitCommand() + { + Kind = InternalRealtimeRequestCommandType.InputAudioBufferCommit; + } + + internal InternalRealtimeRequestInputAudioBufferCommitCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.Serialization.cs new file mode 100644 index 000000000..83e8754ba --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemCreateCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemCreateCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("previous_item_id") != true && Optional.IsDefined(PreviousItemId)) + { + writer.WritePropertyName("previous_item_id"u8); + writer.WriteStringValue(PreviousItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("item") != true) + { + writer.WritePropertyName("item"u8); + writer.WriteObjectValue(Item, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestItemCreateCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemCreateCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestItemCreateCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestItemCreateCommand DeserializeInternalRealtimeRequestItemCreateCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string previousItemId = default; + ConversationItem item = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("previous_item_id"u8)) + { + previousItemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("item"u8)) + { + item = ConversationItem.DeserializeConversationItem(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestItemCreateCommand(type, eventId, serializedAdditionalRawData, previousItemId, item); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemCreateCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestItemCreateCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestItemCreateCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemCreateCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestItemCreateCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestItemCreateCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.cs b/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.cs new file mode 100644 index 000000000..0c8650245 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemCreateCommand.cs @@ -0,0 +1,33 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemCreateCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestItemCreateCommand(ConversationItem item) + { + Argument.AssertNotNull(item, nameof(item)); + + Kind = InternalRealtimeRequestCommandType.ItemCreate; + Item = item; + } + + internal InternalRealtimeRequestItemCreateCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, string previousItemId, ConversationItem item) : base(kind, eventId, serializedAdditionalRawData) + { + PreviousItemId = previousItemId; + Item = item; + } + + internal InternalRealtimeRequestItemCreateCommand() + { + } + + public string PreviousItemId { get; set; } + public ConversationItem Item { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.Serialization.cs new file mode 100644 index 000000000..a16fa99d5 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.Serialization.cs @@ -0,0 +1,155 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemDeleteCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemDeleteCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestItemDeleteCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemDeleteCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestItemDeleteCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestItemDeleteCommand DeserializeInternalRealtimeRequestItemDeleteCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestItemDeleteCommand(type, eventId, serializedAdditionalRawData, itemId); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemDeleteCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestItemDeleteCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestItemDeleteCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemDeleteCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestItemDeleteCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestItemDeleteCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.cs b/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.cs new file mode 100644 index 000000000..d98685fea --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemDeleteCommand.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemDeleteCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestItemDeleteCommand(string itemId) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = InternalRealtimeRequestCommandType.ItemDelete; + ItemId = itemId; + } + + internal InternalRealtimeRequestItemDeleteCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, string itemId) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + } + + internal InternalRealtimeRequestItemDeleteCommand() + { + } + + public string ItemId { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.Serialization.cs new file mode 100644 index 000000000..905f64da1 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.Serialization.cs @@ -0,0 +1,183 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemTruncateCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemTruncateCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("item_id") != true) + { + writer.WritePropertyName("item_id"u8); + writer.WriteStringValue(ItemId); + } + if (SerializedAdditionalRawData?.ContainsKey("content_index") != true) + { + writer.WritePropertyName("content_index"u8); + writer.WriteNumberValue(ContentIndex); + } + if (SerializedAdditionalRawData?.ContainsKey("audio_end_ms") != true) + { + writer.WritePropertyName("audio_end_ms"u8); + writer.WriteNumberValue(AudioEndMs); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestItemTruncateCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemTruncateCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestItemTruncateCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestItemTruncateCommand DeserializeInternalRealtimeRequestItemTruncateCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string itemId = default; + int contentIndex = default; + int audioEndMs = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("item_id"u8)) + { + itemId = property.Value.GetString(); + continue; + } + if (property.NameEquals("content_index"u8)) + { + contentIndex = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("audio_end_ms"u8)) + { + audioEndMs = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestItemTruncateCommand( + type, + eventId, + serializedAdditionalRawData, + itemId, + contentIndex, + audioEndMs); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemTruncateCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestItemTruncateCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestItemTruncateCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestItemTruncateCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestItemTruncateCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestItemTruncateCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.cs b/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.cs new file mode 100644 index 000000000..e867f7c35 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemTruncateCommand.cs @@ -0,0 +1,37 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestItemTruncateCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestItemTruncateCommand(string itemId, int contentIndex, int audioEndMs) + { + Argument.AssertNotNull(itemId, nameof(itemId)); + + Kind = InternalRealtimeRequestCommandType.ItemTruncate; + ItemId = itemId; + ContentIndex = contentIndex; + AudioEndMs = audioEndMs; + } + + internal InternalRealtimeRequestItemTruncateCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, string itemId, int contentIndex, int audioEndMs) : base(kind, eventId, serializedAdditionalRawData) + { + ItemId = itemId; + ContentIndex = contentIndex; + AudioEndMs = audioEndMs; + } + + internal InternalRealtimeRequestItemTruncateCommand() + { + } + + public string ItemId { get; } + public int ContentIndex { get; } + public int AudioEndMs { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestItemType.cs b/src/Generated/Models/InternalRealtimeRequestItemType.cs new file mode 100644 index 000000000..118aab7e3 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestItemType.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeRequestItemType : IEquatable + { + private readonly string _value; + + public InternalRealtimeRequestItemType(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string MessageValue = "message"; + private const string FunctionCallValue = "function_call"; + private const string FunctionCallOutputValue = "function_call_output"; + + public static InternalRealtimeRequestItemType Message { get; } = new InternalRealtimeRequestItemType(MessageValue); + public static InternalRealtimeRequestItemType FunctionCall { get; } = new InternalRealtimeRequestItemType(FunctionCallValue); + public static InternalRealtimeRequestItemType FunctionCallOutput { get; } = new InternalRealtimeRequestItemType(FunctionCallOutputValue); + public static bool operator ==(InternalRealtimeRequestItemType left, InternalRealtimeRequestItemType right) => left.Equals(right); + public static bool operator !=(InternalRealtimeRequestItemType left, InternalRealtimeRequestItemType right) => !left.Equals(right); + public static implicit operator InternalRealtimeRequestItemType(string value) => new InternalRealtimeRequestItemType(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeRequestItemType other && Equals(other); + public bool Equals(InternalRealtimeRequestItemType other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestMessageItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestMessageItem.Serialization.cs new file mode 100644 index 000000000..41b65f714 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestMessageItem.Serialization.cs @@ -0,0 +1,179 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestMessageItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestMessageItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("role") != true) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true && Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestMessageItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestMessageItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestMessageItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestMessageItem DeserializeInternalRealtimeRequestMessageItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("role", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "assistant": return InternalRealtimeRequestAssistantMessageItem.DeserializeInternalRealtimeRequestAssistantMessageItem(element, options); + case "system": return InternalRealtimeRequestSystemMessageItem.DeserializeInternalRealtimeRequestSystemMessageItem(element, options); + case "user": return InternalRealtimeRequestUserMessageItem.DeserializeInternalRealtimeRequestUserMessageItem(element, options); + } + } + ConversationMessageRole role = "message"; + ConversationItemStatus? status = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new ConversationMessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestMessageItem(type, id, serializedAdditionalRawData, role, status); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestMessageItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestMessageItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestMessageItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestMessageItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestMessageItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestMessageItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestMessageItem.cs b/src/Generated/Models/InternalRealtimeRequestMessageItem.cs new file mode 100644 index 000000000..5bba92cad --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestMessageItem.cs @@ -0,0 +1,26 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestMessageItem : ConversationItem + { + public InternalRealtimeRequestMessageItem() + { + Role = new ConversationMessageRole("message"); + } + + internal InternalRealtimeRequestMessageItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, ConversationMessageRole role, ConversationItemStatus? status) : base(type, id, serializedAdditionalRawData) + { + Role = role; + Status = status; + } + + internal ConversationMessageRole Role { get; set; } + public ConversationItemStatus? Status { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestModel.cs b/src/Generated/Models/InternalRealtimeRequestModel.cs new file mode 100644 index 000000000..b7759dca3 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestModel.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeRequestModel : IEquatable + { + private readonly string _value; + + public InternalRealtimeRequestModel(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string Gpt4oRealtimeValue = "gpt-4o-realtime"; + + public static InternalRealtimeRequestModel Gpt4oRealtime { get; } = new InternalRealtimeRequestModel(Gpt4oRealtimeValue); + public static bool operator ==(InternalRealtimeRequestModel left, InternalRealtimeRequestModel right) => left.Equals(right); + public static bool operator !=(InternalRealtimeRequestModel left, InternalRealtimeRequestModel right) => !left.Equals(right); + public static implicit operator InternalRealtimeRequestModel(string value) => new InternalRealtimeRequestModel(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeRequestModel other && Equals(other); + public bool Equals(InternalRealtimeRequestModel other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.Serialization.cs new file mode 100644 index 000000000..37f4c8d58 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCancelCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCancelCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestResponseCancelCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCancelCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestResponseCancelCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestResponseCancelCommand DeserializeInternalRealtimeRequestResponseCancelCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestResponseCancelCommand(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCancelCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestResponseCancelCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestResponseCancelCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCancelCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestResponseCancelCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestResponseCancelCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.cs b/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.cs new file mode 100644 index 000000000..cb8619e25 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCancelCommand.cs @@ -0,0 +1,21 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCancelCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestResponseCancelCommand() + { + Kind = InternalRealtimeRequestCommandType.ResponseCancel; + } + + internal InternalRealtimeRequestResponseCancelCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.Serialization.cs new file mode 100644 index 000000000..85dbea9cc --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.Serialization.cs @@ -0,0 +1,159 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCreateCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("response") != true && Optional.IsDefined(Response)) + { + writer.WritePropertyName("response"u8); + writer.WriteObjectValue(Response, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestResponseCreateCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestResponseCreateCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestResponseCreateCommand DeserializeInternalRealtimeRequestResponseCreateCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestResponseCreateCommandResponse response = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("response"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + response = InternalRealtimeRequestResponseCreateCommandResponse.DeserializeInternalRealtimeRequestResponseCreateCommandResponse(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestResponseCreateCommand(type, eventId, serializedAdditionalRawData, response); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestResponseCreateCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestResponseCreateCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestResponseCreateCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestResponseCreateCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.cs b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.cs new file mode 100644 index 000000000..f165b617d --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommand.cs @@ -0,0 +1,24 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCreateCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestResponseCreateCommand() + { + Kind = InternalRealtimeRequestCommandType.ResponseCreate; + } + + internal InternalRealtimeRequestResponseCreateCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, InternalRealtimeRequestResponseCreateCommandResponse response) : base(kind, eventId, serializedAdditionalRawData) + { + Response = response; + } + + public InternalRealtimeRequestResponseCreateCommandResponse Response { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.Serialization.cs new file mode 100644 index 000000000..8c1a8332c --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.Serialization.cs @@ -0,0 +1,365 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCreateCommandResponse : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommandResponse)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("commit") != true) + { + writer.WritePropertyName("commit"u8); + writer.WriteBooleanValue(Commit); + } + if (SerializedAdditionalRawData?.ContainsKey("cancel_previous") != true) + { + writer.WritePropertyName("cancel_previous"u8); + writer.WriteBooleanValue(CancelPrevious); + } + if (SerializedAdditionalRawData?.ContainsKey("append_input_items") != true && Optional.IsCollectionDefined(AppendInputItems)) + { + writer.WritePropertyName("append_input_items"u8); + writer.WriteStartArray(); + foreach (var item in AppendInputItems) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("input_items") != true && Optional.IsCollectionDefined(InputItems)) + { + writer.WritePropertyName("input_items"u8); + writer.WriteStartArray(); + foreach (var item in InputItems) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("instructions") != true && Optional.IsDefined(Instructions)) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + if (SerializedAdditionalRawData?.ContainsKey("modalities") != true && Optional.IsCollectionDefined(Modalities)) + { + writer.WritePropertyName("modalities"u8); + writer.WriteStartArray(); + foreach (var item in Modalities) + { + writer.WriteStringValue(item.ToString()); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("voice") != true && Optional.IsDefined(Voice)) + { + writer.WritePropertyName("voice"u8); + writer.WriteStringValue(Voice.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("temperature") != true && Optional.IsDefined(Temperature)) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature.Value); + } + if (SerializedAdditionalRawData?.ContainsKey("max_output_tokens") != true && Optional.IsDefined(MaxOutputTokens)) + { + if (MaxOutputTokens != null) + { + writer.WritePropertyName("max_output_tokens"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(MaxOutputTokens); +#else + using (JsonDocument document = JsonDocument.Parse(MaxOutputTokens)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("max_output_tokens"); + } + } + if (SerializedAdditionalRawData?.ContainsKey("tools") != true && Optional.IsCollectionDefined(Tools)) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("tool_choice") != true && Optional.IsDefined(ToolChoice)) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(ToolChoice)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("output_audio_format") != true && Optional.IsDefined(OutputAudioFormat)) + { + writer.WritePropertyName("output_audio_format"u8); + writer.WriteStringValue(OutputAudioFormat.Value.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestResponseCreateCommandResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommandResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestResponseCreateCommandResponse(document.RootElement, options); + } + + internal static InternalRealtimeRequestResponseCreateCommandResponse DeserializeInternalRealtimeRequestResponseCreateCommandResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + bool commit = default; + bool cancelPrevious = default; + IList appendInputItems = default; + IList inputItems = default; + string instructions = default; + IList modalities = default; + ConversationVoice? voice = default; + float? temperature = default; + BinaryData maxOutputTokens = default; + IList tools = default; + BinaryData toolChoice = default; + ConversationAudioFormat? outputAudioFormat = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("commit"u8)) + { + commit = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("cancel_previous"u8)) + { + cancelPrevious = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("append_input_items"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationItem.DeserializeConversationItem(item, options)); + } + appendInputItems = array; + continue; + } + if (property.NameEquals("input_items"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationItem.DeserializeConversationItem(item, options)); + } + inputItems = array; + continue; + } + if (property.NameEquals("instructions"u8)) + { + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("modalities"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(new InternalRealtimeRequestSessionUpdateCommandSessionModality(item.GetString())); + } + modalities = array; + continue; + } + if (property.NameEquals("voice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + voice = new ConversationVoice(property.Value.GetString()); + continue; + } + if (property.NameEquals("temperature"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_output_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxOutputTokens = null; + continue; + } + maxOutputTokens = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("tools"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationTool.DeserializeConversationTool(item, options)); + } + tools = array; + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("output_audio_format"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + outputAudioFormat = new ConversationAudioFormat(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestResponseCreateCommandResponse( + commit, + cancelPrevious, + appendInputItems ?? new ChangeTrackingList(), + inputItems ?? new ChangeTrackingList(), + instructions, + modalities ?? new ChangeTrackingList(), + voice, + temperature, + maxOutputTokens, + tools ?? new ChangeTrackingList(), + toolChoice, + outputAudioFormat, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommandResponse)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestResponseCreateCommandResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestResponseCreateCommandResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestResponseCreateCommandResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeRequestResponseCreateCommandResponse FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestResponseCreateCommandResponse(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.cs b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.cs new file mode 100644 index 000000000..be05ac0db --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestResponseCreateCommandResponse.cs @@ -0,0 +1,57 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestResponseCreateCommandResponse + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalRealtimeRequestResponseCreateCommandResponse(bool commit, bool cancelPrevious) + { + Commit = commit; + CancelPrevious = cancelPrevious; + AppendInputItems = new ChangeTrackingList(); + InputItems = new ChangeTrackingList(); + Modalities = new ChangeTrackingList(); + Tools = new ChangeTrackingList(); + } + + internal InternalRealtimeRequestResponseCreateCommandResponse(bool commit, bool cancelPrevious, IList appendInputItems, IList inputItems, string instructions, IList modalities, ConversationVoice? voice, float? temperature, BinaryData maxOutputTokens, IList tools, BinaryData toolChoice, ConversationAudioFormat? outputAudioFormat, IDictionary serializedAdditionalRawData) + { + Commit = commit; + CancelPrevious = cancelPrevious; + AppendInputItems = appendInputItems; + InputItems = inputItems; + Instructions = instructions; + Modalities = modalities; + Voice = voice; + Temperature = temperature; + MaxOutputTokens = maxOutputTokens; + Tools = tools; + ToolChoice = toolChoice; + OutputAudioFormat = outputAudioFormat; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeRequestResponseCreateCommandResponse() + { + } + + public bool Commit { get; } + public bool CancelPrevious { get; } + public IList AppendInputItems { get; } + public IList InputItems { get; } + public string Instructions { get; set; } + public IList Modalities { get; } + public ConversationVoice? Voice { get; set; } + public float? Temperature { get; set; } + public BinaryData MaxOutputTokens { get; set; } + public IList Tools { get; } + public BinaryData ToolChoice { get; set; } + public ConversationAudioFormat? OutputAudioFormat { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.Serialization.cs new file mode 100644 index 000000000..1b97a5280 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.Serialization.cs @@ -0,0 +1,155 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestSessionUpdateCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestSessionUpdateCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("session") != true) + { + writer.WritePropertyName("session"u8); + writer.WriteObjectValue(Session, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestSessionUpdateCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestSessionUpdateCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestSessionUpdateCommand(document.RootElement, options); + } + + internal static InternalRealtimeRequestSessionUpdateCommand DeserializeInternalRealtimeRequestSessionUpdateCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationSessionOptions session = default; + InternalRealtimeRequestCommandType type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("session"u8)) + { + session = ConversationSessionOptions.DeserializeConversationSessionOptions(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestSessionUpdateCommand(type, eventId, serializedAdditionalRawData, session); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestSessionUpdateCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestSessionUpdateCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestSessionUpdateCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestSessionUpdateCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestSessionUpdateCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestSessionUpdateCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.cs b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.cs new file mode 100644 index 000000000..d014ae106 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommand.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestSessionUpdateCommand : InternalRealtimeRequestCommand + { + public InternalRealtimeRequestSessionUpdateCommand(ConversationSessionOptions session) + { + Argument.AssertNotNull(session, nameof(session)); + + Kind = InternalRealtimeRequestCommandType.SessionUpdate; + Session = session; + } + + internal InternalRealtimeRequestSessionUpdateCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData, ConversationSessionOptions session) : base(kind, eventId, serializedAdditionalRawData) + { + Session = session; + } + + internal InternalRealtimeRequestSessionUpdateCommand() + { + } + + public ConversationSessionOptions Session { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommandSessionModality.cs b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommandSessionModality.cs new file mode 100644 index 000000000..234800a29 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestSessionUpdateCommandSessionModality.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeRequestSessionUpdateCommandSessionModality : IEquatable + { + private readonly string _value; + + public InternalRealtimeRequestSessionUpdateCommandSessionModality(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TextValue = "text"; + private const string AudioValue = "audio"; + + public static InternalRealtimeRequestSessionUpdateCommandSessionModality Text { get; } = new InternalRealtimeRequestSessionUpdateCommandSessionModality(TextValue); + public static InternalRealtimeRequestSessionUpdateCommandSessionModality Audio { get; } = new InternalRealtimeRequestSessionUpdateCommandSessionModality(AudioValue); + public static bool operator ==(InternalRealtimeRequestSessionUpdateCommandSessionModality left, InternalRealtimeRequestSessionUpdateCommandSessionModality right) => left.Equals(right); + public static bool operator !=(InternalRealtimeRequestSessionUpdateCommandSessionModality left, InternalRealtimeRequestSessionUpdateCommandSessionModality right) => !left.Equals(right); + public static implicit operator InternalRealtimeRequestSessionUpdateCommandSessionModality(string value) => new InternalRealtimeRequestSessionUpdateCommandSessionModality(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeRequestSessionUpdateCommandSessionModality other && Equals(other); + public bool Equals(InternalRealtimeRequestSessionUpdateCommandSessionModality other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.Serialization.cs new file mode 100644 index 000000000..e530bc5da --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.Serialization.cs @@ -0,0 +1,197 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestSystemMessageItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestSystemMessageItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("content") != true) + { + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("role") != true) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true && Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestSystemMessageItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestSystemMessageItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestSystemMessageItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestSystemMessageItem DeserializeInternalRealtimeRequestSystemMessageItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList content = default; + ConversationMessageRole role = default; + ConversationItemStatus? status = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationContentPart.DeserializeConversationContentPart(item, options)); + } + content = array; + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ConversationMessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestSystemMessageItem( + type, + id, + serializedAdditionalRawData, + role, + status, + content); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestSystemMessageItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestSystemMessageItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestSystemMessageItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestSystemMessageItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestSystemMessageItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestSystemMessageItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.cs b/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.cs new file mode 100644 index 000000000..f2879fd19 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestSystemMessageItem.cs @@ -0,0 +1,30 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestSystemMessageItem : InternalRealtimeRequestMessageItem + { + public InternalRealtimeRequestSystemMessageItem(IEnumerable content) + { + Argument.AssertNotNull(content, nameof(content)); + + Role = ConversationMessageRole.System; + Content = content.ToList(); + } + + internal InternalRealtimeRequestSystemMessageItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, ConversationMessageRole role, ConversationItemStatus? status, IList content) : base(type, id, serializedAdditionalRawData, role, status) + { + Content = content; + } + + internal InternalRealtimeRequestSystemMessageItem() + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestTextContentPart.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestTextContentPart.Serialization.cs new file mode 100644 index 000000000..2398c8964 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestTextContentPart.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestTextContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestTextContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("text") != true) + { + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestTextContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestTextContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestTextContentPart(document.RootElement, options); + } + + internal static InternalRealtimeRequestTextContentPart DeserializeInternalRealtimeRequestTextContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string text = default; + ConversationContentPartKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationContentPartKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestTextContentPart(type, serializedAdditionalRawData, text); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestTextContentPart)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestTextContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestTextContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestTextContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestTextContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestTextContentPart(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestTextContentPart.cs b/src/Generated/Models/InternalRealtimeRequestTextContentPart.cs new file mode 100644 index 000000000..243370e65 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestTextContentPart.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestTextContentPart : ConversationContentPart + { + public InternalRealtimeRequestTextContentPart(string text) + { + Argument.AssertNotNull(text, nameof(text)); + + Type = ConversationContentPartKind.InputText; + Text = text; + } + + internal InternalRealtimeRequestTextContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData, string text) : base(type, serializedAdditionalRawData) + { + Text = text; + } + + internal InternalRealtimeRequestTextContentPart() + { + } + + public string Text { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestUserMessageItem.Serialization.cs b/src/Generated/Models/InternalRealtimeRequestUserMessageItem.Serialization.cs new file mode 100644 index 000000000..42026d8ac --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestUserMessageItem.Serialization.cs @@ -0,0 +1,197 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestUserMessageItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestUserMessageItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("content") != true) + { + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("role") != true) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true && Optional.IsDefined(Status)) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.Value.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestUserMessageItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestUserMessageItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestUserMessageItem(document.RootElement, options); + } + + internal static InternalRealtimeRequestUserMessageItem DeserializeInternalRealtimeRequestUserMessageItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + IList content = default; + ConversationMessageRole role = default; + ConversationItemStatus? status = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationContentPart.DeserializeConversationContentPart(item, options)); + } + content = array; + continue; + } + if (property.NameEquals("role"u8)) + { + role = new ConversationMessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("status"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeRequestUserMessageItem( + type, + id, + serializedAdditionalRawData, + role, + status, + content); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestUserMessageItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestUserMessageItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestUserMessageItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestUserMessageItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeRequestUserMessageItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeRequestUserMessageItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeRequestUserMessageItem.cs b/src/Generated/Models/InternalRealtimeRequestUserMessageItem.cs new file mode 100644 index 000000000..9fa213483 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeRequestUserMessageItem.cs @@ -0,0 +1,22 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeRequestUserMessageItem : InternalRealtimeRequestMessageItem + { + internal InternalRealtimeRequestUserMessageItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, ConversationMessageRole role, ConversationItemStatus? status, IList content) : base(type, id, serializedAdditionalRawData, role, status) + { + Content = content; + } + + internal InternalRealtimeRequestUserMessageItem() + { + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponse.Serialization.cs b/src/Generated/Models/InternalRealtimeResponse.Serialization.cs new file mode 100644 index 000000000..8c94b962f --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponse.Serialization.cs @@ -0,0 +1,217 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponse : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponse)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("status_details") != true) + { + if (StatusDetails != null) + { + writer.WritePropertyName("status_details"u8); + writer.WriteObjectValue(StatusDetails, options); + } + else + { + writer.WriteNull("status_details"); + } + } + if (SerializedAdditionalRawData?.ContainsKey("output") != true) + { + writer.WritePropertyName("output"u8); + writer.WriteStartArray(); + foreach (var item in Output) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("usage") != true) + { + writer.WritePropertyName("usage"u8); + writer.WriteObjectValue(Usage, options); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponse IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponse)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponse(document.RootElement, options); + } + + internal static InternalRealtimeResponse DeserializeInternalRealtimeResponse(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseObject @object = default; + string id = default; + ConversationStatus status = default; + InternalRealtimeResponseStatusDetails statusDetails = default; + IReadOnlyList output = default; + ConversationTokenUsage usage = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new ConversationStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("status_details"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + statusDetails = null; + continue; + } + statusDetails = InternalRealtimeResponseStatusDetails.DeserializeInternalRealtimeResponseStatusDetails(property.Value, options); + continue; + } + if (property.NameEquals("output"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationItem.DeserializeConversationItem(item, options)); + } + output = array; + continue; + } + if (property.NameEquals("usage"u8)) + { + usage = ConversationTokenUsage.DeserializeConversationTokenUsage(property.Value, options); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponse( + @object, + id, + status, + statusDetails, + output, + usage, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponse)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponse IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponse(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponse)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponse FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponse(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponse.cs b/src/Generated/Models/InternalRealtimeResponse.cs new file mode 100644 index 000000000..73cd76214 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponse.cs @@ -0,0 +1,49 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponse + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalRealtimeResponse(string id, ConversationStatus status, InternalRealtimeResponseStatusDetails statusDetails, IEnumerable output, ConversationTokenUsage usage) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(output, nameof(output)); + Argument.AssertNotNull(usage, nameof(usage)); + + Id = id; + Status = status; + StatusDetails = statusDetails; + Output = output.ToList(); + Usage = usage; + } + + internal InternalRealtimeResponse(InternalRealtimeResponseObject @object, string id, ConversationStatus status, InternalRealtimeResponseStatusDetails statusDetails, IReadOnlyList output, ConversationTokenUsage usage, IDictionary serializedAdditionalRawData) + { + Object = @object; + Id = id; + Status = status; + StatusDetails = statusDetails; + Output = output; + Usage = usage; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeResponse() + { + } + + public InternalRealtimeResponseObject Object { get; } = InternalRealtimeResponseObject.RealtimeResponse; + + public string Id { get; } + public ConversationStatus Status { get; } + public InternalRealtimeResponseStatusDetails StatusDetails { get; } + public ConversationTokenUsage Usage { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseApiError.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseApiError.Serialization.cs new file mode 100644 index 000000000..fc4fc5e8e --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseApiError.Serialization.cs @@ -0,0 +1,166 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseApiError : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseApiError)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData?.ContainsKey("code") != true && Optional.IsDefined(Code)) + { + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code); + } + if (SerializedAdditionalRawData?.ContainsKey("message") != true) + { + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + } + if (SerializedAdditionalRawData?.ContainsKey("param") != true && Optional.IsDefined(Param)) + { + writer.WritePropertyName("param"u8); + writer.WriteStringValue(Param); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseApiError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseApiError)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseApiError(document.RootElement, options); + } + + internal static InternalRealtimeResponseApiError DeserializeInternalRealtimeResponseApiError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + string code = default; + string message = default; + string param = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("code"u8)) + { + code = property.Value.GetString(); + continue; + } + if (property.NameEquals("message"u8)) + { + message = property.Value.GetString(); + continue; + } + if (property.NameEquals("param"u8)) + { + param = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseApiError(type, code, message, param, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseApiError)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseApiError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseApiError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseApiError)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponseApiError FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseApiError(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseApiError.cs b/src/Generated/Models/InternalRealtimeResponseApiError.cs new file mode 100644 index 000000000..337315fb8 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseApiError.cs @@ -0,0 +1,40 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseApiError + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalRealtimeResponseApiError(string type, string message) + { + Argument.AssertNotNull(type, nameof(type)); + Argument.AssertNotNull(message, nameof(message)); + + Type = type; + Message = message; + } + + internal InternalRealtimeResponseApiError(string type, string code, string message, string param, IDictionary serializedAdditionalRawData) + { + Type = type; + Code = code; + Message = message; + Param = param; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeResponseApiError() + { + } + + public string Type { get; } + public string Code { get; } + public string Message { get; } + public string Param { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseAudioContentPart.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseAudioContentPart.Serialization.cs new file mode 100644 index 000000000..8324139d0 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseAudioContentPart.Serialization.cs @@ -0,0 +1,156 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseAudioContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseAudioContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("transcript") != true) + { + if (Transcript != null) + { + writer.WritePropertyName("transcript"u8); + writer.WriteStringValue(Transcript); + } + else + { + writer.WriteNull("transcript"); + } + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseAudioContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseAudioContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseAudioContentPart(document.RootElement, options); + } + + internal static InternalRealtimeResponseAudioContentPart DeserializeInternalRealtimeResponseAudioContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string transcript = default; + ConversationContentPartKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("transcript"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + transcript = null; + continue; + } + transcript = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationContentPartKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseAudioContentPart(type, serializedAdditionalRawData, transcript); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseAudioContentPart)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseAudioContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseAudioContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseAudioContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseAudioContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseAudioContentPart(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseAudioContentPart.cs b/src/Generated/Models/InternalRealtimeResponseAudioContentPart.cs new file mode 100644 index 000000000..076fe2b0e --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseAudioContentPart.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseAudioContentPart : ConversationContentPart + { + internal InternalRealtimeResponseAudioContentPart(string transcript) + { + Type = ConversationContentPartKind.Audio; + Transcript = transcript; + } + + internal InternalRealtimeResponseAudioContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData, string transcript) : base(type, serializedAdditionalRawData) + { + Transcript = transcript; + } + + internal InternalRealtimeResponseAudioContentPart() + { + } + + public string Transcript { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.Serialization.cs new file mode 100644 index 000000000..bd29cb9f7 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseCancelledStatusDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseCancelledStatusDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("reason") != true) + { + writer.WritePropertyName("reason"u8); + writer.WriteStringValue(Reason.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseCancelledStatusDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseCancelledStatusDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseCancelledStatusDetails(document.RootElement, options); + } + + internal static InternalRealtimeResponseCancelledStatusDetails DeserializeInternalRealtimeResponseCancelledStatusDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseCancelledStatusDetailsReason reason = default; + ConversationStatus type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("reason"u8)) + { + reason = new InternalRealtimeResponseCancelledStatusDetailsReason(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationStatus(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseCancelledStatusDetails(type, serializedAdditionalRawData, reason); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseCancelledStatusDetails)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseCancelledStatusDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseCancelledStatusDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseCancelledStatusDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseCancelledStatusDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseCancelledStatusDetails(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.cs b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.cs new file mode 100644 index 000000000..054b0e850 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetails.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseCancelledStatusDetails : InternalRealtimeResponseStatusDetails + { + internal InternalRealtimeResponseCancelledStatusDetails(InternalRealtimeResponseCancelledStatusDetailsReason reason) + { + Type = ConversationStatus.Cancelled; + Reason = reason; + } + + internal InternalRealtimeResponseCancelledStatusDetails(ConversationStatus type, IDictionary serializedAdditionalRawData, InternalRealtimeResponseCancelledStatusDetailsReason reason) : base(type, serializedAdditionalRawData) + { + Reason = reason; + } + + internal InternalRealtimeResponseCancelledStatusDetails() + { + } + + public InternalRealtimeResponseCancelledStatusDetailsReason Reason { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetailsReason.cs b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetailsReason.cs new file mode 100644 index 000000000..00bb14ba5 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseCancelledStatusDetailsReason.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeResponseCancelledStatusDetailsReason : IEquatable + { + private readonly string _value; + + public InternalRealtimeResponseCancelledStatusDetailsReason(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string TurnDetectedValue = "turn_detected"; + private const string ClientCancelledValue = "client_cancelled"; + + public static InternalRealtimeResponseCancelledStatusDetailsReason TurnDetected { get; } = new InternalRealtimeResponseCancelledStatusDetailsReason(TurnDetectedValue); + public static InternalRealtimeResponseCancelledStatusDetailsReason ClientCancelled { get; } = new InternalRealtimeResponseCancelledStatusDetailsReason(ClientCancelledValue); + public static bool operator ==(InternalRealtimeResponseCancelledStatusDetailsReason left, InternalRealtimeResponseCancelledStatusDetailsReason right) => left.Equals(right); + public static bool operator !=(InternalRealtimeResponseCancelledStatusDetailsReason left, InternalRealtimeResponseCancelledStatusDetailsReason right) => !left.Equals(right); + public static implicit operator InternalRealtimeResponseCancelledStatusDetailsReason(string value) => new InternalRealtimeResponseCancelledStatusDetailsReason(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeResponseCancelledStatusDetailsReason other && Equals(other); + public bool Equals(InternalRealtimeResponseCancelledStatusDetailsReason other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseError.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseError.Serialization.cs new file mode 100644 index 000000000..2d2473b76 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseError.Serialization.cs @@ -0,0 +1,183 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseError : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseError)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type); + } + if (SerializedAdditionalRawData?.ContainsKey("code") != true && Optional.IsDefined(Code)) + { + writer.WritePropertyName("code"u8); + writer.WriteStringValue(Code); + } + if (SerializedAdditionalRawData?.ContainsKey("message") != true) + { + writer.WritePropertyName("message"u8); + writer.WriteStringValue(Message); + } + if (SerializedAdditionalRawData?.ContainsKey("param") != true && Optional.IsDefined(Param)) + { + writer.WritePropertyName("param"u8); + writer.WriteStringValue(Param); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseError IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseError)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseError(document.RootElement, options); + } + + internal static InternalRealtimeResponseError DeserializeInternalRealtimeResponseError(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string type = default; + string code = default; + string message = default; + string param = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString(); + continue; + } + if (property.NameEquals("code"u8)) + { + code = property.Value.GetString(); + continue; + } + if (property.NameEquals("message"u8)) + { + message = property.Value.GetString(); + continue; + } + if (property.NameEquals("param"u8)) + { + param = property.Value.GetString(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseError( + type, + code, + message, + param, + eventId, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseError)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseError IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseError(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseError)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponseError FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseError(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseError.cs b/src/Generated/Models/InternalRealtimeResponseError.cs new file mode 100644 index 000000000..c2fec5fd4 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseError.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseError + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalRealtimeResponseError(string type, string message) + { + Argument.AssertNotNull(type, nameof(type)); + Argument.AssertNotNull(message, nameof(message)); + + Type = type; + Message = message; + } + + internal InternalRealtimeResponseError(string type, string code, string message, string param, string eventId, IDictionary serializedAdditionalRawData) + { + Type = type; + Code = code; + Message = message; + Param = param; + EventId = eventId; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeResponseError() + { + } + + public string Type { get; } + public string Code { get; } + public string Message { get; } + public string Param { get; } + public string EventId { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.Serialization.cs new file mode 100644 index 000000000..0f63fd37b --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.Serialization.cs @@ -0,0 +1,219 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseFunctionCallItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("arguments") != true) + { + writer.WritePropertyName("arguments"u8); + writer.WriteStringValue(Arguments); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + if (Id != null) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + else + { + writer.WriteNull("id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseFunctionCallItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseFunctionCallItem(document.RootElement, options); + } + + internal static InternalRealtimeResponseFunctionCallItem DeserializeInternalRealtimeResponseFunctionCallItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + string callId = default; + string arguments = default; + ConversationItemStatus status = default; + InternalRealtimeResponseItemObject @object = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("arguments"u8)) + { + arguments = property.Value.GetString(); + continue; + } + if (property.NameEquals("status"u8)) + { + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseItemObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + id = null; + continue; + } + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseFunctionCallItem( + @object, + type, + id, + serializedAdditionalRawData, + name, + callId, + arguments, + status); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseFunctionCallItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseFunctionCallItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseFunctionCallItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseFunctionCallItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.cs b/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.cs new file mode 100644 index 000000000..98a28e33a --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseFunctionCallItem.cs @@ -0,0 +1,42 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseFunctionCallItem : InternalRealtimeResponseItem + { + internal InternalRealtimeResponseFunctionCallItem(string id, string name, string callId, string arguments, ConversationItemStatus status) : base(id) + { + Argument.AssertNotNull(name, nameof(name)); + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(arguments, nameof(arguments)); + + Type = InternalRealtimeRequestItemType.FunctionCall; + Name = name; + CallId = callId; + Arguments = arguments; + Status = status; + } + + internal InternalRealtimeResponseFunctionCallItem(InternalRealtimeResponseItemObject @object, InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, string name, string callId, string arguments, ConversationItemStatus status) : base(@object, type, id, serializedAdditionalRawData) + { + Name = name; + CallId = callId; + Arguments = arguments; + Status = status; + } + + internal InternalRealtimeResponseFunctionCallItem() + { + } + + public string Name { get; } + public string CallId { get; } + public string Arguments { get; } + public ConversationItemStatus Status { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.Serialization.cs new file mode 100644 index 000000000..a995663e2 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.Serialization.cs @@ -0,0 +1,195 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseFunctionCallOutputItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallOutputItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("call_id") != true) + { + writer.WritePropertyName("call_id"u8); + writer.WriteStringValue(CallId); + } + if (SerializedAdditionalRawData?.ContainsKey("output") != true) + { + writer.WritePropertyName("output"u8); + writer.WriteStringValue(Output); + } + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + if (Id != null) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + else + { + writer.WriteNull("id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseFunctionCallOutputItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallOutputItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseFunctionCallOutputItem(document.RootElement, options); + } + + internal static InternalRealtimeResponseFunctionCallOutputItem DeserializeInternalRealtimeResponseFunctionCallOutputItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string callId = default; + string output = default; + InternalRealtimeResponseItemObject @object = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("call_id"u8)) + { + callId = property.Value.GetString(); + continue; + } + if (property.NameEquals("output"u8)) + { + output = property.Value.GetString(); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseItemObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + id = null; + continue; + } + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseFunctionCallOutputItem( + @object, + type, + id, + serializedAdditionalRawData, + callId, + output); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallOutputItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseFunctionCallOutputItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseFunctionCallOutputItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseFunctionCallOutputItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseFunctionCallOutputItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseFunctionCallOutputItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.cs b/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.cs new file mode 100644 index 000000000..ae62c1e28 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseFunctionCallOutputItem.cs @@ -0,0 +1,35 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseFunctionCallOutputItem : InternalRealtimeResponseItem + { + internal InternalRealtimeResponseFunctionCallOutputItem(string id, string callId, string output) : base(id) + { + Argument.AssertNotNull(callId, nameof(callId)); + Argument.AssertNotNull(output, nameof(output)); + + Type = InternalRealtimeRequestItemType.FunctionCallOutput; + CallId = callId; + Output = output; + } + + internal InternalRealtimeResponseFunctionCallOutputItem(InternalRealtimeResponseItemObject @object, InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, string callId, string output) : base(@object, type, id, serializedAdditionalRawData) + { + CallId = callId; + Output = output; + } + + internal InternalRealtimeResponseFunctionCallOutputItem() + { + } + + public string CallId { get; } + public string Output { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.Serialization.cs new file mode 100644 index 000000000..f1030c8cb --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseIncompleteStatusDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseIncompleteStatusDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("reason") != true) + { + writer.WritePropertyName("reason"u8); + writer.WriteStringValue(Reason.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseIncompleteStatusDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseIncompleteStatusDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseIncompleteStatusDetails(document.RootElement, options); + } + + internal static InternalRealtimeResponseIncompleteStatusDetails DeserializeInternalRealtimeResponseIncompleteStatusDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseIncompleteStatusDetailsReason reason = default; + ConversationStatus type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("reason"u8)) + { + reason = new InternalRealtimeResponseIncompleteStatusDetailsReason(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationStatus(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseIncompleteStatusDetails(type, serializedAdditionalRawData, reason); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseIncompleteStatusDetails)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseIncompleteStatusDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseIncompleteStatusDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseIncompleteStatusDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseIncompleteStatusDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseIncompleteStatusDetails(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.cs b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.cs new file mode 100644 index 000000000..24b55f81c --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetails.cs @@ -0,0 +1,29 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseIncompleteStatusDetails : InternalRealtimeResponseStatusDetails + { + internal InternalRealtimeResponseIncompleteStatusDetails(InternalRealtimeResponseIncompleteStatusDetailsReason reason) + { + Type = ConversationStatus.Incomplete; + Reason = reason; + } + + internal InternalRealtimeResponseIncompleteStatusDetails(ConversationStatus type, IDictionary serializedAdditionalRawData, InternalRealtimeResponseIncompleteStatusDetailsReason reason) : base(type, serializedAdditionalRawData) + { + Reason = reason; + } + + internal InternalRealtimeResponseIncompleteStatusDetails() + { + } + + public InternalRealtimeResponseIncompleteStatusDetailsReason Reason { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetailsReason.cs b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetailsReason.cs new file mode 100644 index 000000000..9bf8c7d63 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseIncompleteStatusDetailsReason.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeResponseIncompleteStatusDetailsReason : IEquatable + { + private readonly string _value; + + public InternalRealtimeResponseIncompleteStatusDetailsReason(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string MaxOutputTokensValue = "max_output_tokens"; + private const string ContentFilterValue = "content_filter"; + + public static InternalRealtimeResponseIncompleteStatusDetailsReason MaxOutputTokens { get; } = new InternalRealtimeResponseIncompleteStatusDetailsReason(MaxOutputTokensValue); + public static InternalRealtimeResponseIncompleteStatusDetailsReason ContentFilter { get; } = new InternalRealtimeResponseIncompleteStatusDetailsReason(ContentFilterValue); + public static bool operator ==(InternalRealtimeResponseIncompleteStatusDetailsReason left, InternalRealtimeResponseIncompleteStatusDetailsReason right) => left.Equals(right); + public static bool operator !=(InternalRealtimeResponseIncompleteStatusDetailsReason left, InternalRealtimeResponseIncompleteStatusDetailsReason right) => !left.Equals(right); + public static implicit operator InternalRealtimeResponseIncompleteStatusDetailsReason(string value) => new InternalRealtimeResponseIncompleteStatusDetailsReason(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeResponseIncompleteStatusDetailsReason other && Equals(other); + public bool Equals(InternalRealtimeResponseIncompleteStatusDetailsReason other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseItem.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseItem.Serialization.cs new file mode 100644 index 000000000..3301880e3 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseItem.Serialization.cs @@ -0,0 +1,142 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeResponseItem))] + internal partial class InternalRealtimeResponseItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + if (Id != null) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + else + { + writer.WriteNull("id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseItem(document.RootElement, options); + } + + internal static InternalRealtimeResponseItem DeserializeInternalRealtimeResponseItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function_call": return InternalRealtimeResponseFunctionCallItem.DeserializeInternalRealtimeResponseFunctionCallItem(element, options); + case "function_call_output": return InternalRealtimeResponseFunctionCallOutputItem.DeserializeInternalRealtimeResponseFunctionCallOutputItem(element, options); + case "message": return InternalRealtimeResponseMessageItem.DeserializeInternalRealtimeResponseMessageItem(element, options); + } + } + return UnknownRealtimeResponseItem.DeserializeUnknownRealtimeResponseItem(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponseItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseItem(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseItem.cs b/src/Generated/Models/InternalRealtimeResponseItem.cs new file mode 100644 index 000000000..9a04f907c --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseItem.cs @@ -0,0 +1,35 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal abstract partial class InternalRealtimeResponseItem + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected InternalRealtimeResponseItem(string id) + { + Id = id; + } + + internal InternalRealtimeResponseItem(InternalRealtimeResponseItemObject @object, InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData) + { + Object = @object; + Type = type; + Id = id; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeResponseItem() + { + } + + public InternalRealtimeResponseItemObject Object { get; } = InternalRealtimeResponseItemObject.RealtimeItem; + + internal InternalRealtimeRequestItemType Type { get; set; } + public string Id { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseItemObject.cs b/src/Generated/Models/InternalRealtimeResponseItemObject.cs new file mode 100644 index 000000000..fed455fcd --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseItemObject.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeResponseItemObject : IEquatable + { + private readonly string _value; + + public InternalRealtimeResponseItemObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RealtimeItemValue = "realtime.item"; + + public static InternalRealtimeResponseItemObject RealtimeItem { get; } = new InternalRealtimeResponseItemObject(RealtimeItemValue); + public static bool operator ==(InternalRealtimeResponseItemObject left, InternalRealtimeResponseItemObject right) => left.Equals(right); + public static bool operator !=(InternalRealtimeResponseItemObject left, InternalRealtimeResponseItemObject right) => !left.Equals(right); + public static implicit operator InternalRealtimeResponseItemObject(string value) => new InternalRealtimeResponseItemObject(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeResponseItemObject other && Equals(other); + public bool Equals(InternalRealtimeResponseItemObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseMessageItem.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseMessageItem.Serialization.cs new file mode 100644 index 000000000..b8feb0ab3 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseMessageItem.Serialization.cs @@ -0,0 +1,217 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseMessageItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseMessageItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("role") != true) + { + writer.WritePropertyName("role"u8); + writer.WriteStringValue(Role.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("content") != true) + { + writer.WritePropertyName("content"u8); + writer.WriteStartArray(); + foreach (var item in Content) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("status") != true) + { + writer.WritePropertyName("status"u8); + writer.WriteStringValue(Status.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + if (Id != null) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + else + { + writer.WriteNull("id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseMessageItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseMessageItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseMessageItem(document.RootElement, options); + } + + internal static InternalRealtimeResponseMessageItem DeserializeInternalRealtimeResponseMessageItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationMessageRole role = default; + IReadOnlyList content = default; + ConversationItemStatus status = default; + InternalRealtimeResponseItemObject @object = default; + InternalRealtimeRequestItemType type = default; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("role"u8)) + { + role = new ConversationMessageRole(property.Value.GetString()); + continue; + } + if (property.NameEquals("content"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationContentPart.DeserializeConversationContentPart(item, options)); + } + content = array; + continue; + } + if (property.NameEquals("status"u8)) + { + status = new ConversationItemStatus(property.Value.GetString()); + continue; + } + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseItemObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + id = null; + continue; + } + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseMessageItem( + @object, + type, + id, + serializedAdditionalRawData, + role, + content, + status); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseMessageItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseMessageItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseMessageItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseMessageItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseMessageItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseMessageItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseMessageItem.cs b/src/Generated/Models/InternalRealtimeResponseMessageItem.cs new file mode 100644 index 000000000..510f6505b --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseMessageItem.cs @@ -0,0 +1,36 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseMessageItem : InternalRealtimeResponseItem + { + internal InternalRealtimeResponseMessageItem(string id, ConversationMessageRole role, IEnumerable content, ConversationItemStatus status) : base(id) + { + Argument.AssertNotNull(content, nameof(content)); + + Type = InternalRealtimeRequestItemType.Message; + Role = role; + Content = content.ToList(); + Status = status; + } + + internal InternalRealtimeResponseMessageItem(InternalRealtimeResponseItemObject @object, InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData, ConversationMessageRole role, IReadOnlyList content, ConversationItemStatus status) : base(@object, type, id, serializedAdditionalRawData) + { + Role = role; + Content = content; + Status = status; + } + + internal InternalRealtimeResponseMessageItem() + { + } + public IReadOnlyList Content { get; } + public ConversationItemStatus Status { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseObject.cs b/src/Generated/Models/InternalRealtimeResponseObject.cs new file mode 100644 index 000000000..66f2080fc --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseObject.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeResponseObject : IEquatable + { + private readonly string _value; + + public InternalRealtimeResponseObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RealtimeResponseValue = "realtime.response"; + + public static InternalRealtimeResponseObject RealtimeResponse { get; } = new InternalRealtimeResponseObject(RealtimeResponseValue); + public static bool operator ==(InternalRealtimeResponseObject left, InternalRealtimeResponseObject right) => left.Equals(right); + public static bool operator !=(InternalRealtimeResponseObject left, InternalRealtimeResponseObject right) => !left.Equals(right); + public static implicit operator InternalRealtimeResponseObject(string value) => new InternalRealtimeResponseObject(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeResponseObject other && Equals(other); + public bool Equals(InternalRealtimeResponseObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseSession.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseSession.Serialization.cs new file mode 100644 index 000000000..1388cbabc --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseSession.Serialization.cs @@ -0,0 +1,349 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseSession : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseSession)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData?.ContainsKey("model") != true) + { + writer.WritePropertyName("model"u8); + writer.WriteStringValue(Model); + } + if (SerializedAdditionalRawData?.ContainsKey("modalities") != true) + { + writer.WritePropertyName("modalities"u8); + writer.WriteStartArray(); + foreach (var item in Modalities) + { + writer.WriteStringValue(item.ToString()); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("instructions") != true) + { + writer.WritePropertyName("instructions"u8); + writer.WriteStringValue(Instructions); + } + if (SerializedAdditionalRawData?.ContainsKey("voice") != true) + { + writer.WritePropertyName("voice"u8); + writer.WriteStringValue(Voice.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("input_audio_format") != true) + { + writer.WritePropertyName("input_audio_format"u8); + writer.WriteStringValue(InputAudioFormat.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("output_audio_format") != true) + { + writer.WritePropertyName("output_audio_format"u8); + writer.WriteStringValue(OutputAudioFormat.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("input_audio_transcription") != true) + { + if (InputAudioTranscription != null) + { + writer.WritePropertyName("input_audio_transcription"u8); + writer.WriteObjectValue(InputAudioTranscription, options); + } + else + { + writer.WriteNull("input_audio_transcription"); + } + } + if (SerializedAdditionalRawData?.ContainsKey("turn_detection") != true) + { + writer.WritePropertyName("turn_detection"u8); + writer.WriteObjectValue(TurnDetection, options); + } + if (SerializedAdditionalRawData?.ContainsKey("tools") != true) + { + writer.WritePropertyName("tools"u8); + writer.WriteStartArray(); + foreach (var item in Tools) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (SerializedAdditionalRawData?.ContainsKey("tool_choice") != true) + { + writer.WritePropertyName("tool_choice"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(ToolChoice); +#else + using (JsonDocument document = JsonDocument.Parse(ToolChoice)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("temperature") != true) + { + writer.WritePropertyName("temperature"u8); + writer.WriteNumberValue(Temperature); + } + if (SerializedAdditionalRawData?.ContainsKey("max_response_output_tokens") != true) + { + if (_maxResponseOutputTokens != null) + { + writer.WritePropertyName("max_response_output_tokens"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(_maxResponseOutputTokens); +#else + using (JsonDocument document = JsonDocument.Parse(_maxResponseOutputTokens)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + else + { + writer.WriteNull("max_response_output_tokens"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseSession IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseSession)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseSession(document.RootElement, options); + } + + internal static InternalRealtimeResponseSession DeserializeInternalRealtimeResponseSession(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseSessionObject @object = default; + string id = default; + string model = default; + IReadOnlyList modalities = default; + string instructions = default; + ConversationVoice voice = default; + ConversationAudioFormat inputAudioFormat = default; + ConversationAudioFormat outputAudioFormat = default; + ConversationInputTranscriptionOptions inputAudioTranscription = default; + ConversationTurnDetectionOptions turnDetection = default; + IReadOnlyList tools = default; + BinaryData toolChoice = default; + float temperature = default; + BinaryData maxResponseOutputTokens = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseSessionObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (property.NameEquals("model"u8)) + { + model = property.Value.GetString(); + continue; + } + if (property.NameEquals("modalities"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(new InternalRealtimeRequestSessionUpdateCommandSessionModality(item.GetString())); + } + modalities = array; + continue; + } + if (property.NameEquals("instructions"u8)) + { + instructions = property.Value.GetString(); + continue; + } + if (property.NameEquals("voice"u8)) + { + voice = new ConversationVoice(property.Value.GetString()); + continue; + } + if (property.NameEquals("input_audio_format"u8)) + { + inputAudioFormat = new ConversationAudioFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("output_audio_format"u8)) + { + outputAudioFormat = new ConversationAudioFormat(property.Value.GetString()); + continue; + } + if (property.NameEquals("input_audio_transcription"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + inputAudioTranscription = null; + continue; + } + inputAudioTranscription = ConversationInputTranscriptionOptions.DeserializeConversationInputTranscriptionOptions(property.Value, options); + continue; + } + if (property.NameEquals("turn_detection"u8)) + { + turnDetection = ConversationTurnDetectionOptions.DeserializeConversationTurnDetectionOptions(property.Value, options); + continue; + } + if (property.NameEquals("tools"u8)) + { + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(ConversationTool.DeserializeConversationTool(item, options)); + } + tools = array; + continue; + } + if (property.NameEquals("tool_choice"u8)) + { + toolChoice = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("temperature"u8)) + { + temperature = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("max_response_output_tokens"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + maxResponseOutputTokens = null; + continue; + } + maxResponseOutputTokens = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseSession( + @object, + id, + model, + modalities, + instructions, + voice, + inputAudioFormat, + outputAudioFormat, + inputAudioTranscription, + turnDetection, + tools, + toolChoice, + temperature, + maxResponseOutputTokens, + serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseSession)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseSession IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseSession(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseSession)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponseSession FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseSession(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseSession.cs b/src/Generated/Models/InternalRealtimeResponseSession.cs new file mode 100644 index 000000000..a35d2544b --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseSession.cs @@ -0,0 +1,77 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseSession + { + internal IDictionary SerializedAdditionalRawData { get; set; } + internal InternalRealtimeResponseSession(string id, string model, IEnumerable modalities, string instructions, ConversationVoice voice, ConversationAudioFormat inputAudioFormat, ConversationAudioFormat outputAudioFormat, ConversationInputTranscriptionOptions inputAudioTranscription, ConversationTurnDetectionOptions turnDetection, IEnumerable tools, BinaryData toolChoice, float temperature, BinaryData maxResponseOutputTokens) + { + Argument.AssertNotNull(id, nameof(id)); + Argument.AssertNotNull(model, nameof(model)); + Argument.AssertNotNull(modalities, nameof(modalities)); + Argument.AssertNotNull(instructions, nameof(instructions)); + Argument.AssertNotNull(turnDetection, nameof(turnDetection)); + Argument.AssertNotNull(tools, nameof(tools)); + Argument.AssertNotNull(toolChoice, nameof(toolChoice)); + + Id = id; + Model = model; + Modalities = modalities.ToList(); + Instructions = instructions; + Voice = voice; + InputAudioFormat = inputAudioFormat; + OutputAudioFormat = outputAudioFormat; + InputAudioTranscription = inputAudioTranscription; + TurnDetection = turnDetection; + Tools = tools.ToList(); + ToolChoice = toolChoice; + Temperature = temperature; + _maxResponseOutputTokens = maxResponseOutputTokens; + } + + internal InternalRealtimeResponseSession(InternalRealtimeResponseSessionObject @object, string id, string model, IReadOnlyList modalities, string instructions, ConversationVoice voice, ConversationAudioFormat inputAudioFormat, ConversationAudioFormat outputAudioFormat, ConversationInputTranscriptionOptions inputAudioTranscription, ConversationTurnDetectionOptions turnDetection, IReadOnlyList tools, BinaryData toolChoice, float temperature, BinaryData maxResponseOutputTokens, IDictionary serializedAdditionalRawData) + { + Object = @object; + Id = id; + Model = model; + Modalities = modalities; + Instructions = instructions; + Voice = voice; + InputAudioFormat = inputAudioFormat; + OutputAudioFormat = outputAudioFormat; + InputAudioTranscription = inputAudioTranscription; + TurnDetection = turnDetection; + Tools = tools; + ToolChoice = toolChoice; + Temperature = temperature; + _maxResponseOutputTokens = maxResponseOutputTokens; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeResponseSession() + { + } + + public InternalRealtimeResponseSessionObject Object { get; } = InternalRealtimeResponseSessionObject.RealtimeSession; + + public string Id { get; } + public string Model { get; } + public IReadOnlyList Modalities { get; } + public string Instructions { get; } + public ConversationVoice Voice { get; } + public ConversationAudioFormat InputAudioFormat { get; } + public ConversationAudioFormat OutputAudioFormat { get; } + public ConversationInputTranscriptionOptions InputAudioTranscription { get; } + public ConversationTurnDetectionOptions TurnDetection { get; } + public IReadOnlyList Tools { get; } + public BinaryData ToolChoice { get; } + public float Temperature { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseSessionObject.cs b/src/Generated/Models/InternalRealtimeResponseSessionObject.cs new file mode 100644 index 000000000..0ebab772a --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseSessionObject.cs @@ -0,0 +1,34 @@ +// + +#nullable disable + +using System; +using System.ComponentModel; + +namespace OpenAI.RealtimeConversation +{ + internal readonly partial struct InternalRealtimeResponseSessionObject : IEquatable + { + private readonly string _value; + + public InternalRealtimeResponseSessionObject(string value) + { + _value = value ?? throw new ArgumentNullException(nameof(value)); + } + + private const string RealtimeSessionValue = "realtime.session"; + + public static InternalRealtimeResponseSessionObject RealtimeSession { get; } = new InternalRealtimeResponseSessionObject(RealtimeSessionValue); + public static bool operator ==(InternalRealtimeResponseSessionObject left, InternalRealtimeResponseSessionObject right) => left.Equals(right); + public static bool operator !=(InternalRealtimeResponseSessionObject left, InternalRealtimeResponseSessionObject right) => !left.Equals(right); + public static implicit operator InternalRealtimeResponseSessionObject(string value) => new InternalRealtimeResponseSessionObject(value); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override bool Equals(object obj) => obj is InternalRealtimeResponseSessionObject other && Equals(other); + public bool Equals(InternalRealtimeResponseSessionObject other) => string.Equals(_value, other._value, StringComparison.InvariantCultureIgnoreCase); + + [EditorBrowsable(EditorBrowsableState.Never)] + public override int GetHashCode() => _value != null ? StringComparer.InvariantCultureIgnoreCase.GetHashCode(_value) : 0; + public override string ToString() => _value; + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseStatusDetails.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseStatusDetails.Serialization.cs new file mode 100644 index 000000000..852c8f9e5 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseStatusDetails.Serialization.cs @@ -0,0 +1,125 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeResponseStatusDetails))] + internal partial class InternalRealtimeResponseStatusDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseStatusDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseStatusDetails(document.RootElement, options); + } + + internal static InternalRealtimeResponseStatusDetails DeserializeInternalRealtimeResponseStatusDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "cancelled": return InternalRealtimeResponseCancelledStatusDetails.DeserializeInternalRealtimeResponseCancelledStatusDetails(element, options); + case "failed": return RealtimeResponseFailedStatusDetails.DeserializeRealtimeResponseFailedStatusDetails(element, options); + case "incomplete": return InternalRealtimeResponseIncompleteStatusDetails.DeserializeInternalRealtimeResponseIncompleteStatusDetails(element, options); + } + } + return UnknownRealtimeResponseStatusDetails.DeserializeUnknownRealtimeResponseStatusDetails(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseStatusDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseStatusDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeResponseStatusDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseStatusDetails(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseStatusDetails.cs b/src/Generated/Models/InternalRealtimeResponseStatusDetails.cs new file mode 100644 index 000000000..fa579305c --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseStatusDetails.cs @@ -0,0 +1,25 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal abstract partial class InternalRealtimeResponseStatusDetails + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected InternalRealtimeResponseStatusDetails() + { + } + + internal InternalRealtimeResponseStatusDetails(ConversationStatus type, IDictionary serializedAdditionalRawData) + { + Type = type; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationStatus Type { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseTextContentPart.Serialization.cs b/src/Generated/Models/InternalRealtimeResponseTextContentPart.Serialization.cs new file mode 100644 index 000000000..4a728d942 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseTextContentPart.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseTextContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseTextContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("text") != true) + { + writer.WritePropertyName("text"u8); + writer.WriteStringValue(Text); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseTextContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseTextContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseTextContentPart(document.RootElement, options); + } + + internal static InternalRealtimeResponseTextContentPart DeserializeInternalRealtimeResponseTextContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string text = default; + ConversationContentPartKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("text"u8)) + { + text = property.Value.GetString(); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationContentPartKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeResponseTextContentPart(type, serializedAdditionalRawData, text); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseTextContentPart)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseTextContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseTextContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseTextContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeResponseTextContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeResponseTextContentPart(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeResponseTextContentPart.cs b/src/Generated/Models/InternalRealtimeResponseTextContentPart.cs new file mode 100644 index 000000000..063b4f309 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeResponseTextContentPart.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeResponseTextContentPart : ConversationContentPart + { + internal InternalRealtimeResponseTextContentPart(string text) + { + Argument.AssertNotNull(text, nameof(text)); + + Type = ConversationContentPartKind.Text; + Text = text; + } + + internal InternalRealtimeResponseTextContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData, string text) : base(type, serializedAdditionalRawData) + { + Text = text; + } + + internal InternalRealtimeResponseTextContentPart() + { + } + + public string Text { get; } + } +} diff --git a/src/Generated/Models/InternalRealtimeServerVadTurnDetection.Serialization.cs b/src/Generated/Models/InternalRealtimeServerVadTurnDetection.Serialization.cs new file mode 100644 index 000000000..d5daf900e --- /dev/null +++ b/src/Generated/Models/InternalRealtimeServerVadTurnDetection.Serialization.cs @@ -0,0 +1,170 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeServerVadTurnDetection : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeServerVadTurnDetection)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("threshold") != true && Optional.IsDefined(Threshold)) + { + writer.WritePropertyName("threshold"u8); + writer.WriteNumberValue(Threshold.Value); + } + if (SerializedAdditionalRawData?.ContainsKey("prefix_padding_ms") != true && Optional.IsDefined(PrefixPaddingMs)) + { + writer.WritePropertyName("prefix_padding_ms"u8); + SerializePrefixPaddingMs(writer, options); + } + if (SerializedAdditionalRawData?.ContainsKey("silence_duration_ms") != true && Optional.IsDefined(SilenceDurationMs)) + { + writer.WritePropertyName("silence_duration_ms"u8); + SerializeSilenceDurationMs(writer, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeServerVadTurnDetection IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeServerVadTurnDetection)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeServerVadTurnDetection(document.RootElement, options); + } + + internal static InternalRealtimeServerVadTurnDetection DeserializeInternalRealtimeServerVadTurnDetection(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + float? threshold = default; + TimeSpan? prefixPaddingMs = default; + TimeSpan? silenceDurationMs = default; + ConversationTurnDetectionKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("threshold"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + threshold = property.Value.GetSingle(); + continue; + } + if (property.NameEquals("prefix_padding_ms"u8)) + { + DeserializeMillisecondDuration(property, ref prefixPaddingMs); + continue; + } + if (property.NameEquals("silence_duration_ms"u8)) + { + DeserializeMillisecondDuration(property, ref silenceDurationMs); + continue; + } + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationTurnDetectionKind(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeServerVadTurnDetection(type, serializedAdditionalRawData, threshold, prefixPaddingMs, silenceDurationMs); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeServerVadTurnDetection)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeServerVadTurnDetection IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeServerVadTurnDetection(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeServerVadTurnDetection)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeServerVadTurnDetection FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeServerVadTurnDetection(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeServerVadTurnDetection.cs b/src/Generated/Models/InternalRealtimeServerVadTurnDetection.cs new file mode 100644 index 000000000..e0ec40082 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeServerVadTurnDetection.cs @@ -0,0 +1,28 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeServerVadTurnDetection : ConversationTurnDetectionOptions + { + public InternalRealtimeServerVadTurnDetection() + { + Kind = ConversationTurnDetectionKind.ServerVoiceActivityDetection; + } + + internal InternalRealtimeServerVadTurnDetection(ConversationTurnDetectionKind kind, IDictionary serializedAdditionalRawData, float? threshold, TimeSpan? prefixPaddingMs, TimeSpan? silenceDurationMs) : base(kind, serializedAdditionalRawData) + { + Threshold = threshold; + PrefixPaddingMs = prefixPaddingMs; + SilenceDurationMs = silenceDurationMs; + } + + public float? Threshold { get; set; } + public TimeSpan? PrefixPaddingMs { get; set; } + public TimeSpan? SilenceDurationMs { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.Serialization.cs b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.Serialization.cs new file mode 100644 index 000000000..0186db465 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeToolChoiceFunctionObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("function") != true) + { + writer.WritePropertyName("function"u8); + writer.WriteObjectValue(Function, options); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeToolChoiceFunctionObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeToolChoiceFunctionObject(document.RootElement, options); + } + + internal static InternalRealtimeToolChoiceFunctionObject DeserializeInternalRealtimeToolChoiceFunctionObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeToolChoiceFunctionObjectFunction function = default; + ConversationToolKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("function"u8)) + { + function = InternalRealtimeToolChoiceFunctionObjectFunction.DeserializeInternalRealtimeToolChoiceFunctionObjectFunction(property.Value, options); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationToolKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeToolChoiceFunctionObject(type, serializedAdditionalRawData, function); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObject)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeToolChoiceFunctionObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeToolChoiceFunctionObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new InternalRealtimeToolChoiceFunctionObject FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeToolChoiceFunctionObject(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.cs b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.cs new file mode 100644 index 000000000..f072dc3a8 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObject.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeToolChoiceFunctionObject : InternalRealtimeToolChoiceObject + { + public InternalRealtimeToolChoiceFunctionObject(InternalRealtimeToolChoiceFunctionObjectFunction function) + { + Argument.AssertNotNull(function, nameof(function)); + + Type = ConversationToolKind.Function; + Function = function; + } + + internal InternalRealtimeToolChoiceFunctionObject(ConversationToolKind type, IDictionary serializedAdditionalRawData, InternalRealtimeToolChoiceFunctionObjectFunction function) : base(type, serializedAdditionalRawData) + { + Function = function; + } + + internal InternalRealtimeToolChoiceFunctionObject() + { + } + + public InternalRealtimeToolChoiceFunctionObjectFunction Function { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.Serialization.cs b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.Serialization.cs new file mode 100644 index 000000000..cd8398e92 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeToolChoiceFunctionObjectFunction : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObjectFunction)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("name") != true) + { + writer.WritePropertyName("name"u8); + writer.WriteStringValue(Name); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeToolChoiceFunctionObjectFunction IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObjectFunction)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeToolChoiceFunctionObjectFunction(document.RootElement, options); + } + + internal static InternalRealtimeToolChoiceFunctionObjectFunction DeserializeInternalRealtimeToolChoiceFunctionObjectFunction(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string name = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("name"u8)) + { + name = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InternalRealtimeToolChoiceFunctionObjectFunction(name, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObjectFunction)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeToolChoiceFunctionObjectFunction IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeToolChoiceFunctionObjectFunction(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceFunctionObjectFunction)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeToolChoiceFunctionObjectFunction FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeToolChoiceFunctionObjectFunction(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.cs b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.cs new file mode 100644 index 000000000..45162c2bb --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceFunctionObjectFunction.cs @@ -0,0 +1,32 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class InternalRealtimeToolChoiceFunctionObjectFunction + { + internal IDictionary SerializedAdditionalRawData { get; set; } + public InternalRealtimeToolChoiceFunctionObjectFunction(string name) + { + Argument.AssertNotNull(name, nameof(name)); + + Name = name; + } + + internal InternalRealtimeToolChoiceFunctionObjectFunction(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal InternalRealtimeToolChoiceFunctionObjectFunction() + { + } + + public string Name { get; set; } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceObject.Serialization.cs b/src/Generated/Models/InternalRealtimeToolChoiceObject.Serialization.cs new file mode 100644 index 000000000..c7cd2c8df --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceObject.Serialization.cs @@ -0,0 +1,123 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + [PersistableModelProxy(typeof(UnknownRealtimeToolChoiceObject))] + internal partial class InternalRealtimeToolChoiceObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeToolChoiceObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeToolChoiceObject(document.RootElement, options); + } + + internal static InternalRealtimeToolChoiceObject DeserializeInternalRealtimeToolChoiceObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + if (element.TryGetProperty("type", out JsonElement discriminator)) + { + switch (discriminator.GetString()) + { + case "function": return InternalRealtimeToolChoiceFunctionObject.DeserializeInternalRealtimeToolChoiceFunctionObject(element, options); + } + } + return UnknownRealtimeToolChoiceObject.DeserializeUnknownRealtimeToolChoiceObject(element, options); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeToolChoiceObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeToolChoiceObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static InternalRealtimeToolChoiceObject FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInternalRealtimeToolChoiceObject(document.RootElement); + } + + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/InternalRealtimeToolChoiceObject.cs b/src/Generated/Models/InternalRealtimeToolChoiceObject.cs new file mode 100644 index 000000000..b219a7b10 --- /dev/null +++ b/src/Generated/Models/InternalRealtimeToolChoiceObject.cs @@ -0,0 +1,25 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal abstract partial class InternalRealtimeToolChoiceObject + { + internal IDictionary SerializedAdditionalRawData { get; set; } + protected InternalRealtimeToolChoiceObject() + { + } + + internal InternalRealtimeToolChoiceObject(ConversationToolKind type, IDictionary serializedAdditionalRawData) + { + Type = type; + SerializedAdditionalRawData = serializedAdditionalRawData; + } + + internal ConversationToolKind Type { get; set; } + } +} diff --git a/src/Generated/Models/RealtimeResponseFailedStatusDetails.Serialization.cs b/src/Generated/Models/RealtimeResponseFailedStatusDetails.Serialization.cs new file mode 100644 index 000000000..4bc9d5382 --- /dev/null +++ b/src/Generated/Models/RealtimeResponseFailedStatusDetails.Serialization.cs @@ -0,0 +1,151 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class RealtimeResponseFailedStatusDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RealtimeResponseFailedStatusDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("error") != true) + { + writer.WritePropertyName("error"u8); +#if NET6_0_OR_GREATER + writer.WriteRawValue(Error); +#else + using (JsonDocument document = JsonDocument.Parse(Error)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + RealtimeResponseFailedStatusDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(RealtimeResponseFailedStatusDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeRealtimeResponseFailedStatusDetails(document.RootElement, options); + } + + internal static RealtimeResponseFailedStatusDetails DeserializeRealtimeResponseFailedStatusDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + BinaryData error = default; + ConversationStatus type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("error"u8)) + { + error = BinaryData.FromString(property.Value.GetRawText()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new ConversationStatus(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new RealtimeResponseFailedStatusDetails(type, serializedAdditionalRawData, error); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(RealtimeResponseFailedStatusDetails)} does not support writing '{options.Format}' format."); + } + } + + RealtimeResponseFailedStatusDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeRealtimeResponseFailedStatusDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(RealtimeResponseFailedStatusDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new RealtimeResponseFailedStatusDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeRealtimeResponseFailedStatusDetails(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/RealtimeResponseFailedStatusDetails.cs b/src/Generated/Models/RealtimeResponseFailedStatusDetails.cs new file mode 100644 index 000000000..27d432b59 --- /dev/null +++ b/src/Generated/Models/RealtimeResponseFailedStatusDetails.cs @@ -0,0 +1,31 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class RealtimeResponseFailedStatusDetails : InternalRealtimeResponseStatusDetails + { + internal RealtimeResponseFailedStatusDetails(BinaryData error) + { + Argument.AssertNotNull(error, nameof(error)); + + Type = ConversationStatus.Failed; + Error = error; + } + + internal RealtimeResponseFailedStatusDetails(ConversationStatus type, IDictionary serializedAdditionalRawData, BinaryData error) : base(type, serializedAdditionalRawData) + { + Error = error; + } + + internal RealtimeResponseFailedStatusDetails() + { + } + + public BinaryData Error { get; } + } +} diff --git a/src/Generated/Models/UnknownRealtimeContentPart.Serialization.cs b/src/Generated/Models/UnknownRealtimeContentPart.Serialization.cs new file mode 100644 index 000000000..225ca656a --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeContentPart.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeContentPart : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationContentPart IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationContentPart(document.RootElement, options); + } + + internal static UnknownRealtimeContentPart DeserializeUnknownRealtimeContentPart(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationContentPartKind type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new ConversationContentPartKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeContentPart(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support writing '{options.Format}' format."); + } + } + + ConversationContentPart IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationContentPart(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationContentPart)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeContentPart FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeContentPart(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeContentPart.cs b/src/Generated/Models/UnknownRealtimeContentPart.cs new file mode 100644 index 000000000..64cbf4dfc --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeContentPart.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeContentPart : ConversationContentPart + { + internal UnknownRealtimeContentPart(ConversationContentPartKind type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeContentPart() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeRequestCommand.Serialization.cs b/src/Generated/Models/UnknownRealtimeRequestCommand.Serialization.cs new file mode 100644 index 000000000..f70bd7c3c --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeRequestCommand.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeRequestCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true && Optional.IsDefined(EventId)) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeRequestCommand IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeRequestCommand(document.RootElement, options); + } + + internal static UnknownRealtimeRequestCommand DeserializeUnknownRealtimeRequestCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestCommandType type = "Unknown"; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestCommandType(property.Value.GetString()); + continue; + } + if (property.NameEquals("event_id"u8)) + { + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeRequestCommand(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeRequestCommand IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeRequestCommand(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeRequestCommand)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeRequestCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeRequestCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeRequestCommand.cs b/src/Generated/Models/UnknownRealtimeRequestCommand.cs new file mode 100644 index 000000000..952508ab8 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeRequestCommand.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeRequestCommand : InternalRealtimeRequestCommand + { + internal UnknownRealtimeRequestCommand(InternalRealtimeRequestCommandType kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeRequestCommand() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeRequestItem.Serialization.cs b/src/Generated/Models/UnknownRealtimeRequestItem.Serialization.cs new file mode 100644 index 000000000..55e8e5dbf --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeRequestItem.Serialization.cs @@ -0,0 +1,144 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeRequestItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true && Optional.IsDefined(Id)) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationItem(document.RootElement, options); + } + + internal static UnknownRealtimeRequestItem DeserializeUnknownRealtimeRequestItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeRequestItemType type = "Unknown"; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeRequestItem(type, id, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationItem)} does not support writing '{options.Format}' format."); + } + } + + ConversationItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeRequestItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeRequestItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeRequestItem.cs b/src/Generated/Models/UnknownRealtimeRequestItem.cs new file mode 100644 index 000000000..e082a4d7d --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeRequestItem.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeRequestItem : ConversationItem + { + internal UnknownRealtimeRequestItem(InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData) : base(type, id, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeRequestItem() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseCommand.Serialization.cs b/src/Generated/Models/UnknownRealtimeResponseCommand.Serialization.cs new file mode 100644 index 000000000..40cda0afb --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseCommand.Serialization.cs @@ -0,0 +1,156 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseCommand : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData?.ContainsKey("event_id") != true) + { + if (EventId != null) + { + writer.WritePropertyName("event_id"u8); + writer.WriteStringValue(EventId); + } + else + { + writer.WriteNull("event_id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationUpdate IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationUpdate(document.RootElement, options); + } + + internal static UnknownRealtimeResponseCommand DeserializeUnknownRealtimeResponseCommand(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationUpdateKind type = default; + string eventId = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationUpdateKind(); + continue; + } + if (property.NameEquals("event_id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + eventId = null; + continue; + } + eventId = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeResponseCommand(type, eventId, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support writing '{options.Format}' format."); + } + } + + ConversationUpdate IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationUpdate(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationUpdate)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeResponseCommand FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeResponseCommand(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseCommand.cs b/src/Generated/Models/UnknownRealtimeResponseCommand.cs new file mode 100644 index 000000000..83579fbec --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseCommand.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseCommand : ConversationUpdate + { + internal UnknownRealtimeResponseCommand(ConversationUpdateKind kind, string eventId, IDictionary serializedAdditionalRawData) : base(kind, eventId, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeResponseCommand() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseItem.Serialization.cs b/src/Generated/Models/UnknownRealtimeResponseItem.Serialization.cs new file mode 100644 index 000000000..9a7487d9d --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseItem.Serialization.cs @@ -0,0 +1,167 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseItem : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("object") != true) + { + writer.WritePropertyName("object"u8); + writer.WriteStringValue(Object.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData?.ContainsKey("id") != true) + { + if (Id != null) + { + writer.WritePropertyName("id"u8); + writer.WriteStringValue(Id); + } + else + { + writer.WriteNull("id"); + } + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseItem IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseItem(document.RootElement, options); + } + + internal static UnknownRealtimeResponseItem DeserializeUnknownRealtimeResponseItem(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + InternalRealtimeResponseItemObject @object = default; + InternalRealtimeRequestItemType type = "Unknown"; + string id = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("object"u8)) + { + @object = new InternalRealtimeResponseItemObject(property.Value.GetString()); + continue; + } + if (property.NameEquals("type"u8)) + { + type = new InternalRealtimeRequestItemType(property.Value.GetString()); + continue; + } + if (property.NameEquals("id"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + id = null; + continue; + } + id = property.Value.GetString(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeResponseItem(@object, type, id, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseItem IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseItem(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseItem)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeResponseItem FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeResponseItem(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseItem.cs b/src/Generated/Models/UnknownRealtimeResponseItem.cs new file mode 100644 index 000000000..cc2edc03d --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseItem.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseItem : InternalRealtimeResponseItem + { + internal UnknownRealtimeResponseItem(InternalRealtimeResponseItemObject @object, InternalRealtimeRequestItemType type, string id, IDictionary serializedAdditionalRawData) : base(@object, type, id, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeResponseItem() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseStatusDetails.Serialization.cs b/src/Generated/Models/UnknownRealtimeResponseStatusDetails.Serialization.cs new file mode 100644 index 000000000..35bb140ab --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseStatusDetails.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseStatusDetails : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeResponseStatusDetails IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeResponseStatusDetails(document.RootElement, options); + } + + internal static UnknownRealtimeResponseStatusDetails DeserializeUnknownRealtimeResponseStatusDetails(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationStatus type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new ConversationStatus(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeResponseStatusDetails(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeResponseStatusDetails IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeResponseStatusDetails(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeResponseStatusDetails)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeResponseStatusDetails FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeResponseStatusDetails(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeResponseStatusDetails.cs b/src/Generated/Models/UnknownRealtimeResponseStatusDetails.cs new file mode 100644 index 000000000..3857576aa --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeResponseStatusDetails.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeResponseStatusDetails : InternalRealtimeResponseStatusDetails + { + internal UnknownRealtimeResponseStatusDetails(ConversationStatus type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeResponseStatusDetails() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeTool.Serialization.cs b/src/Generated/Models/UnknownRealtimeTool.Serialization.cs new file mode 100644 index 000000000..0a570abc1 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeTool.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeTool : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTool)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTool IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTool)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTool(document.RootElement, options); + } + + internal static UnknownRealtimeTool DeserializeUnknownRealtimeTool(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationToolKind type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new ConversationToolKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeTool(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTool)} does not support writing '{options.Format}' format."); + } + } + + ConversationTool IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTool(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTool)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeTool FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeTool(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeTool.cs b/src/Generated/Models/UnknownRealtimeTool.cs new file mode 100644 index 000000000..c71d8e5c5 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeTool.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeTool : ConversationTool + { + internal UnknownRealtimeTool(ConversationToolKind kind, IDictionary serializedAdditionalRawData) : base(kind, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeTool() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeToolChoiceObject.Serialization.cs b/src/Generated/Models/UnknownRealtimeToolChoiceObject.Serialization.cs new file mode 100644 index 000000000..8675b9116 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeToolChoiceObject.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeToolChoiceObject : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Type.ToString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InternalRealtimeToolChoiceObject IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInternalRealtimeToolChoiceObject(document.RootElement, options); + } + + internal static UnknownRealtimeToolChoiceObject DeserializeUnknownRealtimeToolChoiceObject(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationToolKind type = "Unknown"; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = new ConversationToolKind(property.Value.GetString()); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeToolChoiceObject(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support writing '{options.Format}' format."); + } + } + + InternalRealtimeToolChoiceObject IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInternalRealtimeToolChoiceObject(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InternalRealtimeToolChoiceObject)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeToolChoiceObject FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeToolChoiceObject(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeToolChoiceObject.cs b/src/Generated/Models/UnknownRealtimeToolChoiceObject.cs new file mode 100644 index 000000000..a3fa5eb28 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeToolChoiceObject.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeToolChoiceObject : InternalRealtimeToolChoiceObject + { + internal UnknownRealtimeToolChoiceObject(ConversationToolKind type, IDictionary serializedAdditionalRawData) : base(type, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeToolChoiceObject() + { + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeTurnDetection.Serialization.cs b/src/Generated/Models/UnknownRealtimeTurnDetection.Serialization.cs new file mode 100644 index 000000000..3f2fd3a69 --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeTurnDetection.Serialization.cs @@ -0,0 +1,133 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeTurnDetection : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + if (SerializedAdditionalRawData?.ContainsKey("type") != true) + { + writer.WritePropertyName("type"u8); + writer.WriteStringValue(Kind.ToSerialString()); + } + if (SerializedAdditionalRawData != null) + { + foreach (var item in SerializedAdditionalRawData) + { + if (ModelSerializationExtensions.IsSentinelValue(item.Value)) + { + continue; + } + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + ConversationTurnDetectionOptions IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeConversationTurnDetectionOptions(document.RootElement, options); + } + + internal static UnknownRealtimeTurnDetection DeserializeUnknownRealtimeTurnDetection(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + ConversationTurnDetectionKind type = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("type"u8)) + { + type = property.Value.GetString().ToConversationTurnDetectionKind(); + continue; + } + if (true) + { + rawDataDictionary ??= new Dictionary(); + rawDataDictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new UnknownRealtimeTurnDetection(type, serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support writing '{options.Format}' format."); + } + } + + ConversationTurnDetectionOptions IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeConversationTurnDetectionOptions(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(ConversationTurnDetectionOptions)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + internal static new UnknownRealtimeTurnDetection FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeUnknownRealtimeTurnDetection(document.RootElement); + } + + internal override BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/src/Generated/Models/UnknownRealtimeTurnDetection.cs b/src/Generated/Models/UnknownRealtimeTurnDetection.cs new file mode 100644 index 000000000..5234828ae --- /dev/null +++ b/src/Generated/Models/UnknownRealtimeTurnDetection.cs @@ -0,0 +1,20 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace OpenAI.RealtimeConversation +{ + internal partial class UnknownRealtimeTurnDetection : ConversationTurnDetectionOptions + { + internal UnknownRealtimeTurnDetection(ConversationTurnDetectionKind kind, IDictionary serializedAdditionalRawData) : base(kind, serializedAdditionalRawData) + { + } + + internal UnknownRealtimeTurnDetection() + { + } + } +} diff --git a/src/Generated/OpenAIClient.cs b/src/Generated/OpenAIClient.cs index 6d35313c6..706a03969 100644 --- a/src/Generated/OpenAIClient.cs +++ b/src/Generated/OpenAIClient.cs @@ -17,6 +17,7 @@ using OpenAI.LegacyCompletions; using OpenAI.Models; using OpenAI.Moderations; +using OpenAI.RealtimeConversation; using OpenAI.VectorStores; namespace OpenAI diff --git a/src/Generated/OpenAIModelFactory.cs b/src/Generated/OpenAIModelFactory.cs index ac68c3bf9..ff52fc4c9 100644 --- a/src/Generated/OpenAIModelFactory.cs +++ b/src/Generated/OpenAIModelFactory.cs @@ -11,6 +11,7 @@ using OpenAI.Embeddings; using OpenAI.Images; using OpenAI.Moderations; +using OpenAI.RealtimeConversation; using OpenAI.VectorStores; namespace OpenAI @@ -58,6 +59,187 @@ public static RunStepTokenUsage RunStepTokenUsage(int outputTokenCount = default return new RunStepTokenUsage(outputTokenCount, inputTokenCount, totalTokenCount, serializedAdditionalRawData: null); } + public static ConversationUpdate ConversationUpdate(string eventId = null) + { + return new UnknownRealtimeResponseCommand(default, eventId, serializedAdditionalRawData: null); + } + + public static ConversationItemAcknowledgedUpdate ConversationItemAcknowledgedUpdate(string eventId = null, ConversationItem item = null) + { + return new ConversationItemAcknowledgedUpdate(ConversationUpdateKind.ItemAcknowledged, eventId, serializedAdditionalRawData: null, item); + } + + public static ConversationItemDeletedUpdate ConversationItemDeletedUpdate(string eventId = null, string itemId = null) + { + return new ConversationItemDeletedUpdate(ConversationUpdateKind.ItemDeleted, eventId, serializedAdditionalRawData: null, itemId); + } + + public static ConversationItemTruncatedUpdate ConversationItemTruncatedUpdate(string eventId = null, string itemId = null, int audioEndMs = default, int index = default) + { + return new ConversationItemTruncatedUpdate( + ConversationUpdateKind.ItemTruncated, + eventId, + serializedAdditionalRawData: null, + itemId, + audioEndMs, + index); + } + + public static ConversationTokenUsage ConversationTokenUsage(int totalTokens = default, int inputTokens = default, int outputTokens = default, ConversationInputTokenUsageDetails inputTokenDetails = null, ConversationOutputTokenUsageDetails outputTokenDetails = null) + { + return new ConversationTokenUsage( + totalTokens, + inputTokens, + outputTokens, + inputTokenDetails, + outputTokenDetails, + serializedAdditionalRawData: null); + } + + public static ConversationInputTokenUsageDetails ConversationInputTokenUsageDetails(int cachedTokens = default, int textTokens = default, int audioTokens = default) + { + return new ConversationInputTokenUsageDetails(cachedTokens, textTokens, audioTokens, serializedAdditionalRawData: null); + } + + public static ConversationOutputTokenUsageDetails ConversationOutputTokenUsageDetails(int textTokens = default, int audioTokens = default) + { + return new ConversationOutputTokenUsageDetails(textTokens, audioTokens, serializedAdditionalRawData: null); + } + + public static ConversationRateLimitsUpdatedUpdate ConversationRateLimitsUpdatedUpdate(string eventId = null, IEnumerable rateLimits = null) + { + rateLimits ??= new List(); + + return new ConversationRateLimitsUpdatedUpdate(ConversationUpdateKind.RateLimitsUpdated, eventId, serializedAdditionalRawData: null, rateLimits?.ToList()); + } + + public static ConversationRateLimitDetailsItem ConversationRateLimitDetailsItem(string name = null, int limit = default, int remaining = default, float resetSeconds = default) + { + return new ConversationRateLimitDetailsItem(name, limit, remaining, resetSeconds, serializedAdditionalRawData: null); + } + + public static ConversationAudioDeltaUpdate ConversationAudioDeltaUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, int contentIndex = default, BinaryData delta = null) + { + return new ConversationAudioDeltaUpdate( + ConversationUpdateKind.ResponseAudioDelta, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + public static ConversationOutputTranscriptionDeltaUpdate ConversationOutputTranscriptionDeltaUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, int contentIndex = default, string delta = null) + { + return new ConversationOutputTranscriptionDeltaUpdate( + ConversationUpdateKind.ResponseAudioTranscriptDelta, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + public static ConversationOutputTranscriptionFinishedUpdate ConversationOutputTranscriptionFinishedUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, int contentIndex = default) + { + return new ConversationOutputTranscriptionFinishedUpdate( + ConversationUpdateKind.ResponseAudioTranscriptDone, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + contentIndex); + } + + public static ConversationTextDeltaUpdate ConversationTextDeltaUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, int contentIndex = default, string delta = null) + { + return new ConversationTextDeltaUpdate( + ConversationUpdateKind.ResponseTextDelta, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + contentIndex, + delta); + } + + public static ConversationTextDoneUpdate ConversationTextDoneUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, int contentIndex = default, string value = null) + { + return new ConversationTextDoneUpdate( + ConversationUpdateKind.ResponseTextDone, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + contentIndex, + value); + } + + public static ConversationFunctionCallArgumentsDeltaUpdate ConversationFunctionCallArgumentsDeltaUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, string callId = null, string delta = null) + { + return new ConversationFunctionCallArgumentsDeltaUpdate( + ConversationUpdateKind.ResponseFunctionCallArgumentsDelta, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + callId, + delta); + } + + public static ConversationFunctionCallArgumentsDoneUpdate ConversationFunctionCallArgumentsDoneUpdate(string eventId = null, string responseId = null, string itemId = null, int outputIndex = default, string callId = null, string name = null, string arguments = null) + { + return new ConversationFunctionCallArgumentsDoneUpdate( + ConversationUpdateKind.ResponseFunctionCallArgumentsDone, + eventId, + serializedAdditionalRawData: null, + responseId, + itemId, + outputIndex, + callId, + name, + arguments); + } + + public static ConversationInputSpeechStartedUpdate ConversationInputSpeechStartedUpdate(string eventId = null, int audioStartMs = default, string itemId = null) + { + return new ConversationInputSpeechStartedUpdate(ConversationUpdateKind.InputAudioBufferSpeechStarted, eventId, serializedAdditionalRawData: null, audioStartMs, itemId); + } + + public static ConversationInputSpeechFinishedUpdate ConversationInputSpeechFinishedUpdate(string eventId = null, int audioEndMs = default, string itemId = null) + { + return new ConversationInputSpeechFinishedUpdate(ConversationUpdateKind.InputAudioBufferSpeechStopped, eventId, serializedAdditionalRawData: null, audioEndMs, itemId); + } + + public static ConversationInputTranscriptionFinishedUpdate ConversationInputTranscriptionFinishedUpdate(string eventId = null, string itemId = null, int contentIndex = default, string transcript = null) + { + return new ConversationInputTranscriptionFinishedUpdate( + ConversationUpdateKind.ItemInputAudioTranscriptionCompleted, + eventId, + serializedAdditionalRawData: null, + itemId, + contentIndex, + transcript); + } + + public static ConversationInputAudioBufferCommittedUpdate ConversationInputAudioBufferCommittedUpdate(string eventId = null, string itemId = null, string previousItemId = null) + { + return new ConversationInputAudioBufferCommittedUpdate(ConversationUpdateKind.InputAudioBufferCommitted, eventId, serializedAdditionalRawData: null, itemId, previousItemId); + } + + public static ConversationInputAudioBufferClearedUpdate ConversationInputAudioBufferClearedUpdate(string eventId = null) + { + return new ConversationInputAudioBufferClearedUpdate(ConversationUpdateKind.InputAudioBufferCleared, eventId, serializedAdditionalRawData: null); + } + public static ModerationResultCollection ModerationResultCollection(string id = null, string model = null, IEnumerable results = null) { results ??= new List(); diff --git a/src/Generated/RealtimeConversationClient.cs b/src/Generated/RealtimeConversationClient.cs new file mode 100644 index 000000000..def54f0ba --- /dev/null +++ b/src/Generated/RealtimeConversationClient.cs @@ -0,0 +1,38 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace OpenAI.RealtimeConversation +{ + // Data plane generated sub-client. + public partial class RealtimeConversationClient + { + private const string AuthorizationHeader = "Authorization"; + private readonly ApiKeyCredential _keyCredential; + private const string AuthorizationApiKeyPrefix = "Bearer"; + private readonly ClientPipeline _pipeline; + + public virtual ClientPipeline Pipeline => _pipeline; + + protected RealtimeConversationClient() + { + } + + internal RealtimeConversationClient(ClientPipeline pipeline, ApiKeyCredential keyCredential, Uri endpoint) + { + _pipeline = pipeline; + _keyCredential = keyCredential; + _endpoint = endpoint; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + } +} diff --git a/src/OpenAI.csproj b/src/OpenAI.csproj index a420cdd88..2cdc4b907 100644 --- a/src/OpenAI.csproj +++ b/src/OpenAI.csproj @@ -39,7 +39,7 @@ $(NoWarn),0169 - $(NoWarn),OPENAI001; + $(NoWarn),OPENAI001;OPENAI002 Debug;Release;Unsigned diff --git a/tests/Assets/whats_the_weather_pcm16_24khz_mono.wav b/tests/Assets/whats_the_weather_pcm16_24khz_mono.wav new file mode 100644 index 000000000..399cd5ad3 Binary files /dev/null and b/tests/Assets/whats_the_weather_pcm16_24khz_mono.wav differ diff --git a/tests/RealtimeConversation/ConversationProtocolTests.cs b/tests/RealtimeConversation/ConversationProtocolTests.cs new file mode 100644 index 000000000..27abc4dc8 --- /dev/null +++ b/tests/RealtimeConversation/ConversationProtocolTests.cs @@ -0,0 +1,99 @@ +using Microsoft.VisualStudio.TestPlatform.ObjectModel; +using NUnit.Framework; +using OpenAI.Chat; +using OpenAI.RealtimeConversation; +using OpenAI.Tests.Telemetry; +using OpenAI.Tests.Utility; +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Net; +using System.Text; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Threading; +using System.Threading.Tasks; +using static OpenAI.Tests.Telemetry.TestMeterListener; +using static OpenAI.Tests.TestHelpers; + +namespace OpenAI.Tests.Conversation; + +#pragma warning disable OPENAI002 + +[TestFixture(true)] +[TestFixture(false)] +public class ConversationProtocolTests : ConversationTestFixtureBase +{ + public ConversationProtocolTests(bool isAsync) : base(isAsync) + { } + + [Test] + public async Task ProtocolCanConfigureSession() + { + RealtimeConversationClient client = GetTestClient(); + using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken); + + BinaryData configureSessionCommand = BinaryData.FromString(""" + { + "type": "session.update", + "session": { + "turn_detection": null + } + } + """); + await session.SendCommandAsync(configureSessionCommand, CancellationOptions); + + List receivedCommands = []; + + await foreach (ConversationUpdate update in session.ReceiveUpdatesAsync(CancellationToken)) + { + BinaryData rawContentBytes = update.GetRawContent(); + JsonNode jsonNode = JsonNode.Parse(rawContentBytes); + string updateType = jsonNode["type"]?.GetValue(); + Assert.That(updateType, Is.Not.Null.And.Not.Empty); + + receivedCommands.Add(jsonNode); + + if (updateType == "error") + { + Assert.Fail($"Error encountered: {rawContentBytes.ToString()}"); + } + else if (updateType == "session.created") + { + BinaryData createResponseCommand = BinaryData.FromString(""" + { + "type": "response.create", + "response": { + "max_output_tokens": null + } + } + """); + await session.SendCommandAsync(createResponseCommand, CancellationOptions); + } + else if (updateType == "response.done") + { + break; + } + } + + List NodesOfType(string type) => receivedCommands.Where(command => command["type"].GetValue() == type).ToList(); + + Assert.That(NodesOfType("session.created"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("session.updated"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.created"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.done"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.output_item.added"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("conversation.item.created"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.content_part.added"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.audio_transcript.delta"), Has.Count.GreaterThan(0)); + Assert.That(NodesOfType("response.audio.delta"), Has.Count.GreaterThan(0)); + Assert.That(NodesOfType("response.audio_transcript.done"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.content_part.done"), Has.Count.EqualTo(1)); + Assert.That(NodesOfType("response.output_item.done"), Has.Count.EqualTo(1)); + } +} diff --git a/tests/RealtimeConversation/ConversationSmokeTests.cs b/tests/RealtimeConversation/ConversationSmokeTests.cs new file mode 100644 index 000000000..056ecc999 --- /dev/null +++ b/tests/RealtimeConversation/ConversationSmokeTests.cs @@ -0,0 +1,170 @@ +using NUnit.Framework; +using OpenAI.RealtimeConversation; +using OpenAI.Tests.Utility; +using System; +using System.ClientModel.Primitives; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text.Json.Nodes; + +namespace OpenAI.Tests.Conversation; + +#pragma warning disable OPENAI002 + +[TestFixture(false)] +[Category("Smoke")] +public class ConversationSmokeTests : ConversationTestFixtureBase +{ + public ConversationSmokeTests(bool isAsync) : base(isAsync) + { } + + [Test] + public void ItemCreation() + { + ConversationItem messageItem = ConversationItem.CreateUserMessage(["Hello, world!"]); + Assert.That(messageItem?.MessageContentParts?.Count, Is.EqualTo(1)); + Assert.That(messageItem.MessageContentParts[0].TextValue, Is.EqualTo("Hello, world!")); + } + + [Test] + public void OptionsSerializationWorks() + { + ConversationSessionOptions options = new() + { + ContentModalities = ConversationContentModalities.Text, + InputAudioFormat = ConversationAudioFormat.G711Alaw, + InputTranscriptionOptions = new ConversationInputTranscriptionOptions() + { + Model = "whisper-1", + }, + Instructions = "test instructions", + MaxResponseOutputTokens = 42, + Model = "gpt-4o-realtime-preview", + OutputAudioFormat = ConversationAudioFormat.G711Ulaw, + Temperature = 0.42f, + ToolChoice = ConversationToolChoice.CreateFunctionToolChoice("test-function"), + Tools = + { + ConversationTool.CreateFunctionTool( + name: "test-function-tool-name", + description: "description of test function tool", + parameters: BinaryData.FromString(""" + { + "type": "object", + "properties": {} + } + """)), + }, + TurnDetectionOptions = ConversationTurnDetectionOptions.CreateServerVoiceActivityTurnDetectionOptions( + detectionThreshold: 0.42f, + prefixPaddingDuration: TimeSpan.FromMilliseconds(234), + silenceDuration: TimeSpan.FromMilliseconds(345)), + Voice = ConversationVoice.Echo, + }; + BinaryData serializedOptions = ModelReaderWriter.Write(options); + JsonNode jsonNode = JsonNode.Parse(serializedOptions.ToString()); + Assert.That(jsonNode["modalities"]?.AsArray()?.ToList(), Has.Count.EqualTo(1)); + Assert.That(jsonNode["modalities"].AsArray().First().GetValue(), Is.EqualTo("text")); + Assert.That(jsonNode["input_audio_format"]?.GetValue(), Is.EqualTo("g711_alaw")); + Assert.That(jsonNode["input_audio_transcription"]?["model"]?.GetValue(), Is.EqualTo("whisper-1")); + Assert.That(jsonNode["instructions"]?.GetValue(), Is.EqualTo("test instructions")); + Assert.That(jsonNode["max_response_output_tokens"]?.GetValue(), Is.EqualTo(42)); + Assert.That(jsonNode["model"]?.GetValue(), Is.EqualTo("gpt-4o-realtime-preview")); + Assert.That(jsonNode["output_audio_format"]?.GetValue(), Is.EqualTo("g711_ulaw")); + Assert.That(jsonNode["temperature"]?.GetValue(), Is.EqualTo(0.42f)); + Assert.That(jsonNode["tools"]?.AsArray()?.ToList(), Has.Count.EqualTo(1)); + Assert.That(jsonNode["tools"].AsArray().First()["name"]?.GetValue(), Is.EqualTo("test-function-tool-name")); + Assert.That(jsonNode["tools"].AsArray().First()["description"]?.GetValue(), Is.EqualTo("description of test function tool")); + Assert.That(jsonNode["tools"].AsArray().First()["parameters"]?["type"]?.GetValue(), Is.EqualTo("object")); + Assert.That(jsonNode["tool_choice"]?["function"]?["name"]?.GetValue(), Is.EqualTo("test-function")); + Assert.That(jsonNode["turn_detection"]?["threshold"]?.GetValue(), Is.EqualTo(0.42f)); + Assert.That(jsonNode["turn_detection"]?["prefix_padding_ms"]?.GetValue(), Is.EqualTo(234)); + Assert.That(jsonNode["turn_detection"]?["silence_duration_ms"]?.GetValue(), Is.EqualTo(345)); + Assert.That(jsonNode["voice"]?.GetValue(), Is.EqualTo("echo")); + ConversationSessionOptions deserializedOptions = ModelReaderWriter.Read(serializedOptions); + Assert.That(deserializedOptions.ContentModalities.HasFlag(ConversationContentModalities.Text)); + Assert.That(deserializedOptions.ContentModalities.HasFlag(ConversationContentModalities.Audio), Is.False); + Assert.That(deserializedOptions.InputAudioFormat, Is.EqualTo(ConversationAudioFormat.G711Alaw)); + Assert.That(deserializedOptions.InputTranscriptionOptions?.Model, Is.EqualTo(ConversationTranscriptionModel.Whisper1)); + Assert.That(deserializedOptions.Instructions, Is.EqualTo("test instructions")); + Assert.That(deserializedOptions.MaxResponseOutputTokens.NumericValue, Is.EqualTo(42)); + Assert.That(deserializedOptions.Model, Is.EqualTo("gpt-4o-realtime-preview")); + Assert.That(deserializedOptions.OutputAudioFormat, Is.EqualTo(ConversationAudioFormat.G711Ulaw)); + Assert.That(deserializedOptions.Tools, Has.Count.EqualTo(1)); + Assert.That(deserializedOptions.Tools[0].Kind, Is.EqualTo(ConversationToolKind.Function)); + Assert.That((deserializedOptions.Tools[0] as ConversationFunctionTool)?.Name, Is.EqualTo("test-function-tool-name")); + Assert.That((deserializedOptions.Tools[0] as ConversationFunctionTool)?.Description, Is.EqualTo("description of test function tool")); + Assert.That((deserializedOptions.Tools[0] as ConversationFunctionTool)?.Parameters?.ToString(), Does.Contain("properties")); + Assert.That(deserializedOptions.ToolChoice?.Kind, Is.EqualTo(ConversationToolChoiceKind.Function)); + Assert.That(deserializedOptions.ToolChoice?.FunctionName, Is.EqualTo("test-function")); + Assert.That(deserializedOptions.TurnDetectionOptions?.Kind, Is.EqualTo(ConversationTurnDetectionKind.ServerVoiceActivityDetection)); + Assert.That(deserializedOptions.Voice, Is.EqualTo(ConversationVoice.Echo)); + } + + [Test] + public void MaxTokensSerializationWorks() + { + // Implicit omission + ConversationSessionOptions options = new() { }; + BinaryData serializedOptions = ModelReaderWriter.Write(options); + Assert.That(serializedOptions.ToString(), Does.Not.Contain("max_response_output_tokens")); + + // Explicit omission + options = new() + { + MaxResponseOutputTokens = null + }; + serializedOptions = ModelReaderWriter.Write(options); + Assert.That(serializedOptions.ToString(), Does.Not.Contain("max_response_output_tokens")); + + // Explicit default (null) + options = new() + { + MaxResponseOutputTokens = ConversationMaxTokensChoice.CreateDefaultMaxTokensChoice() + }; + serializedOptions = ModelReaderWriter.Write(options); + Assert.That(serializedOptions.ToString(), Does.Contain(@"""max_response_output_tokens"":null")); + + // Numeric literal + options = new() + { + MaxResponseOutputTokens = 42, + }; + serializedOptions = ModelReaderWriter.Write(options); + Assert.That(serializedOptions.ToString(), Does.Contain(@"""max_response_output_tokens"":42")); + + // Numeric by factory + options = new() + { + MaxResponseOutputTokens = ConversationMaxTokensChoice.CreateNumericMaxTokensChoice(42) + }; + serializedOptions = ModelReaderWriter.Write(options); + Assert.That(serializedOptions.ToString(), Does.Contain(@"""max_response_output_tokens"":42")); + } + + [Test] + public void TurnDetectionSerializationWorks() + { + // Implicit omission + ConversationSessionOptions sessionOptions = new(); + BinaryData serializedOptions = ModelReaderWriter.Write(sessionOptions); + Assert.That(serializedOptions.ToString(), Does.Not.Contain("turn_detection")); + + sessionOptions = new() + { + TurnDetectionOptions = ConversationTurnDetectionOptions.CreateDisabledTurnDetectionOptions(), + }; + serializedOptions = ModelReaderWriter.Write(sessionOptions); + Assert.That(serializedOptions.ToString(), Does.Contain(@"""turn_detection"":null")); + + sessionOptions = new() + { + TurnDetectionOptions = ConversationTurnDetectionOptions.CreateServerVoiceActivityTurnDetectionOptions( + detectionThreshold: 0.42f) + }; + serializedOptions = ModelReaderWriter.Write(sessionOptions); + JsonNode serializedNode = JsonNode.Parse(serializedOptions); + Assert.That(serializedNode["turn_detection"]?["type"]?.GetValue(), Is.EqualTo("server_vad")); + Assert.That(serializedNode["turn_detection"]?["threshold"]?.GetValue(), Is.EqualTo(0.42f)); + } +} diff --git a/tests/RealtimeConversation/ConversationTestFixtureBase.cs b/tests/RealtimeConversation/ConversationTestFixtureBase.cs new file mode 100644 index 000000000..9ceac0bff --- /dev/null +++ b/tests/RealtimeConversation/ConversationTestFixtureBase.cs @@ -0,0 +1,67 @@ +using NUnit.Framework; +using OpenAI.RealtimeConversation; +using OpenAI.Tests.Utility; +using System; +using System.ClientModel.Primitives; +using System.Diagnostics; +using System.Text.Json; +using System.Text.Json.Nodes; +using System.Threading; +using static OpenAI.Tests.TestHelpers; + +namespace OpenAI.Tests.Conversation; + +#pragma warning disable OPENAI002 + +[Parallelizable(ParallelScope.All)] +[Category("Conversation")] +public class ConversationTestFixtureBase : SyncAsyncTestBase +{ + public CancellationTokenSource CancellationTokenSource { get; } + public CancellationToken CancellationToken => CancellationTokenSource?.Token ?? default; + public RequestOptions CancellationOptions => new() { CancellationToken = CancellationToken }; + + public ConversationTestFixtureBase(bool isAsync) : base(isAsync) + { + CancellationTokenSource = new(); + if (!Debugger.IsAttached) + { + CancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(15)); + } + } + + public static RealtimeConversationClient GetTestClient() + { + RealtimeConversationClient client = GetTestClient(TestScenario.RealtimeConversation); + client.OnSendingCommand += (_, data) => PrintMessageData(data, "> "); + client.OnReceivingCommand += (_, data) => PrintMessageData(data, " < "); + return client; + } + + public static void PrintMessageData(BinaryData data, string prefix = "") + { + JsonNode jsonNode = JsonNode.Parse(data.ToString()); + + foreach ((string labelKey, string labelValue, string dataKey) in new (string, string, string)[] + { + ("type", "input_audio_buffer.append", "audio"), + ("type", "audio", "data"), + ("event", "add_user_audio", "data"), + ("type", "response.audio.delta", "delta") + }) + { + if (jsonNode[labelKey]?.GetValue() == labelValue) + { + string rawBase64Data = jsonNode[dataKey]?.GetValue(); + if (rawBase64Data is not null) + { + byte[] base64Data = rawBase64Data == null ? [] : Convert.FromBase64String(rawBase64Data); + jsonNode[dataKey] = $"<{base64Data.Length} bytes>"; + } + } + } + + string rawMessage = jsonNode.ToJsonString(new JsonSerializerOptions()); + Console.WriteLine($"{prefix}{rawMessage}"); + } +} diff --git a/tests/RealtimeConversation/ConversationTests.cs b/tests/RealtimeConversation/ConversationTests.cs new file mode 100644 index 000000000..b26b4b8e6 --- /dev/null +++ b/tests/RealtimeConversation/ConversationTests.cs @@ -0,0 +1,250 @@ +using NUnit.Framework; +using OpenAI.RealtimeConversation; +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OpenAI.Tests.Conversation; + +#pragma warning disable OPENAI002 + +[TestFixture(true)] +[TestFixture(false)] +public class ConversationTests : ConversationTestFixtureBase +{ + public ConversationTests(bool isAsync) : base(isAsync) { } + + [Test] + public async Task CanConfigureSession() + { + RealtimeConversationClient client = GetTestClient(); + using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken); + + await session.ConfigureSessionAsync( + new ConversationSessionOptions() + { + Instructions = "You are a helpful assistant.", + TurnDetectionOptions = ConversationTurnDetectionOptions.CreateDisabledTurnDetectionOptions(), + OutputAudioFormat = ConversationAudioFormat.G711Ulaw + }, + CancellationToken); + + await session.StartResponseTurnAsync(CancellationToken); + + List receivedUpdates = []; + + await foreach (ConversationUpdate update in session.ReceiveUpdatesAsync(CancellationToken)) + { + receivedUpdates.Add(update); + + if (update is ConversationErrorUpdate errorUpdate) + { + Assert.That(errorUpdate.Kind, Is.EqualTo(ConversationUpdateKind.Error)); + Assert.Fail($"Error: {ModelReaderWriter.Write(errorUpdate)}"); + } + else if (update is ConversationResponseFinishedUpdate turnFinishedUpdate) + { + break; + } + } + + List GetReceivedUpdates() where T : ConversationUpdate + => receivedUpdates.Select(update => update as T) + .Where(update => update is not null) + .ToList(); + + Assert.That(GetReceivedUpdates(), Has.Count.EqualTo(1)); + Assert.That(GetReceivedUpdates(), Has.Count.EqualTo(1)); + Assert.That(GetReceivedUpdates(), Has.Count.EqualTo(1)); + Assert.That(GetReceivedUpdates(), Has.Count.EqualTo(1)); + Assert.That(GetReceivedUpdates(), Has.Count.EqualTo(1)); + } + + [Test] + public async Task TextOnlyWorks() + { + RealtimeConversationClient client = GetTestClient(); + using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken); + await session.AddItemAsync( + ConversationItem.CreateUserMessage(["Hello, world!"]), + cancellationToken: CancellationToken); + await session.StartResponseTurnAsync(CancellationToken); + + StringBuilder responseBuilder = new(); + + await foreach (ConversationUpdate update in session.ReceiveUpdatesAsync(CancellationToken)) + { + if (update is ConversationSessionStartedUpdate sessionStartedUpdate) + { + Assert.That(sessionStartedUpdate.SessionId, Is.Not.Null.And.Not.Empty); + } + if (update is ConversationTextDeltaUpdate textDeltaUpdate) + { + responseBuilder.Append(textDeltaUpdate.Delta); + } + + if (update is ConversationItemAcknowledgedUpdate itemAddedUpdate) + { + Assert.That(itemAddedUpdate.Item is not null); + } + + if (update is ConversationRateLimitsUpdatedUpdate) + { + break; + } + } + + Assert.That(responseBuilder.ToString(), Is.Not.Null.Or.Empty); + } + + [Test] + public async Task AudioWithToolsWorks() + { + RealtimeConversationClient client = GetTestClient(); + using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken); + + ConversationFunctionTool getWeatherTool = new() + { + Name = "get_weather_for_location", + Description = "gets the weather for a location", + Parameters = BinaryData.FromString(""" + { + "type": "object", + "properties": { + "location": { + "type": "string", + "description": "The city and state e.g. San Francisco, CA" + }, + "unit": { + "type": "string", + "enum": [ + "c", + "f" + ] + } + }, + "required": [ + "location", + "unit" + ] + } + """) + }; + + ConversationSessionOptions options = new() + { + Instructions = "Call provided tools if appropriate for the user's input.", + Voice = ConversationVoice.Alloy, + Tools = { getWeatherTool }, + InputTranscriptionOptions = new ConversationInputTranscriptionOptions() + { + Model = "whisper-1" + }, + }; + + await session.ConfigureSessionAsync(options, CancellationToken); + + using Stream audioStream = File.OpenRead(Path.Join("Assets", "whats_the_weather_pcm16_24khz_mono.wav")); + _ = session.SendAudioAsync(audioStream, CancellationToken); + + string userTranscript = null; + + await foreach (ConversationUpdate update in session.ReceiveUpdatesAsync(CancellationToken)) + { + Assert.That(update.EventId, Is.Not.Null.And.Not.Empty); + + if (update is ConversationSessionStartedUpdate sessionStartedUpdate) + { + Assert.That(sessionStartedUpdate.SessionId, Is.Not.Null.And.Not.Empty); + Assert.That(sessionStartedUpdate.Model, Is.Not.Null.And.Not.Empty); + Assert.That(sessionStartedUpdate.ContentModalities.HasFlag(ConversationContentModalities.Text)); + Assert.That(sessionStartedUpdate.ContentModalities.HasFlag(ConversationContentModalities.Audio)); + Assert.That(sessionStartedUpdate.Voice.ToString(), Is.Not.Null.And.Not.Empty); + Assert.That(sessionStartedUpdate.Temperature, Is.GreaterThan(0)); + } + + if (update is ConversationInputTranscriptionFinishedUpdate inputTranscriptionCompletedUpdate) + { + userTranscript = inputTranscriptionCompletedUpdate.Transcript; + } + + if (update is ConversationItemFinishedUpdate itemFinishedUpdate + && itemFinishedUpdate.FunctionCallId is not null) + { + Assert.That(itemFinishedUpdate.FunctionName, Is.EqualTo(getWeatherTool.Name)); + + ConversationItem functionResponse = ConversationItem.CreateFunctionCallOutput( + itemFinishedUpdate.FunctionCallId, + "71 degrees Fahrenheit, sunny"); + await session.AddItemAsync(functionResponse, CancellationToken); + } + + if (update is ConversationResponseFinishedUpdate turnFinishedUpdate) + { + if (turnFinishedUpdate.CreatedItems.Any(item => !string.IsNullOrEmpty(item.FunctionCallId))) + { + await session.StartResponseTurnAsync(CancellationToken); + } + else + { + break; + } + } + } + + Assert.That(userTranscript, Is.Not.Null.And.Not.Empty); + } + + [Test] + public async Task CanDisableVoiceActivityDetection() + { + RealtimeConversationClient client = GetTestClient(); + using RealtimeConversationSession session = await client.StartConversationSessionAsync(CancellationToken); + + await session.ConfigureSessionAsync( + new() + { + TurnDetectionOptions = ConversationTurnDetectionOptions.CreateDisabledTurnDetectionOptions(), + }, + CancellationToken); + + const string folderName = "Assets"; + const string fileName = "whats_the_weather_pcm16_24khz_mono.wav"; +#if NET6_0_OR_GREATER + using Stream audioStream = File.OpenRead(Path.Join(folderName, fileName)); +#else + using Stream audioStream = File.OpenRead($"{folderName}\\{fileName}"); +#endif + await session.SendAudioAsync(audioStream, CancellationToken); + + await session.AddItemAsync(ConversationItem.CreateUserMessage(["Hello, assistant!"]), CancellationToken); + + await foreach (ConversationUpdate update in session.ReceiveUpdatesAsync(CancellationToken)) + { + if (update is ConversationErrorUpdate errorUpdate) + { + Assert.Fail($"Error received: {ModelReaderWriter.Write(errorUpdate)}"); + } + + if (update is ConversationInputSpeechStartedUpdate + or ConversationInputSpeechFinishedUpdate + or ConversationInputTranscriptionFinishedUpdate + or ConversationInputTranscriptionFailedUpdate + or ConversationResponseStartedUpdate + or ConversationResponseFinishedUpdate) + { + Assert.Fail($"Shouldn't receive any VAD events or response creation!"); + } + + if (update is ConversationItemAcknowledgedUpdate itemAcknowledgedUpdate + && itemAcknowledgedUpdate.Item.MessageRole == ConversationMessageRole.User) + { + break; + } + } + } +} diff --git a/tests/Utility/TestHelpers.cs b/tests/Utility/TestHelpers.cs index c7007e89b..a781a91a2 100644 --- a/tests/Utility/TestHelpers.cs +++ b/tests/Utility/TestHelpers.cs @@ -9,6 +9,7 @@ using OpenAI.Images; using OpenAI.Models; using OpenAI.Moderations; +using OpenAI.RealtimeConversation; using OpenAI.VectorStores; using System; using System.ClientModel; @@ -37,6 +38,7 @@ public enum TestScenario LegacyCompletions, Models, Moderations, + RealtimeConversation, VectorStores, TopLevel, } @@ -67,6 +69,9 @@ public static T GetTestClient(TestScenario scenario, string overrideModel = n TestScenario.VectorStores => new VectorStoreClient(credential, options), #pragma warning restore OPENAI001 TestScenario.TopLevel => new OpenAIClient(credential, options), +#pragma warning disable OPENAI002 + TestScenario.RealtimeConversation => new RealtimeConversationClient(overrideModel ?? "gpt-4o-realtime-preview-2024-10-01", credential, options), +#pragma warning restore _ => throw new NotImplementedException(), }; return (T)clientObject;