Skip to content

Commit

Permalink
feat: Initial work for Realtime API.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Oct 13, 2024
1 parent 5ff2342 commit 68006cd
Show file tree
Hide file tree
Showing 32 changed files with 1,809 additions and 25 deletions.
7 changes: 7 additions & 0 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

var path = args[0];
var text = await File.ReadAllTextAsync(path);
var extendedText = await File.ReadAllTextAsync(path.Replace(".yaml", ".extended.yaml"));

text = text.Replace("description: *run_temperature_description", "description: empty");
text = text.Replace("description: &run_temperature_description ", "description: ");
Expand All @@ -17,6 +18,12 @@
text = text.Replace("response: &moderation_example |", "response: |");

var openApiDocument = new OpenApiStringReader().Read(text, out var diagnostics);
var extendedOpenApiDocument = new OpenApiStringReader().Read(extendedText, out var extendedDiagnostics);
foreach (var schema in extendedOpenApiDocument.Components.Schemas)
{
openApiDocument.Components.Schemas[schema.Key] = schema.Value;
}

openApiDocument.Components.Schemas["ParallelToolCalls"]!.Default = null;
openApiDocument.Components.Schemas["ParallelToolCalls"]!.Nullable = true;

Expand Down
49 changes: 49 additions & 0 deletions src/libs/OpenAI/Generated/JsonConverters.RealtimeAudioFormat.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeAudioFormatJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeAudioFormat>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeAudioFormat Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeAudioFormatExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeAudioFormat)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeAudioFormat value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.RealtimeAudioFormatExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeAudioFormatNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeAudioFormat?>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeAudioFormat? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeAudioFormatExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeAudioFormat)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeAudioFormat? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.RealtimeAudioFormatExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeResponseCreateResponseMaxOutputTokensJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokensExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokensExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeResponseCreateResponseMaxOutputTokensNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens?>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokensExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokens? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.RealtimeResponseCreateResponseMaxOutputTokensExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeResponseCreateResponseModalitieJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeResponseCreateResponseModalitie>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeResponseCreateResponseModalitie Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeResponseCreateResponseModalitieExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeResponseCreateResponseModalitie)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeResponseCreateResponseModalitie value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.RealtimeResponseCreateResponseModalitieExtensions.ToValueString(value));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeResponseCreateResponseModalitieNullableJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeResponseCreateResponseModalitie?>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeResponseCreateResponseModalitie? Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeResponseCreateResponseModalitieExtensions.ToEnum(stringValue);
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeResponseCreateResponseModalitie)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeResponseCreateResponseModalitie? value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

if (value == null)
{
writer.WriteNullValue();
}
else
{
writer.WriteStringValue(global::OpenAI.RealtimeResponseCreateResponseModalitieExtensions.ToValueString(value.Value));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#nullable enable

namespace OpenAI.JsonConverters
{
/// <inheritdoc />
public sealed class RealtimeResponseCreateResponseVoiceJsonConverter : global::System.Text.Json.Serialization.JsonConverter<global::OpenAI.RealtimeResponseCreateResponseVoice>
{
/// <inheritdoc />
public override global::OpenAI.RealtimeResponseCreateResponseVoice Read(
ref global::System.Text.Json.Utf8JsonReader reader,
global::System.Type typeToConvert,
global::System.Text.Json.JsonSerializerOptions options)
{
switch (reader.TokenType)
{
case global::System.Text.Json.JsonTokenType.String:
{
var stringValue = reader.GetString();
if (stringValue != null)
{
return global::OpenAI.RealtimeResponseCreateResponseVoiceExtensions.ToEnum(stringValue) ?? default;
}

break;
}
case global::System.Text.Json.JsonTokenType.Number:
{
var numValue = reader.GetInt32();
return (global::OpenAI.RealtimeResponseCreateResponseVoice)numValue;
}
default:
throw new global::System.ArgumentOutOfRangeException(nameof(reader));
}

return default;
}

/// <inheritdoc />
public override void Write(
global::System.Text.Json.Utf8JsonWriter writer,
global::OpenAI.RealtimeResponseCreateResponseVoice value,
global::System.Text.Json.JsonSerializerOptions options)
{
writer = writer ?? throw new global::System.ArgumentNullException(nameof(writer));

writer.WriteStringValue(global::OpenAI.RealtimeResponseCreateResponseVoiceExtensions.ToValueString(value));
}
}
}
Loading

0 comments on commit 68006cd

Please sign in to comment.