Skip to content

Commit

Permalink
fix: Fixed generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HavenDV committed Dec 18, 2024
1 parent d066bbc commit 1424c75
Show file tree
Hide file tree
Showing 306 changed files with 10,280 additions and 9,978 deletions.
2 changes: 0 additions & 2 deletions src/helpers/FixOpenApiSpec/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@
openApiDocument.Components.Schemas["Tool"].Properties["input_schema"].Type = "object";
openApiDocument.Components.Schemas["BetaTool"].Properties["input_schema"].AllOf.Clear();
openApiDocument.Components.Schemas["BetaTool"].Properties["input_schema"].Type = "object";
openApiDocument.Components.Schemas["PromptCachingBetaTool"].Properties["input_schema"].AllOf.Clear();
openApiDocument.Components.Schemas["PromptCachingBetaTool"].Properties["input_schema"].Type = "object";

openApiDocument.Components.SecuritySchemes.Clear();
openApiDocument.Components.SecuritySchemes.Add("ApiKeyAuth", new OpenApiSecurityScheme
Expand Down
12 changes: 6 additions & 6 deletions src/libs/Anthropic/Extensions/AnthropicClient.ChatClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,17 +166,17 @@ private static CreateMessageParams CreateRequest(IList<ChatMessage> chatMessages
continue;
}

List<ContentVariant2Item2> blocks = [];
List<InputContentBlock> blocks = [];
foreach (var content in chatMessage.Contents)
{
switch (content)
{
case TextContent tc:
blocks.Add(new ContentVariant2Item2(new RequestTextBlock { Text = tc.Text }));
blocks.Add(new InputContentBlock(new RequestTextBlock { Text = tc.Text }));
break;

case ImageContent ic when ic.ContainsData:
blocks.Add(new ContentVariant2Item2(new RequestImageBlock
blocks.Add(new InputContentBlock(new RequestImageBlock
{
Source = new Base64ImageSource
{
Expand All @@ -194,7 +194,7 @@ private static CreateMessageParams CreateRequest(IList<ChatMessage> chatMessages
break;

case FunctionCallContent fcc:
blocks.Add(new ContentVariant2Item2(new RequestToolUseBlock
blocks.Add(new InputContentBlock(new RequestToolUseBlock
{
Id = fcc.CallId,
Name = fcc.Name,
Expand All @@ -203,7 +203,7 @@ private static CreateMessageParams CreateRequest(IList<ChatMessage> chatMessages
break;

case FunctionResultContent frc:
blocks.Add(new ContentVariant2Item2(new RequestToolResultBlock
blocks.Add(new InputContentBlock(new RequestToolResultBlock
{
ToolUseId = frc.CallId,
Content = frc.Result?.ToString() ?? string.Empty,
Expand All @@ -212,7 +212,7 @@ private static CreateMessageParams CreateRequest(IList<ChatMessage> chatMessages
break;
}

foreach (ContentVariant2Item2 block in blocks)
foreach (InputContentBlock block in blocks)
{
messages.Add(new InputMessage
{
Expand Down
8 changes: 4 additions & 4 deletions src/libs/Anthropic/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static InputMessage AsToolCall(this string content, ResponseToolUseBlock
return new InputMessage
{
Role = InputMessageRole.User,
Content = new List<ContentVariant2Item2>
Content = new List<InputContentBlock>
{
new RequestToolResultBlock
{
Expand All @@ -72,22 +72,22 @@ public static InputMessage AsInputMessage(this Message message)
{
if (x.IsText)
{
return new ContentVariant2Item2(new RequestTextBlock
return new InputContentBlock(new RequestTextBlock
{
Text = x.Text!.Text,
});
}
if (x.IsToolUse)
{
return new ContentVariant2Item2(new RequestToolUseBlock
return new InputContentBlock(new RequestToolUseBlock
{
Id = x.ToolUse!.Id,
Input = x.ToolUse.Input,
Name = x.ToolUse!.Name,
});
}

return new ContentVariant2Item2();
return new InputContentBlock();
}).ToList(),
Role = InputMessageRole.Assistant,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@

#nullable enable

namespace Anthropic
{
public partial class AnthropicClient
{
partial void PrepareBetaModelsGetArguments(
global::System.Net.Http.HttpClient httpClient,
ref string modelId,
ref string? anthropicVersion,
ref string? xApiKey);
partial void PrepareBetaModelsGetRequest(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpRequestMessage httpRequestMessage,
string modelId,
string? anthropicVersion,
string? xApiKey);
partial void ProcessBetaModelsGetResponse(
global::System.Net.Http.HttpClient httpClient,
global::System.Net.Http.HttpResponseMessage httpResponseMessage);

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

/// <summary>
/// Get a Model<br/>
/// Get a specific model.<br/>
/// The Models API response can be used to determine information about a specific model or resolve a model alias to a model ID.
/// </summary>
/// <param name="modelId">
/// Model identifier or alias.
/// </param>
/// <param name="anthropicVersion">
/// The version of the Anthropic API you want to use.<br/>
/// Read more about versioning and our version history [here](https://docs.anthropic.com/en/api/versioning).
/// </param>
/// <param name="xApiKey">
/// Your unique API key for authentication. <br/>
/// This key is required in the header of all API requests, to authenticate your account and access Anthropic's services. Get your API key through the [Console](https://console.anthropic.com/settings/keys). Each key is scoped to a Workspace.
/// </param>
/// <param name="cancellationToken">The token to cancel the operation with</param>
/// <exception cref="global::Anthropic.ApiException"></exception>
public async global::System.Threading.Tasks.Task<global::Anthropic.BetaModelResponse> BetaModelsGetAsync(
string modelId,
string? anthropicVersion = default,
string? xApiKey = default,
global::System.Threading.CancellationToken cancellationToken = default)
{
PrepareArguments(
client: HttpClient);
PrepareBetaModelsGetArguments(
httpClient: HttpClient,
modelId: ref modelId,
anthropicVersion: ref anthropicVersion,
xApiKey: ref xApiKey);

var __pathBuilder = new PathBuilder(
path: $"/v1/models/{modelId}?beta=true",
baseUri: HttpClient.BaseAddress);
var __path = __pathBuilder.ToString();
using var __httpRequest = new global::System.Net.Http.HttpRequestMessage(
method: global::System.Net.Http.HttpMethod.Get,
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 (anthropicVersion != default)
{
__httpRequest.Headers.TryAddWithoutValidation("anthropic-version", anthropicVersion.ToString());
}
if (xApiKey != default)
{
__httpRequest.Headers.TryAddWithoutValidation("x-api-key", xApiKey.ToString());
}


PrepareRequest(
client: HttpClient,
request: __httpRequest);
PrepareBetaModelsGetRequest(
httpClient: HttpClient,
httpRequestMessage: __httpRequest,
modelId: modelId,
anthropicVersion: anthropicVersion,
xApiKey: xApiKey);

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

ProcessResponse(
client: HttpClient,
response: __response);
ProcessBetaModelsGetResponse(
httpClient: HttpClient,
httpResponseMessage: __response);
// Error response. See our [errors documentation](https://docs.anthropic.com/en/api/errors) for more details.
if ((int)__response.StatusCode >= 400 && (int)__response.StatusCode <= 499)
{
string? __content_4XX = null;
global::Anthropic.BetaErrorResponse? __value_4XX = null;
if (ReadResponseAsString)
{
__content_4XX = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
__value_4XX = global::Anthropic.BetaErrorResponse.FromJson(__content_4XX, JsonSerializerContext);
}
else
{
var __contentStream_4XX = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
__value_4XX = await global::Anthropic.BetaErrorResponse.FromJsonStreamAsync(__contentStream_4XX, JsonSerializerContext).ConfigureAwait(false);
}

throw new global::Anthropic.ApiException<global::Anthropic.BetaErrorResponse>(
message: __response.ReasonPhrase ?? string.Empty,
statusCode: __response.StatusCode)
{
ResponseBody = __content_4XX,
ResponseObject = __value_4XX,
ResponseHeaders = global::System.Linq.Enumerable.ToDictionary(
__response.Headers,
h => h.Key,
h => h.Value),
};
}

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

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

try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Anthropic.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),
};
}

return
global::Anthropic.BetaModelResponse.FromJson(__content, JsonSerializerContext) ??
throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" ");
}
else
{
try
{
__response.EnsureSuccessStatusCode();
}
catch (global::System.Net.Http.HttpRequestException __ex)
{
throw new global::Anthropic.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),
};
}

using var __content = await __response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);

return
await global::Anthropic.BetaModelResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ??
throw new global::System.InvalidOperationException("Response deserialization failed.");
}
}
}
}
Loading

0 comments on commit 1424c75

Please sign in to comment.