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
Expand Up @@ -15,6 +15,8 @@ namespace DeepInfra
{
typeof(global::DeepInfra.JsonConverters.SuspendReasonJsonConverter),
typeof(global::DeepInfra.JsonConverters.SuspendReasonNullableJsonConverter),
typeof(global::DeepInfra.JsonConverters.AnthropicSystemContentTypeJsonConverter),
typeof(global::DeepInfra.JsonConverters.AnthropicSystemContentTypeNullableJsonConverter),
typeof(global::DeepInfra.JsonConverters.BodyOpenaiAudioTranscriptionsV1AudioTranscriptionsPostResponseFormatJsonConverter),
typeof(global::DeepInfra.JsonConverters.BodyOpenaiAudioTranscriptionsV1AudioTranscriptionsPostResponseFormatNullableJsonConverter),
typeof(global::DeepInfra.JsonConverters.BodyOpenaiAudioTranscriptionsV1AudioTranscriptionsPostTimestampGranularitieJsonConverter),
Expand Down Expand Up @@ -82,6 +84,8 @@ namespace DeepInfra
typeof(global::DeepInfra.JsonConverters.ContainerRentalsListV1ContainersGetStateJsonConverter),
typeof(global::DeepInfra.JsonConverters.ContainerRentalsListV1ContainersGetStateNullableJsonConverter),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, int?>),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, global::System.Collections.Generic.IList<global::DeepInfra.AnthropicSystemContent>>),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, global::System.Collections.Generic.IList<global::DeepInfra.AnthropicSystemContent>>),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, global::System.Collections.Generic.IList<global::DeepInfra.ChatCompletionContentPartText>>),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, global::System.Collections.Generic.IList<global::DeepInfra.ChatCompletionContentPartText>>),
typeof(global::DeepInfra.JsonConverters.AnyOfJsonConverter<string, global::System.Collections.Generic.IList<global::DeepInfra.AnyOf<global::DeepInfra.ChatCompletionContentPartText, global::DeepInfra.ChatCompletionContentPartImage, global::DeepInfra.ChatCompletionContentPartAudio>>>),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,341 @@

#nullable enable

namespace DeepInfra
{
public partial class DeepInfraClient
{
partial void PrepareAnthropicMessagesArguments(
global::System.Net.Http.HttpClient httpClient,
ref string? authorization,
ref string? xApiKey,
ref string? anthropicVersion,
ref string? anthropicBeta,
ref string? xDeepinfraSource,
ref string? userAgent,
global::DeepInfra.AnthropicMessagesIn request);
partial void PrepareAnthropicMessagesRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string? authorization,
string? xApiKey,
string? anthropicVersion,
string? anthropicBeta,
string? xDeepinfraSource,
string? userAgent,
global::DeepInfra.AnthropicMessagesIn request);
partial void ProcessAnthropicMessagesResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

partial void ProcessAnthropicMessagesResponseContent(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage,
ref string content);

/// <summary>
/// Anthropic Messages
/// </summary>
/// <param name="authorization"></param>
/// <param name="xApiKey"></param>
/// <param name="anthropicVersion"></param>
/// <param name="anthropicBeta"></param>
/// <param name="xDeepinfraSource"></param>
/// <param name="userAgent"></param>
/// <param name="request"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::DeepInfra.ApiException"></exception>
public async global::System.Threading.Tasks.Task<string> AnthropicMessagesAsync(
global::DeepInfra.AnthropicMessagesIn request,
string? authorization = default,
string? xApiKey = default,
string? anthropicVersion = default,
string? anthropicBeta = default,
string? xDeepinfraSource = default,
string? userAgent = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
request = request ?? throw new global::System.ArgumentNullException(nameof(request));

PrepareArguments(
client: HttpClient);
PrepareAnthropicMessagesArguments(
httpClient: HttpClient,
authorization: ref authorization,
xApiKey: ref xApiKey,
anthropicVersion: ref anthropicVersion,
anthropicBeta: ref anthropicBeta,
xDeepinfraSource: ref xDeepinfraSource,
userAgent: ref userAgent,
request: request);

var __pathBuilder = new global::DeepInfra.PathBuilder(
path: "/anthropic/v1/messages",
baseUri: HttpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Post,
requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute));
#if NET6_0_OR_GREATER
__httpRequest.Version = global::System.Net.HttpVersion.Version11;
__httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher;
#endif

foreach (var __authorization in Authorizations)
{
if (__authorization.Type == "Http" ||
__authorization.Type == "OAuth2")
{
__httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue(
scheme: __authorization.Name,
parameter: __authorization.Value);
}
else if (__authorization.Type == "ApiKey" &&
__authorization.Location == "Header")
{
__httpRequest.Headers.Add(__authorization.Name, __authorization.Value);
}
}

if (authorization != default)
{
__httpRequest.Headers.TryAddWithoutValidation("authorization", authorization.ToString());
}
if (xApiKey != default)
{
__httpRequest.Headers.TryAddWithoutValidation("x-api-key", xApiKey.ToString());
}
if (anthropicVersion != default)
{
__httpRequest.Headers.TryAddWithoutValidation("anthropic-version", anthropicVersion.ToString());
}
if (anthropicBeta != default)
{
__httpRequest.Headers.TryAddWithoutValidation("anthropic-beta", anthropicBeta.ToString());
}
if (xDeepinfraSource != default)
{
__httpRequest.Headers.TryAddWithoutValidation("x-deepinfra-source", xDeepinfraSource.ToString());
}
if (userAgent != default)
{
__httpRequest.Headers.TryAddWithoutValidation("user-agent", userAgent.ToString());
}

var __httpRequestContentBody = request.ToJson(JsonSerializerContext);
var __httpRequestContent = new global::System.Net.Http.StringContent(
content: __httpRequestContentBody,
encoding: global::System.Text.Encoding.UTF8,
mediaType: "application/json");
__httpRequest.Content = __httpRequestContent;

PrepareRequest(
client: HttpClient,
request: __httpRequest);
PrepareAnthropicMessagesRequest(
httpClient: HttpClient,
httpRequestMessage: __httpRequest,
authorization: authorization,
xApiKey: xApiKey,
anthropicVersion: anthropicVersion,
anthropicBeta: anthropicBeta,
xDeepinfraSource: xDeepinfraSource,
userAgent: userAgent,
request: request);

using var __response = await HttpClient.SendAsync(
request: __httpRequest,
completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead,
cancellationToken: cancellationToken).ConfigureAwait(false);

ProcessResponse(
client: HttpClient,
response: __response);
ProcessAnthropicMessagesResponse(
httpClient: HttpClient,
httpResponseMessage: __response);
// Validation Error
if ((int)__response.StatusCode == 422)
{
string? __content_422 = null;
global::System.Exception? __exception_422 = null;
global::DeepInfra.HTTPValidationError? __value_422 = null;
try
{
if (ReadResponseAsString)
{
__content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
__value_422 = global::DeepInfra.HTTPValidationError.FromJson(__content_422, JsonSerializerContext);
}
else
{
var __contentStream_422 = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
__value_422 = await global::DeepInfra.HTTPValidationError.FromJsonStreamAsync(__contentStream_422, JsonSerializerContext).ConfigureAwait(false);
}
}
catch (global::System.Exception __ex)
{
__exception_422 = __ex;
}

throw new global::DeepInfra.ApiException<global::DeepInfra.HTTPValidationError>(
message: __content_422 ?? __response.ReasonPhrase ?? string.Empty,
innerException: __exception_422,
statusCode: __response.StatusCode)
{
ResponseBody = __content_422,
ResponseObject = __value_422,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

if (ReadResponseAsString)
{
var __content = await __response.Content.ReadAsStringAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

ProcessResponseContent(
client: HttpClient,
response: __response,
content: ref __content);
ProcessAnthropicMessagesResponseContent(
httpClient: HttpClient,
httpResponseMessage: __response,
content: ref __content);

try
{
__response.EnsureSuccessStatusCode();

return __content;
}
catch (global::System.Exception __ex)
{
throw new global::DeepInfra.ApiException(
message: __content ?? __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseBody = __content,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
}
else
{
try
{
__response.EnsureSuccessStatusCode();

var __content = await __response.Content.ReadAsStringAsync(
#if NET5_0_OR_GREATER
cancellationToken
#endif
).ConfigureAwait(false);

return __content;
}
catch (global::System.Exception __ex)
{
throw new global::DeepInfra.ApiException(
message: __response.ReasonPhrase ?? string.Empty,
innerException: __ex,
statusCode: __response.StatusCode)
{
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}
}
}

/// <summary>
/// Anthropic Messages
/// </summary>
/// <param name="authorization"></param>
/// <param name="xApiKey"></param>
/// <param name="anthropicVersion"></param>
/// <param name="anthropicBeta"></param>
/// <param name="xDeepinfraSource"></param>
/// <param name="userAgent"></param>
/// <param name="model"></param>
/// <param name="maxTokens"></param>
/// <param name="messages"></param>
/// <param name="system"></param>
/// <param name="stopSequences"></param>
/// <param name="stream">
/// Default Value: false
/// </param>
/// <param name="temperature">
/// Default Value: 1
/// </param>
/// <param name="topP"></param>
/// <param name="topK"></param>
/// <param name="metadata"></param>
/// <param name="tools"></param>
/// <param name="toolChoice"></param>
/// <param name="thinking"></param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::System.InvalidOperationException"></exception>
public async global::System.Threading.Tasks.Task<string> AnthropicMessagesAsync(
string model,
global::System.Collections.Generic.IList<object> messages,
string? authorization = default,
string? xApiKey = default,
string? anthropicVersion = default,
string? anthropicBeta = default,
string? xDeepinfraSource = default,
string? userAgent = default,
int? maxTokens = default,
global::DeepInfra.AnyOf<string, global::System.Collections.Generic.IList<global::DeepInfra.AnthropicSystemContent>>? system = default,
global::System.Collections.Generic.IList<string>? stopSequences = default,
bool? stream = default,
double? temperature = default,
double? topP = default,
int? topK = default,
object? metadata = default,
global::System.Collections.Generic.IList<global::DeepInfra.AnthropicTool>? tools = default,
object? toolChoice = default,
global::DeepInfra.AnthropicThinkingConfig? thinking = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
var __request = new global::DeepInfra.AnthropicMessagesIn
{
Model = model,
MaxTokens = maxTokens,
Messages = messages,
System = system,
StopSequences = stopSequences,
Stream = stream,
Temperature = temperature,
TopP = topP,
TopK = topK,
Metadata = metadata,
Tools = tools,
ToolChoice = toolChoice,
Thinking = thinking,
};

return await AnthropicMessagesAsync(
authorization: authorization,
xApiKey: xApiKey,
anthropicVersion: anthropicVersion,
anthropicBeta: anthropicBeta,
xDeepinfraSource: xDeepinfraSource,
userAgent: userAgent,
request: __request,
cancellationToken: cancellationToken).ConfigureAwait(false);
}
}
}
Loading