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
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@

#nullable enable

namespace tryAGI.OpenAI
{
/// <summary>
/// Represents a successful HTTP response with status code and headers.
/// </summary>
public partial class AutoSDKHttpResponse
{
/// <summary>
/// Initializes a new instance of the <see cref="AutoSDKHttpResponse"/> class.
/// </summary>
public AutoSDKHttpResponse(
global::System.Net.HttpStatusCode statusCode,
global::System.Collections.Generic.Dictionary<string, global::System.Collections.Generic.IEnumerable<string>> headers)
{
StatusCode = statusCode;
Headers = headers ?? throw new global::System.ArgumentNullException(nameof(headers));
}

/// <summary>
/// Gets the HTTP status code.
/// </summary>
public global::System.Net.HttpStatusCode StatusCode { get; }
/// <summary>
/// Gets the response headers.
/// </summary>
public global::System.Collections.Generic.Dictionary<string, global::System.Collections.Generic.IEnumerable<string>> Headers { get; }

internal static global::System.Collections.Generic.Dictionary<string, global::System.Collections.Generic.IEnumerable<string>> CreateHeaders(
global::System.Net.Http.HttpResponseMessage response)
{
response = response ?? throw new global::System.ArgumentNullException(nameof(response));

var headers = global::System.Linq.Enumerable.ToDictionary(
response.Headers,
static header => header.Key,
static header => (global::System.Collections.Generic.IEnumerable<string>)global::System.Linq.Enumerable.ToArray(header.Value),
global::System.StringComparer.OrdinalIgnoreCase);

if (response.Content?.Headers == null)
{
return headers;
}

foreach (var header in response.Content.Headers)
{
if (headers.TryGetValue(header.Key, out var existingValues))
{
headers[header.Key] = global::System.Linq.Enumerable.ToArray(
global::System.Linq.Enumerable.Concat(existingValues, header.Value));
}
else
{
headers[header.Key] = global::System.Linq.Enumerable.ToArray(header.Value);
}
}

return headers;
}
}

/// <summary>
/// Represents a successful HTTP response with status code, headers, and body.
/// </summary>
public partial class AutoSDKHttpResponse<T> : AutoSDKHttpResponse
{
/// <summary>
/// Initializes a new instance of the <see cref="AutoSDKHttpResponse{T}"/> class.
/// </summary>
public AutoSDKHttpResponse(
global::System.Net.HttpStatusCode statusCode,
global::System.Collections.Generic.Dictionary<string, global::System.Collections.Generic.IEnumerable<string>> headers,
T body)
: base(statusCode, headers)
{
Body = body;
}

/// <summary>
/// Gets the response body.
/// </summary>
public T Body { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ public partial interface IRealtimeClient
/// Create a new Realtime API call over WebRTC and receive the SDP answer needed<br/>
/// to complete the peer connection.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::tryAGI.OpenAI.ApiException"></exception>
global::System.Threading.Tasks.Task<global::tryAGI.OpenAI.AutoSDKHttpResponse<string>> CreateCallAsResponseAsync(

global::tryAGI.OpenAI.RealtimeCallCreateRequest request,
global::System.Threading.CancellationToken cancellationToken = default);
/// <summary>
/// Create a new Realtime API call over WebRTC and receive the SDP answer needed<br/>
/// to complete the peer connection.
/// </summary>
/// <param name="sdp">
/// WebRTC Session Description Protocol (SDP) offer generated by the caller.
/// </param>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ partial void ProcessCreateCallResponseContent(
/// <exception cref="global::tryAGI.OpenAI.ApiException"></exception>
public async global::System.Threading.Tasks.Task<string> CreateCallAsync(

global::tryAGI.OpenAI.RealtimeCallCreateRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
var __response = await CreateCallAsResponseAsync(

request: request,
cancellationToken: cancellationToken
).ConfigureAwait(false);

return __response.Body;
}
/// <summary>
/// Create a new Realtime API call over WebRTC and receive the SDP answer needed<br/>
/// to complete the peer connection.
/// </summary>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::tryAGI.OpenAI.ApiException"></exception>
public async global::System.Threading.Tasks.Task<global::tryAGI.OpenAI.AutoSDKHttpResponse<string>> CreateCallAsResponseAsync(

global::tryAGI.OpenAI.RealtimeCallCreateRequest request,
global::System.Threading.CancellationToken cancellationToken = default)
{
Expand Down Expand Up @@ -122,7 +142,10 @@ partial void ProcessCreateCallResponseContent(
{
__response.EnsureSuccessStatusCode();

return __content;
return new global::tryAGI.OpenAI.AutoSDKHttpResponse<string>(
statusCode: __response.StatusCode,
headers: global::tryAGI.OpenAI.AutoSDKHttpResponse.CreateHeaders(__response),
body: __content);
}
catch (global::System.Exception __ex)
{
Expand Down Expand Up @@ -151,7 +174,10 @@ partial void ProcessCreateCallResponseContent(
#endif
).ConfigureAwait(false);

return __content;
return new global::tryAGI.OpenAI.AutoSDKHttpResponse<string>(
statusCode: __response.StatusCode,
headers: global::tryAGI.OpenAI.AutoSDKHttpResponse.CreateHeaders(__response),
body: __content);
}
catch (global::System.Exception __ex)
{
Expand Down
Loading