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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion src/libs/tryAGI.OpenAI/Generated/tryAGI.OpenAI.AllOf.2.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,51 @@ Value1 as object
Value2?.ToString()
;

private static bool RequiresValue<TValue>() => RequirementCache<TValue>.Value;

private static bool DetermineRequiresValue(global::System.Type type)
{
if (global::System.Nullable.GetUnderlyingType(type) != null)
{
return false;
}

if (type.IsValueType ||
type == typeof(string) ||
type.IsArray)
{
return true;
}

foreach (var property in type.GetProperties(global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Public))
{
foreach (var attributeData in property.CustomAttributes)
{
var attributeTypeName = attributeData.AttributeType.FullName;
if (attributeTypeName == "System.Text.Json.Serialization.JsonRequiredAttribute" ||
attributeTypeName == "Newtonsoft.Json.JsonRequiredAttribute" ||
attributeTypeName == "System.Runtime.CompilerServices.RequiredMemberAttribute")
{
return true;
}
}
}

return false;
}

private static class RequirementCache<TValue>
{
public static readonly bool Value = DetermineRequiresValue(typeof(TValue));
}


/// <summary>
///
/// </summary>
public bool Validate()
{
return IsValue1 && IsValue2;
return (!RequiresValue<T1>() || IsValue1) && (!RequiresValue<T2>() || IsValue2);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ public sealed partial class OpenAiRealtimeClient
if (result.MessageType == global::System.Net.WebSockets.WebSocketMessageType.Text)
{
string json = global::System.Text.Encoding.UTF8.GetString(buffer, 0, result.Count);
var @event = (global::tryAGI.OpenAI.Realtime.ServerEvent?)global::System.Text.Json.JsonSerializer.Deserialize(json, typeof(global::tryAGI.OpenAI.Realtime.ServerEvent), JsonSerializerContext) ??
throw new global::System.InvalidOperationException(
$"Response deserialization failed for \"{json}\" ");
var @event = (global::tryAGI.OpenAI.Realtime.ServerEvent)global::System.Text.Json.JsonSerializer.Deserialize(json, typeof(global::tryAGI.OpenAI.Realtime.ServerEvent), JsonSerializerContext)!;

yield return @event;
}
Expand Down