Skip to content

Commit 5cc0d0e

Browse files
committed
sync fork to upstream
2 parents cdf174c + 3f0eca9 commit 5cc0d0e

File tree

10 files changed

+2613
-96
lines changed

10 files changed

+2613
-96
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System.Runtime.Serialization;
2+
using System.Text.Json;
3+
using System.Text.Json.Serialization;
4+
5+
namespace AzureOpenAIProxy.ApiApp.Converters;
6+
7+
/// <summary>
8+
/// This represents the converter entity for <see cref="EnumMemberAttribute"/>.
9+
/// </summary>
10+
/// <typeparam name="T">The type of the enum to be converted.</typeparam>
11+
public class EnumMemberConverter<T> : JsonConverter<T> where T : Enum
12+
{
13+
/// <inheritdoc />
14+
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
15+
{
16+
var enumText = reader.GetString();
17+
18+
if (enumText == null)
19+
{
20+
throw new JsonException($"Unable to convert null to Enum \"{typeToConvert}\".");
21+
}
22+
23+
foreach (var field in typeToConvert.GetFields())
24+
{
25+
var attribute = Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) as EnumMemberAttribute;
26+
27+
if (attribute != null && attribute.Value == enumText)
28+
{
29+
var value = field.GetValue(null);
30+
if (value != null)
31+
{
32+
return (T)value;
33+
}
34+
}
35+
else if (field.Name == enumText)
36+
{
37+
var value = field.GetValue(null);
38+
if (value != null)
39+
{
40+
return (T)value;
41+
}
42+
}
43+
}
44+
45+
throw new JsonException($"Unable to convert \"{enumText}\" to Enum \"{typeToConvert}\".");
46+
}
47+
48+
/// <inheritdoc />
49+
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)
50+
{
51+
var field = value.GetType().GetField(value.ToString());
52+
53+
if (field != null)
54+
{
55+
var attribute = Attribute.GetCustomAttribute(field, typeof(EnumMemberAttribute)) as EnumMemberAttribute;
56+
57+
if (attribute != null)
58+
{
59+
writer.WriteStringValue(attribute.Value);
60+
}
61+
else
62+
{
63+
writer.WriteStringValue(value.ToString());
64+
}
65+
}
66+
else
67+
{
68+
writer.WriteStringValue(value.ToString());
69+
}
70+
}
71+
72+
}

src/AzureOpenAIProxy.ApiApp/Endpoints/ProxyChatCompletionsEndpoint.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Text.Json;
22

33
using AzureOpenAIProxy.ApiApp.Attributes;
4+
using AzureOpenAIProxy.ApiApp.Models;
45
using AzureOpenAIProxy.ApiApp.Services;
56

67
using Microsoft.AspNetCore.Mvc;
@@ -54,7 +55,7 @@ public static RouteHandlerBuilder AddChatCompletions(this WebApplication app)
5455
})
5556
// TODO: Check both request/response payloads
5657
.Accepts<ChatCompletionOptions>(contentType: "application/json")
57-
.Produces<ChatCompletion>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
58+
.Produces<CreateChatCompletionResponse>(statusCode: StatusCodes.Status200OK, contentType: "application/json")
5859
// TODO: Check both request/response payloads
5960
.Produces(statusCode: StatusCodes.Status401Unauthorized)
6061
.Produces<string>(statusCode: StatusCodes.Status500InternalServerError, contentType: "text/plain")
Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
1-
using System.Text.Json.Serialization;
2-
3-
namespace AzureOpenAIProxy.ApiApp.Models;
4-
5-
/// <summary>
6-
/// This represent the event detail data for response by admin event endpoint.
7-
/// </summary>
8-
public class AdminEventDetails : EventDetails
9-
{
10-
/// <summary>
11-
/// Gets or sets the event description.
12-
/// </summary>
13-
public string? Description { get; set; }
14-
15-
/// <summary>
16-
/// Gets or sets the event start date.
17-
/// </summary>
18-
[JsonRequired]
19-
public DateTimeOffset DateStart { get; set; }
20-
21-
/// <summary>
22-
/// Gets or sets the event end date.
23-
/// </summary>
24-
[JsonRequired]
25-
public DateTimeOffset DateEnd { get; set; }
26-
27-
/// <summary>
28-
/// Gets or sets the event start to end date timezone.
29-
/// </summary>
30-
[JsonRequired]
31-
public string TimeZone { get; set; } = string.Empty;
32-
33-
/// <summary>
34-
/// Gets or sets the event active status.
35-
/// </summary>
36-
[JsonRequired]
37-
public bool IsActive { get; set; }
38-
39-
/// <summary>
40-
/// Gets or sets the event organizer name.
41-
/// </summary>
42-
[JsonRequired]
43-
public string OrganizerName { get; set; } = string.Empty;
44-
45-
/// <summary>
46-
/// Gets or sets the event organizer email.
47-
/// </summary>
48-
[JsonRequired]
49-
public string OrganizerEmail { get; set; } = string.Empty;
50-
51-
/// <summary>
52-
/// Gets or sets the event coorganizer name.
53-
/// </summary>
54-
public string? CoorganizerName { get; set; }
55-
56-
/// <summary>
57-
/// Gets or sets the event coorganizer email.
58-
/// </summary>
59-
public string? CoorganizerEmail { get; set; }
1+
using System.Text.Json.Serialization;
2+
3+
namespace AzureOpenAIProxy.ApiApp.Models;
4+
5+
/// <summary>
6+
/// This represent the entity for the event details for admin.
7+
/// </summary>
8+
public class AdminEventDetails : EventDetails
9+
{
10+
/// <summary>
11+
/// Gets or sets the event description.
12+
/// </summary>
13+
public string? Description { get; set; }
14+
15+
/// <summary>
16+
/// Gets or sets the event start date.
17+
/// </summary>
18+
[JsonRequired]
19+
public DateTimeOffset DateStart { get; set; }
20+
21+
/// <summary>
22+
/// Gets or sets the event end date.
23+
/// </summary>
24+
[JsonRequired]
25+
public DateTimeOffset DateEnd { get; set; }
26+
27+
/// <summary>
28+
/// Gets or sets the event start to end date timezone.
29+
/// </summary>
30+
[JsonRequired]
31+
public string TimeZone { get; set; } = string.Empty;
32+
33+
/// <summary>
34+
/// Gets or sets the event active status.
35+
/// </summary>
36+
[JsonRequired]
37+
public bool IsActive { get; set; }
38+
39+
/// <summary>
40+
/// Gets or sets the event organizer name.
41+
/// </summary>
42+
[JsonRequired]
43+
public string OrganizerName { get; set; } = string.Empty;
44+
45+
/// <summary>
46+
/// Gets or sets the event organizer email.
47+
/// </summary>
48+
[JsonRequired]
49+
public string OrganizerEmail { get; set; } = string.Empty;
50+
51+
/// <summary>
52+
/// Gets or sets the event coorganizer name.
53+
/// </summary>
54+
public string? CoorganizerName { get; set; }
55+
56+
/// <summary>
57+
/// Gets or sets the event coorganizer email.
58+
/// </summary>
59+
public string? CoorganizerEmail { get; set; }
6060
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System.Runtime.Serialization;
2+
using System.Text.Json.Serialization;
3+
4+
using AzureOpenAIProxy.ApiApp.Converters;
5+
6+
namespace AzureOpenAIProxy.ApiApp.Models;
7+
8+
/// <summary>
9+
/// This represent the entity for the resource details for admin.
10+
/// </summary>
11+
public class AdminResourceDetails
12+
{
13+
/// <summary>
14+
/// Gets or sets the event id.
15+
/// </summary>
16+
[JsonRequired]
17+
public Guid ResourceId { get; set; }
18+
19+
/// <summary>
20+
/// Gets or sets the friendly name of the resource.
21+
/// </summary>
22+
[JsonRequired]
23+
public string FriendlyName { get; set; } = string.Empty;
24+
25+
/// <summary>
26+
/// Gets or sets the deployment name of the resource.
27+
/// </summary>
28+
[JsonRequired]
29+
public string DeploymentName { get; set; } = string.Empty;
30+
31+
/// <summary>
32+
/// Gets or sets the resource type.
33+
/// </summary>
34+
[JsonRequired]
35+
public ResourceType ResourceType { get; set; } = ResourceType.None;
36+
37+
/// <summary>
38+
/// Gets or sets the resource endpoint.
39+
/// </summary>
40+
[JsonRequired]
41+
public string Endpoint { get; set; } = string.Empty;
42+
43+
/// <summary>
44+
/// Gets or sets the resource API key.
45+
/// </summary>
46+
[JsonRequired]
47+
public string ApiKey { get; set; } = string.Empty;
48+
49+
/// <summary>
50+
/// Gets or sets the resource region.
51+
/// </summary>
52+
[JsonRequired]
53+
public string Region { get; set; } = string.Empty;
54+
55+
/// <summary>
56+
/// Gets or sets the value indicating whether the resource is active.
57+
/// </summary>
58+
[JsonRequired]
59+
public bool IsActive { get; set; }
60+
}
61+
62+
/// <summary>
63+
/// /// This defines the type of the resource.
64+
[JsonConverter(typeof(EnumMemberConverter<ResourceType>))]
65+
public enum ResourceType
66+
{
67+
/// <summary>
68+
/// Indicates the resource type is not defined.
69+
/// </summary>
70+
[EnumMember(Value = "none")]
71+
None,
72+
73+
/// <summary>
74+
/// Indicates the chat resource type.
75+
/// </summary>
76+
[EnumMember(Value = "chat")]
77+
Chat,
78+
79+
/// <summary>
80+
/// Indicates the image resource type.
81+
/// </summary>
82+
[EnumMember(Value = "image")]
83+
Image,
84+
}

0 commit comments

Comments
 (0)