Skip to content

Commit 8871510

Browse files
committed
Code Cleanup and some renamings. Readme Update
1 parent 7faffde commit 8871510

28 files changed

+139
-67
lines changed

Anthropic.Playground/Program.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
using Anthropic.Extensions;
2-
using Anthropic.ObjectModels.RequestModels;
32
using Anthropic.Playground.TestHelpers;
43
using Anthropic.Services;
54
using LaserCatEyes.HttpClientListener;
65
using Microsoft.Extensions.Configuration;
76
using Microsoft.Extensions.DependencyInjection;
87

9-
108
var builder = new ConfigurationBuilder().AddUserSecrets<Program>();
119

1210
IConfiguration configuration = builder.Build();
@@ -18,7 +16,6 @@
1816
// It is in Beta version, if you don't want to use it just comment out below line.
1917
serviceCollection.AddLaserCatEyesHttpClientListener();
2018

21-
//if you want to use beta services you have to set UseBeta to true. Otherwise, it will use the stable version of Anthropic apis.
2219
serviceCollection.AddAnthropicService();
2320

2421
//serviceCollection.AddAnthropicService(options =>

Anthropic.Playground/TestHelpers/ChatTestHelper.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ public static async Task RunChatCompletionTest(IAnthropicService anthropicServic
5151
Console.WriteLine($"Exception occurred: {ex}");
5252
throw;
5353
}
54-
Console.WriteLine("---- 0 ----");
5554

55+
Console.WriteLine("---- 0 ----");
5656
}
5757

5858
/// <summary>
@@ -103,6 +103,7 @@ public static async Task RunChatCompletionStreamTest(IAnthropicService anthropic
103103
Console.WriteLine($"Exception occurred: {ex}");
104104
throw;
105105
}
106+
106107
Console.WriteLine("---- 0 ----");
107108
}
108109
}

Anthropic.Playground/TestHelpers/ChatToolUseTestHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static async Task RunChatCompletionWithToolUseTest(IAnthropicService anth
5151
{
5252
continue;
5353
}
54+
5455
switch (content.Type)
5556
{
5657
case "text":

Anthropic/ObjectModels/AnthropicOptions.cs renamed to Anthropic/ApiModels/AnthropicOptions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ public class AnthropicOptions
1212
/// </summary>
1313
public static readonly string SettingKey = "AnthropicServiceOptions";
1414

15-
private string? _providerVersion;
1615
private string? _apiVersion;
1716
private string? _baseDomain;
1817

18+
private string? _providerVersion;
19+
1920

2021
public AnthropicProviderType ProviderType { get; set; } = AnthropicProviderType.Anthropic;
2122

Anthropic/ObjectModels/RequestModels/MessageRequest.cs renamed to Anthropic/ApiModels/RequestModels/MessageRequest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System.Text.Json.Serialization;
2+
using Anthropic.ObjectModels;
23
using Anthropic.ObjectModels.SharedModels;
34

4-
namespace Anthropic.ObjectModels.RequestModels;
5+
namespace Anthropic.ApiModels.RequestModels;
56

67
/// <summary>
78
/// Represents a request to create a message using the Anthropic API.
@@ -13,7 +14,6 @@ public MessageRequest()
1314
}
1415

1516
/// <summary>
16-
///
1717
/// </summary>
1818
/// <param name="messages"></param>
1919
/// <param name="maxTokens"></param>
@@ -29,14 +29,14 @@ public MessageRequest(List<Message> messages, int maxTokens, string? model = nul
2929
/// <summary>
3030
/// Gets or sets the maximum number of tokens to generate before stopping.
3131
/// </summary>
32-
/// <remarks> Required </remarks>
32+
/// <remarks> Required </remarks>
3333
[JsonPropertyName("max_tokens")]
3434
public int MaxTokens { get; set; }
3535

3636
/// <summary>
3737
/// Gets or sets the input messages for the conversation.
3838
/// </summary>
39-
/// <remarks> Required </remarks>
39+
/// <remarks> Required </remarks>
4040
[JsonPropertyName("messages")]
4141
public List<Message> Messages { get; set; }
4242

@@ -86,7 +86,7 @@ public MessageRequest(List<Message> messages, int maxTokens, string? model = nul
8686
/// <summary>
8787
/// Gets or sets the model that will complete the prompt.
8888
/// </summary>
89-
/// <remarks> Required </remarks>
89+
/// <remarks> Required </remarks>
9090
[JsonPropertyName("model")]
9191
public string Model { get; set; }
9292
}

Anthropic/ObjectModels/ResponseModels/BaseResponse.cs renamed to Anthropic/ApiModels/ResponseModels/BaseResponse.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,24 @@
44
using Anthropic.ObjectModels.SharedModels;
55

66
namespace Anthropic.ObjectModels.ResponseModels;
7-
public class TypeBaseResponse:IType
7+
8+
public class TypeBaseResponse : IType
89
{
910
[JsonPropertyName("type")]
1011
public string Type { get; set; }
1112
}
13+
1214
public interface IType
1315
{
1416
[JsonPropertyName("type")]
1517
public string Type { get; set; }
1618
}
1719

18-
public interface IStreamResponse:IType
20+
public interface IStreamResponse : IType
1921
{
2022
public string? StreamEvent { get; set; }
2123
}
24+
2225
public static class StreamResponseExtensions
2326
{
2427
public static T As<T>(this IStreamResponse response) where T : class, IStreamResponse
@@ -42,24 +45,26 @@ public static bool TryAs<T>(this IStreamResponse response, out T result) where T
4245
result = null;
4346
return false;
4447
}
45-
4648
}
49+
4750
public static class StreamExtensions
4851
{
4952
public static bool IsMessageResponse(this IStreamResponse response)
5053
{
5154
return response.Type == "message";
5255
}
56+
5357
public static bool IsPingResponse(this IStreamResponse response)
5458
{
5559
return response.Type == "ping";
5660
}
61+
5762
public static bool IsError(this IStreamResponse response)
5863
{
5964
return response.Type == "error";
6065
}
61-
6266
}
67+
6368
public class BaseResponse : TypeBaseResponse, IStreamResponse
6469
{
6570
/// <summary>
@@ -74,8 +79,6 @@ public class BaseResponse : TypeBaseResponse, IStreamResponse
7479
[JsonPropertyName("usage")]
7580
public Usage? Usage { get; set; }
7681

77-
[JsonPropertyName("StreamEvent")]
78-
public string? StreamEvent { get; set; }
7982
public bool IsDelta => StreamEvent?.EndsWith("delta") ?? false;
8083

8184
public HttpStatusCode HttpStatusCode { get; set; }
@@ -85,27 +88,30 @@ public class BaseResponse : TypeBaseResponse, IStreamResponse
8588
public Error? Error { get; set; }
8689

8790
public bool Successful => Error == null;
91+
92+
[JsonPropertyName("StreamEvent")]
93+
public string? StreamEvent { get; set; }
8894
}
8995

90-
public class Error:TypeBaseResponse
96+
public class Error : TypeBaseResponse
9197
{
9298
[JsonPropertyName("message")]
9399
public string Message { get; set; } = string.Empty;
94100
}
95101

96102
/// <summary>
97-
/// Represents Anthropic-specific headers in an HTTP response.
103+
/// Represents Anthropic-specific headers in an HTTP response.
98104
/// </summary>
99105
/// <remarks>
100-
/// Initializes a new instance of the AnthropicHeaders class from HttpResponseHeaders.
106+
/// Initializes a new instance of the AnthropicHeaders class from HttpResponseHeaders.
101107
/// </remarks>
102108
public class AnthropicHeaders
103109
{
104110
/// <summary>
105-
/// Represents Anthropic-specific headers in an HTTP response.
111+
/// Represents Anthropic-specific headers in an HTTP response.
106112
/// </summary>
107113
/// <remarks>
108-
/// Initializes a new instance of the AnthropicHeaders class from HttpResponseHeaders.
114+
/// Initializes a new instance of the AnthropicHeaders class from HttpResponseHeaders.
109115
/// </remarks>
110116
/// <param name="headers">The HTTP response headers.</param>
111117
public AnthropicHeaders(HttpResponseHeaders headers)
@@ -114,7 +120,7 @@ public AnthropicHeaders(HttpResponseHeaders headers)
114120
}
115121

116122
/// <summary>
117-
/// Gets information about rate limits applied to the request.
123+
/// Gets information about rate limits applied to the request.
118124
/// </summary>
119125
public RateLimitInfo? RateLimit { get; }
120126
}

Anthropic/ObjectModels/ResponseModels/MessageResponse.cs renamed to Anthropic/ApiModels/ResponseModels/MessageResponse.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,12 @@
33

44
namespace Anthropic.ObjectModels.ResponseModels;
55

6-
public class PingResponse: BaseResponse, IStreamResponse
6+
public class PingResponse : BaseResponse, IStreamResponse
77
{
88
}
9+
910
public class MessageResponse : BaseResponse, IStreamResponse
1011
{
11-
12-
public override string? ToString()
13-
{
14-
return Content?.FirstOrDefault()?.Text;
15-
}
16-
1712
[JsonPropertyName("content")]
1813
[JsonConverter(typeof(JsonConverters.ContentConverter))]
1914
public List<ContentBlock>? Content { get; set; }
@@ -30,6 +25,11 @@ public class MessageResponse : BaseResponse, IStreamResponse
3025
[JsonPropertyName("stop_sequence")]
3126
public string? StopSequence { get; set; }
3227

28+
public override string? ToString()
29+
{
30+
return Content?.FirstOrDefault()?.Text;
31+
}
32+
3333
public Message ToMessage()
3434
{
3535
return new()

Anthropic/ObjectModels/ResponseModels/RateLimitInfo.cs renamed to Anthropic/ApiModels/ResponseModels/RateLimitInfo.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
namespace Anthropic.ObjectModels.ResponseModels;
55

66
/// <summary>
7-
/// Represents rate limit information from Anthropic API headers.
7+
/// Represents rate limit information from Anthropic API headers.
88
/// </summary>
99
/// <remarks>
10-
/// Initializes a new instance of the RateLimitInfo class from HttpResponseHeaders.
10+
/// Initializes a new instance of the RateLimitInfo class from HttpResponseHeaders.
1111
/// </remarks>
1212
public class RateLimitInfo
1313
{
1414
/// <summary>
15-
/// Represents rate limit information from Anthropic API headers.
15+
/// Represents rate limit information from Anthropic API headers.
1616
/// </summary>
1717
/// <remarks>
18-
/// Initializes a new instance of the RateLimitInfo class from HttpResponseHeaders.
18+
/// Initializes a new instance of the RateLimitInfo class from HttpResponseHeaders.
1919
/// </remarks>
2020
/// <param name="headers">The HTTP response headers.</param>
2121
public RateLimitInfo(HttpResponseHeaders headers)
@@ -30,37 +30,37 @@ public RateLimitInfo(HttpResponseHeaders headers)
3030
}
3131

3232
/// <summary>
33-
/// Gets the maximum number of requests allowed within any rate limit period.
33+
/// Gets the maximum number of requests allowed within any rate limit period.
3434
/// </summary>
3535
public int? RequestsLimit { get; }
3636

3737
/// <summary>
38-
/// Gets the number of requests remaining before being rate limited.
38+
/// Gets the number of requests remaining before being rate limited.
3939
/// </summary>
4040
public int? RequestsRemaining { get; }
4141

4242
/// <summary>
43-
/// Gets the time when the request rate limit will reset, provided in RFC 3339 format.
43+
/// Gets the time when the request rate limit will reset, provided in RFC 3339 format.
4444
/// </summary>
4545
public DateTimeOffset? RequestsReset { get; }
4646

4747
/// <summary>
48-
/// Gets the maximum number of tokens allowed within any rate limit period.
48+
/// Gets the maximum number of tokens allowed within any rate limit period.
4949
/// </summary>
5050
public int? TokensLimit { get; }
5151

5252
/// <summary>
53-
/// Gets the number of tokens remaining (rounded to the nearest thousand) before being rate limited.
53+
/// Gets the number of tokens remaining (rounded to the nearest thousand) before being rate limited.
5454
/// </summary>
5555
public int? TokensRemaining { get; }
5656

5757
/// <summary>
58-
/// Gets the time when the token rate limit will reset, provided in RFC 3339 format.
58+
/// Gets the time when the token rate limit will reset, provided in RFC 3339 format.
5959
/// </summary>
6060
public DateTimeOffset? TokensReset { get; }
6161

6262
/// <summary>
63-
/// Gets the number of seconds until you can retry the request.
63+
/// Gets the number of seconds until you can retry the request.
6464
/// </summary>
6565
public int? RetryAfter { get; }
6666

@@ -70,6 +70,7 @@ public RateLimitInfo(HttpResponseHeaders headers)
7070
{
7171
return value;
7272
}
73+
7374
return null;
7475
}
7576

@@ -79,6 +80,7 @@ public RateLimitInfo(HttpResponseHeaders headers)
7980
{
8081
return value;
8182
}
83+
8284
return null;
8385
}
8486
}

0 commit comments

Comments
 (0)