docs: work on README
This commit is contained in:
@@ -5,7 +5,7 @@ public class MessageCompleteEventDataTests
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var expectedMessage = new ChatResponse();
|
||||
var expectedMessage = new MessageResponse();
|
||||
var expectedHeaders = new AnthropicHeaders();
|
||||
|
||||
var messageCompleteEventData = new MessageCompleteEventData(expectedMessage, expectedHeaders);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class MessageDeltaEventDataTests : SerializationTest
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var expectedDelta = new MessageDelta("max_tokens", "max_tokens");
|
||||
var expectedUsage = new ChatUsage { InputTokens = 1, OutputTokens = 1 };
|
||||
var expectedUsage = new Usage { InputTokens = 1, OutputTokens = 1 };
|
||||
|
||||
var messageDeltaEventData = new MessageDeltaEventData(expectedDelta, expectedUsage);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class MessageDeltaEventDataTests : SerializationTest
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var expectedDelta = new MessageDelta("max_tokens", "max_tokens");
|
||||
var expectedUsage = new ChatUsage { InputTokens = 1, OutputTokens = 1 };
|
||||
var expectedUsage = new Usage { InputTokens = 1, OutputTokens = 1 };
|
||||
|
||||
var messageDeltaEventData = new MessageDeltaEventData(expectedDelta, expectedUsage);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class MessageDeltaEventDataTests : SerializationTest
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedValues()
|
||||
{
|
||||
var expectedDelta = new MessageDelta("max_tokens", "max_tokens");
|
||||
var expectedUsage = new ChatUsage { InputTokens = 1, OutputTokens = 1 };
|
||||
var expectedUsage = new Usage { InputTokens = 1, OutputTokens = 1 };
|
||||
|
||||
var messageDeltaEventData = Deserialize<MessageDeltaEventData>(_testJson);
|
||||
|
||||
|
||||
+113
-113
@@ -1,6 +1,6 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ChatMessageRequestTests : SerializationTest
|
||||
public class MessageRequestTests : SerializationTest
|
||||
{
|
||||
private readonly string _testJson = @"{
|
||||
""model"": ""claude-3-sonnet-20240229"",
|
||||
@@ -152,7 +152,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var model = AnthropicModels.Claude3Sonnet;
|
||||
var messages = new List<ChatMessage> { new() };
|
||||
var messages = new List<Message> { new() };
|
||||
var maxTokens = 512;
|
||||
var system = "test-system";
|
||||
var metadata = new Dictionary<string, object> { ["test"] = "test" };
|
||||
@@ -162,7 +162,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var chatMessageRequest = new ChatMessageRequest(
|
||||
var messageRequest = new MessageRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
maxTokens: maxTokens,
|
||||
@@ -175,23 +175,23 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
tools: tools
|
||||
);
|
||||
|
||||
chatMessageRequest.Model.Should().Be(model);
|
||||
chatMessageRequest.Messages.Should().BeSameAs(messages);
|
||||
chatMessageRequest.MaxTokens.Should().Be(maxTokens);
|
||||
chatMessageRequest.System.Should().Be(system);
|
||||
chatMessageRequest.Metadata.Should().BeSameAs(metadata);
|
||||
chatMessageRequest.Temperature.Should().Be(temperature);
|
||||
chatMessageRequest.TopK.Should().Be(topK);
|
||||
chatMessageRequest.TopP.Should().Be(topP);
|
||||
chatMessageRequest.ToolChoice.Should().Be(toolChoice);
|
||||
chatMessageRequest.Tools.Should().BeSameAs(tools);
|
||||
chatMessageRequest.Stream.Should().BeFalse();
|
||||
messageRequest.Model.Should().Be(model);
|
||||
messageRequest.Messages.Should().BeSameAs(messages);
|
||||
messageRequest.MaxTokens.Should().Be(maxTokens);
|
||||
messageRequest.System.Should().Be(system);
|
||||
messageRequest.Metadata.Should().BeSameAs(metadata);
|
||||
messageRequest.Temperature.Should().Be(temperature);
|
||||
messageRequest.TopK.Should().Be(topK);
|
||||
messageRequest.TopP.Should().Be(topP);
|
||||
messageRequest.ToolChoice.Should().Be(toolChoice);
|
||||
messageRequest.Tools.Should().BeSameAs(tools);
|
||||
messageRequest.Stream.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: null!,
|
||||
messages: [new()]
|
||||
);
|
||||
@@ -202,7 +202,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: null!
|
||||
);
|
||||
@@ -213,7 +213,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: "invalid-model",
|
||||
messages: [new()]
|
||||
);
|
||||
@@ -224,7 +224,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsEmpty_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: []
|
||||
);
|
||||
@@ -235,7 +235,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMaxTokensIsInvalid_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: [new()],
|
||||
maxTokens: 0
|
||||
@@ -249,7 +249,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[InlineData(2)]
|
||||
public void Constructor_WhenCalledAndTemperatureIsInvalid_ItShouldThrowArgumentException(decimal temperature)
|
||||
{
|
||||
var action = () => new ChatMessageRequest(
|
||||
var action = () => new MessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: [new()],
|
||||
temperature: temperature
|
||||
@@ -261,7 +261,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var messages = new List<ChatMessage>()
|
||||
var messages = new List<Message>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
@@ -283,7 +283,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var chatMessageRequest = new ChatMessageRequest(
|
||||
var messageRequest = new MessageRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
maxTokens: maxTokens,
|
||||
@@ -296,7 +296,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
tools: tools
|
||||
);
|
||||
|
||||
var actual = Serialize(chatMessageRequest);
|
||||
var actual = Serialize(messageRequest);
|
||||
|
||||
JsonAssert.Equal(_testJson, actual);
|
||||
}
|
||||
@@ -304,71 +304,71 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJson);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJson);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
chatMessageRequest.Stream.Should().BeFalse();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Stream.Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithAnyToolChoice_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJsonWithAnyToolChoice);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJsonWithAnyToolChoice);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AnyToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("any");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AnyToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("any");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithSpecificToolChoice_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJsonWithSpecificToolChoice);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJsonWithSpecificToolChoice);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<SpecificToolChoice>();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<SpecificToolChoice>();
|
||||
|
||||
var specificToolChoice = chatMessageRequest.ToolChoice as SpecificToolChoice;
|
||||
var specificToolChoice = messageRequest.ToolChoice as SpecificToolChoice;
|
||||
specificToolChoice!.Type.Should().Be("tool");
|
||||
specificToolChoice.Name.Should().Be("test-tool");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -376,7 +376,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
{
|
||||
var json = @"{""model"":""claude-3-sonnet-20240229"",""system"":""test-system"",""messages"":[{""role"":""user"",""content"":[{""text"":""Hello!"",""type"":""text""}]}],""max_tokens"":512,""metadata"":{""test"":""test""},""stop_sequences"":[],""temperature"":0.5,""topK"":10,""topP"":0.5,""tool_choice"":{""type"":""unknown""},""tools"":[{""name"":""test-tool"",""description"":""test-description"",""input_schema"":{""type"":""object"",""properties"":{""test-property"":{""type"":""string"",""description"":""test-description""}},""required"":[""test-property""]}}],""stream"":false}";
|
||||
|
||||
var action = () => Deserialize<ChatMessageRequest>(json);
|
||||
var action = () => Deserialize<MessageRequest>(json);
|
||||
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
@@ -384,27 +384,27 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithImageContent_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJsonWithImageContent);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJsonWithImageContent);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
chatMessageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
chatMessageRequest.Messages[0].Content[0].Should().BeOfType<ImageContent>();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
messageRequest.Messages[0].Content[0].Should().BeOfType<ImageContent>();
|
||||
|
||||
var imageContent = chatMessageRequest.Messages[0].Content[0] as ImageContent;
|
||||
var imageContent = messageRequest.Messages[0].Content[0] as ImageContent;
|
||||
imageContent!.Type.Should().Be("image");
|
||||
imageContent.Source.MediaType.Should().Be("image/jpeg");
|
||||
imageContent.Source.Data.Should().Be("data");
|
||||
@@ -413,27 +413,27 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithToolUseContent_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJsonWithToolUseContent);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJsonWithToolUseContent);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
chatMessageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
chatMessageRequest.Messages[0].Content[0].Should().BeOfType<ToolUseContent>();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
messageRequest.Messages[0].Content[0].Should().BeOfType<ToolUseContent>();
|
||||
|
||||
var toolUseContent = chatMessageRequest.Messages[0].Content[0] as ToolUseContent;
|
||||
var toolUseContent = messageRequest.Messages[0].Content[0] as ToolUseContent;
|
||||
toolUseContent!.Type.Should().Be("tool_use");
|
||||
toolUseContent.Name.Should().Be("test-tool");
|
||||
toolUseContent.Id.Should().Be("test-tool-id");
|
||||
@@ -444,27 +444,27 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithToolResultContent_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<ChatMessageRequest>(_testJsonWithToolResultContent);
|
||||
var messageRequest = Deserialize<MessageRequest>(_testJsonWithToolResultContent);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
chatMessageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
chatMessageRequest.Messages[0].Content[0].Should().BeOfType<ToolResultContent>();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Messages[0].Content.Should().HaveCount(1);
|
||||
messageRequest.Messages[0].Content[0].Should().BeOfType<ToolResultContent>();
|
||||
|
||||
var toolResultContent = chatMessageRequest.Messages[0].Content[0] as ToolResultContent;
|
||||
var toolResultContent = messageRequest.Messages[0].Content[0] as ToolResultContent;
|
||||
toolResultContent!.Type.Should().Be("tool_result");
|
||||
toolResultContent.ToolUseId.Should().Be("test-tool");
|
||||
toolResultContent.Content.Should().Be("test-value");
|
||||
@@ -473,7 +473,7 @@ public class ChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserializedWithUnknownContent_ItShouldThrowJsonException()
|
||||
{
|
||||
var action = () => Deserialize<ChatMessageRequest>(_testJsonWithUnknownContent);
|
||||
var action = () => Deserialize<MessageRequest>(_testJsonWithUnknownContent);
|
||||
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
+23
-23
@@ -1,6 +1,6 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ChatResponseTests : SerializationTest
|
||||
public class MessageResponseTests : SerializationTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldInitializeProperties()
|
||||
@@ -11,7 +11,7 @@ public class ChatResponseTests : SerializationTest
|
||||
var expectedStopReason = "stop reason";
|
||||
var expectedStopSequence = "stop sequence";
|
||||
var expectedType = "type";
|
||||
var expectedUsage = new ChatUsage
|
||||
var expectedUsage = new Usage
|
||||
{
|
||||
InputTokens = 1,
|
||||
OutputTokens = 2
|
||||
@@ -21,7 +21,7 @@ public class ChatResponseTests : SerializationTest
|
||||
new TextContent("text content"),
|
||||
};
|
||||
|
||||
var chatResponse = new ChatResponse
|
||||
var messageResponse = new MessageResponse
|
||||
{
|
||||
Id = expectedId,
|
||||
Model = expectedModel,
|
||||
@@ -33,14 +33,14 @@ public class ChatResponseTests : SerializationTest
|
||||
Content = expectedContent
|
||||
};
|
||||
|
||||
chatResponse.Id.Should().Be(expectedId);
|
||||
chatResponse.Model.Should().Be(expectedModel);
|
||||
chatResponse.Role.Should().Be(expectedRole);
|
||||
chatResponse.StopReason.Should().Be(expectedStopReason);
|
||||
chatResponse.StopSequence.Should().Be(expectedStopSequence);
|
||||
chatResponse.Type.Should().Be(expectedType);
|
||||
chatResponse.Usage.Should().BeEquivalentTo(expectedUsage);
|
||||
chatResponse.Content.Should().BeEquivalentTo(expectedContent);
|
||||
messageResponse.Id.Should().Be(expectedId);
|
||||
messageResponse.Model.Should().Be(expectedModel);
|
||||
messageResponse.Role.Should().Be(expectedRole);
|
||||
messageResponse.StopReason.Should().Be(expectedStopReason);
|
||||
messageResponse.StopSequence.Should().Be(expectedStopSequence);
|
||||
messageResponse.Type.Should().Be(expectedType);
|
||||
messageResponse.Usage.Should().BeEquivalentTo(expectedUsage);
|
||||
messageResponse.Content.Should().BeEquivalentTo(expectedContent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -59,7 +59,7 @@ public class ChatResponseTests : SerializationTest
|
||||
]
|
||||
}";
|
||||
|
||||
var chatResponse = new ChatResponse
|
||||
var messageResponse = new MessageResponse
|
||||
{
|
||||
Id = "id",
|
||||
Model = "model",
|
||||
@@ -67,7 +67,7 @@ public class ChatResponseTests : SerializationTest
|
||||
StopReason = "stop reason",
|
||||
StopSequence = "stop sequence",
|
||||
Type = "type",
|
||||
Usage = new ChatUsage
|
||||
Usage = new Usage
|
||||
{
|
||||
InputTokens = 1,
|
||||
OutputTokens = 2
|
||||
@@ -78,7 +78,7 @@ public class ChatResponseTests : SerializationTest
|
||||
]
|
||||
};
|
||||
|
||||
var actual = Serialize(chatResponse);
|
||||
var actual = Serialize(messageResponse);
|
||||
|
||||
JsonAssert.Equal(expectedJson, actual);
|
||||
}
|
||||
@@ -99,20 +99,20 @@ public class ChatResponseTests : SerializationTest
|
||||
]
|
||||
}";
|
||||
|
||||
var chatResponse = Deserialize<ChatResponse>(json);
|
||||
var messageResponse = Deserialize<MessageResponse>(json);
|
||||
|
||||
chatResponse!.Id.Should().Be("id");
|
||||
chatResponse.Model.Should().Be("model");
|
||||
chatResponse.Role.Should().Be("role");
|
||||
chatResponse.StopReason.Should().Be("stop reason");
|
||||
chatResponse.StopSequence.Should().Be("stop sequence");
|
||||
chatResponse.Type.Should().Be("type");
|
||||
chatResponse.Usage.Should().BeEquivalentTo(new ChatUsage
|
||||
messageResponse!.Id.Should().Be("id");
|
||||
messageResponse.Model.Should().Be("model");
|
||||
messageResponse.Role.Should().Be("role");
|
||||
messageResponse.StopReason.Should().Be("stop reason");
|
||||
messageResponse.StopSequence.Should().Be("stop sequence");
|
||||
messageResponse.Type.Should().Be("type");
|
||||
messageResponse.Usage.Should().BeEquivalentTo(new Usage
|
||||
{
|
||||
InputTokens = 1,
|
||||
OutputTokens = 2
|
||||
});
|
||||
chatResponse.Content.Should().BeEquivalentTo(new List<Content>
|
||||
messageResponse.Content.Should().BeEquivalentTo(new List<Content>
|
||||
{
|
||||
new TextContent("text content"),
|
||||
});
|
||||
@@ -22,7 +22,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var expectedMessage = new ChatResponse
|
||||
var expectedMessage = new MessageResponse
|
||||
{
|
||||
Id = "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY",
|
||||
Type = "message",
|
||||
@@ -31,7 +31,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
Model = "claude-3-5-sonnet-20240620",
|
||||
StopReason = string.Empty,
|
||||
StopSequence = string.Empty,
|
||||
Usage = new ChatUsage { InputTokens = 25, OutputTokens = 1 }
|
||||
Usage = new Usage { InputTokens = 25, OutputTokens = 1 }
|
||||
};
|
||||
|
||||
var messageStartEventData = new MessageStartEventData(expectedMessage);
|
||||
@@ -42,7 +42,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var expectedMessage = new ChatResponse
|
||||
var expectedMessage = new MessageResponse
|
||||
{
|
||||
Id = "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY",
|
||||
Type = "message",
|
||||
@@ -51,7 +51,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
Model = "claude-3-5-sonnet-20240620",
|
||||
StopReason = string.Empty,
|
||||
StopSequence = string.Empty,
|
||||
Usage = new ChatUsage { InputTokens = 25, OutputTokens = 1 }
|
||||
Usage = new Usage { InputTokens = 25, OutputTokens = 1 }
|
||||
};
|
||||
|
||||
var messageStartEventData = new MessageStartEventData(expectedMessage);
|
||||
@@ -64,7 +64,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedValues()
|
||||
{
|
||||
var expectedMessage = new ChatResponse
|
||||
var expectedMessage = new MessageResponse
|
||||
{
|
||||
Id = "msg_1nZdL29xx5MUA1yADyHTEsnR8uuvGzszyY",
|
||||
Type = "message",
|
||||
@@ -73,7 +73,7 @@ public class MessageStartEventDataTests : SerializationTest
|
||||
Model = "claude-3-5-sonnet-20240620",
|
||||
StopReason = string.Empty,
|
||||
StopSequence = string.Empty,
|
||||
Usage = new ChatUsage { InputTokens = 25, OutputTokens = 1 }
|
||||
Usage = new Usage { InputTokens = 25, OutputTokens = 1 }
|
||||
};
|
||||
|
||||
var messageStartEventData = Deserialize<MessageStartEventData>(_testJson);
|
||||
|
||||
+16
-16
@@ -1,6 +1,6 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ChatMessageTests : SerializationTest
|
||||
public class MessageTests : SerializationTest
|
||||
{
|
||||
private readonly string _testJson = @"{
|
||||
""role"": ""assistant"",
|
||||
@@ -15,10 +15,10 @@ public class ChatMessageTests : SerializationTest
|
||||
var role = "assistant";
|
||||
var content = new List<Content> { new TextContent("text") };
|
||||
|
||||
var chatMessage = new ChatMessage(role, content);
|
||||
var message = new Message(role, content);
|
||||
|
||||
chatMessage.Role.Should().Be(role);
|
||||
chatMessage.Content.Should().BeSameAs(content);
|
||||
message.Role.Should().Be(role);
|
||||
message.Content.Should().BeSameAs(content);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -26,7 +26,7 @@ public class ChatMessageTests : SerializationTest
|
||||
{
|
||||
var content = new List<Content> { new TextContent("text") };
|
||||
|
||||
var action = () => new ChatMessage(null!, content);
|
||||
var action = () => new Message(null!, content);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class ChatMessageTests : SerializationTest
|
||||
{
|
||||
var role = "assistant";
|
||||
|
||||
var action = () => new ChatMessage(role, null!);
|
||||
var action = () => new Message(role, null!);
|
||||
|
||||
action.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public class ChatMessageTests : SerializationTest
|
||||
var role = "invalid";
|
||||
var content = new List<Content> { new TextContent("text") };
|
||||
|
||||
var action = () => new ChatMessage(role, content);
|
||||
var action = () => new Message(role, content);
|
||||
|
||||
action.Should().Throw<ArgumentException>();
|
||||
}
|
||||
@@ -57,22 +57,22 @@ public class ChatMessageTests : SerializationTest
|
||||
{
|
||||
var role = "assistant";
|
||||
var content = new List<Content> { new TextContent("text") };
|
||||
var chatMessage = new ChatMessage(role, content);
|
||||
var message = new Message(role, content);
|
||||
|
||||
var actual = Serialize(chatMessage);
|
||||
var actual = Serialize(message);
|
||||
|
||||
JsonAssert.Equal(_testJson, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldReturnChatMessage()
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldReturnMessage()
|
||||
{
|
||||
var chatMessage = Deserialize<ChatMessage>(_testJson);
|
||||
var message = Deserialize<Message>(_testJson);
|
||||
|
||||
chatMessage.Should().NotBeNull();
|
||||
chatMessage!.Role.Should().Be("assistant");
|
||||
chatMessage.Content.Should().HaveCount(1);
|
||||
chatMessage.Content[0].Should().BeOfType<TextContent>();
|
||||
chatMessage.Content[0].As<TextContent>().Text.Should().Be("text");
|
||||
message.Should().NotBeNull();
|
||||
message!.Role.Should().Be("assistant");
|
||||
message.Content.Should().HaveCount(1);
|
||||
message.Content[0].Should().BeOfType<TextContent>();
|
||||
message.Content[0].As<TextContent>().Text.Should().Be("text");
|
||||
}
|
||||
}
|
||||
+37
-37
@@ -1,6 +1,6 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class StreamChatMessageRequestTests : SerializationTest
|
||||
public class StreamMessageRequestTests : SerializationTest
|
||||
{
|
||||
private readonly string _testJson = @"{
|
||||
""model"": ""claude-3-sonnet-20240229"",
|
||||
@@ -23,7 +23,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
public void Constructor_WhenCalled_ItShouldInitializeProperties()
|
||||
{
|
||||
var model = AnthropicModels.Claude3Sonnet;
|
||||
var messages = new List<ChatMessage> { new() };
|
||||
var messages = new List<Message> { new() };
|
||||
var maxTokens = 512;
|
||||
var system = "test-system";
|
||||
var metadata = new Dictionary<string, object> { ["test"] = "test" };
|
||||
@@ -33,7 +33,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var chatMessageRequest = new StreamChatMessageRequest(
|
||||
var messageRequest = new StreamMessageRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
maxTokens: maxTokens,
|
||||
@@ -46,23 +46,23 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
tools: tools
|
||||
);
|
||||
|
||||
chatMessageRequest.Model.Should().Be(model);
|
||||
chatMessageRequest.Messages.Should().BeSameAs(messages);
|
||||
chatMessageRequest.MaxTokens.Should().Be(maxTokens);
|
||||
chatMessageRequest.System.Should().Be(system);
|
||||
chatMessageRequest.Metadata.Should().BeSameAs(metadata);
|
||||
chatMessageRequest.Temperature.Should().Be(temperature);
|
||||
chatMessageRequest.TopK.Should().Be(topK);
|
||||
chatMessageRequest.TopP.Should().Be(topP);
|
||||
chatMessageRequest.ToolChoice.Should().Be(toolChoice);
|
||||
chatMessageRequest.Tools.Should().BeSameAs(tools);
|
||||
chatMessageRequest.Stream.Should().BeTrue();
|
||||
messageRequest.Model.Should().Be(model);
|
||||
messageRequest.Messages.Should().BeSameAs(messages);
|
||||
messageRequest.MaxTokens.Should().Be(maxTokens);
|
||||
messageRequest.System.Should().Be(system);
|
||||
messageRequest.Metadata.Should().BeSameAs(metadata);
|
||||
messageRequest.Temperature.Should().Be(temperature);
|
||||
messageRequest.TopK.Should().Be(topK);
|
||||
messageRequest.TopP.Should().Be(topP);
|
||||
messageRequest.ToolChoice.Should().Be(toolChoice);
|
||||
messageRequest.Tools.Should().BeSameAs(tools);
|
||||
messageRequest.Stream.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: null!,
|
||||
messages: [new()]
|
||||
);
|
||||
@@ -73,7 +73,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsNull_ItShouldThrowArgumentNullException()
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: null!
|
||||
);
|
||||
@@ -84,7 +84,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndModelIsInvalid_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: "invalid-model",
|
||||
messages: [new()]
|
||||
);
|
||||
@@ -95,7 +95,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMessagesIsEmpty_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: []
|
||||
);
|
||||
@@ -106,7 +106,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void Constructor_WhenCalledAndMaxTokensIsInvalid_ItShouldThrowArgumentException()
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: [new()],
|
||||
maxTokens: 0
|
||||
@@ -120,7 +120,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[InlineData(2)]
|
||||
public void Constructor_WhenCalledAndTemperatureIsInvalid_ItShouldThrowArgumentException(decimal temperature)
|
||||
{
|
||||
var action = () => new StreamChatMessageRequest(
|
||||
var action = () => new StreamMessageRequest(
|
||||
model: AnthropicModels.Claude3Sonnet,
|
||||
messages: [new()],
|
||||
temperature: temperature
|
||||
@@ -132,7 +132,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var messages = new List<ChatMessage>()
|
||||
var messages = new List<Message>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
@@ -154,7 +154,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
var toolChoice = new AutoToolChoice();
|
||||
var tools = new List<Tool>();
|
||||
|
||||
var chatMessageRequest = new StreamChatMessageRequest(
|
||||
var messageRequest = new StreamMessageRequest(
|
||||
model: model,
|
||||
messages: messages,
|
||||
maxTokens: maxTokens,
|
||||
@@ -167,7 +167,7 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
tools: tools
|
||||
);
|
||||
|
||||
var actual = Serialize(chatMessageRequest);
|
||||
var actual = Serialize(messageRequest);
|
||||
|
||||
JsonAssert.Equal(_testJson, actual);
|
||||
}
|
||||
@@ -175,23 +175,23 @@ public class StreamChatMessageRequestTests : SerializationTest
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var chatMessageRequest = Deserialize<StreamChatMessageRequest>(_testJson);
|
||||
var messageRequest = Deserialize<StreamMessageRequest>(_testJson);
|
||||
|
||||
chatMessageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
chatMessageRequest.System.Should().Be("test-system");
|
||||
chatMessageRequest.Messages.Should().HaveCount(1);
|
||||
chatMessageRequest.MaxTokens.Should().Be(512);
|
||||
chatMessageRequest.Metadata.Should().HaveCount(1);
|
||||
messageRequest!.Model.Should().Be(AnthropicModels.Claude3Sonnet);
|
||||
messageRequest.System.Should().Be("test-system");
|
||||
messageRequest.Messages.Should().HaveCount(1);
|
||||
messageRequest.MaxTokens.Should().Be(512);
|
||||
messageRequest.Metadata.Should().HaveCount(1);
|
||||
|
||||
var testValue = chatMessageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
var testValue = messageRequest.Metadata!.GetValueOrDefault("test")!.ToString();
|
||||
testValue.Should().Be("test");
|
||||
|
||||
chatMessageRequest.Temperature.Should().Be(0.5m);
|
||||
chatMessageRequest.TopK.Should().Be(10);
|
||||
chatMessageRequest.TopP.Should().Be(0.5m);
|
||||
chatMessageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
chatMessageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
chatMessageRequest.Tools.Should().HaveCount(0);
|
||||
chatMessageRequest.Stream.Should().BeTrue();
|
||||
messageRequest.Temperature.Should().Be(0.5m);
|
||||
messageRequest.TopK.Should().Be(10);
|
||||
messageRequest.TopP.Should().Be(0.5m);
|
||||
messageRequest.ToolChoice.Should().BeOfType<AutoToolChoice>();
|
||||
messageRequest.ToolChoice!.Type.Should().Be("auto");
|
||||
messageRequest.Tools.Should().HaveCount(0);
|
||||
messageRequest.Stream.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
+9
-9
@@ -1,6 +1,6 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ChatUsageTests : SerializationTest
|
||||
public class UsageTests : SerializationTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ShouldInitializeProperties()
|
||||
@@ -8,14 +8,14 @@ public class ChatUsageTests : SerializationTest
|
||||
var expectedInputTokens = 1;
|
||||
var expectedOutputTokens = 2;
|
||||
|
||||
var chatUsage = new ChatUsage
|
||||
var usage = new Usage
|
||||
{
|
||||
InputTokens = expectedInputTokens,
|
||||
OutputTokens = expectedOutputTokens
|
||||
};
|
||||
|
||||
chatUsage.InputTokens.Should().Be(expectedInputTokens);
|
||||
chatUsage.OutputTokens.Should().Be(expectedOutputTokens);
|
||||
usage.InputTokens.Should().Be(expectedInputTokens);
|
||||
usage.OutputTokens.Should().Be(expectedOutputTokens);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -23,13 +23,13 @@ public class ChatUsageTests : SerializationTest
|
||||
{
|
||||
var expectedJson = @"{ ""input_tokens"": 1, ""output_tokens"": 2 }";
|
||||
|
||||
var chatUsage = new ChatUsage
|
||||
var usage = new Usage
|
||||
{
|
||||
InputTokens = 1,
|
||||
OutputTokens = 2
|
||||
};
|
||||
|
||||
var actual = Serialize(chatUsage);
|
||||
var actual = Serialize(usage);
|
||||
|
||||
JsonAssert.Equal(expectedJson, actual);
|
||||
}
|
||||
@@ -39,9 +39,9 @@ public class ChatUsageTests : SerializationTest
|
||||
{
|
||||
var json = @"{ ""input_tokens"": 1, ""output_tokens"": 2 }";
|
||||
|
||||
var chatUsage = Deserialize<ChatUsage>(json);
|
||||
var usage = Deserialize<Usage>(json);
|
||||
|
||||
chatUsage!.InputTokens.Should().Be(1);
|
||||
chatUsage.OutputTokens.Should().Be(2);
|
||||
usage!.InputTokens.Should().Be(1);
|
||||
usage.OutputTokens.Should().Be(2);
|
||||
}
|
||||
}
|
||||
@@ -1,980 +0,0 @@
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace AnthropicClient.Tests.Unit.Utils;
|
||||
|
||||
public class JsonSchemaGeneratorTestData : IEnumerable<object[]>
|
||||
{
|
||||
private const string TestToolName = "Test tool name";
|
||||
private const string TestToolDescription = "Test tool description";
|
||||
|
||||
public IEnumerator<object[]> GetEnumerator()
|
||||
{
|
||||
// string parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(string name) => name),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"name"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// GUID parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Guid id) => id),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["id"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["format"] = "uuid",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"id"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// char parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(char name) => name),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"name"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// int parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(int age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// uint parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(uint age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// long parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(long age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// ulong parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(ulong age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// short parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(short age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// ushort parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(ushort age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// byte parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(byte age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// sbyte parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(sbyte age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// bool parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(bool isAdult) => isAdult),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["isAdult"] = new JsonObject()
|
||||
{
|
||||
["type"] = "boolean",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"isAdult"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// double parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(double age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "number",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// float parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(float age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "number",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// decimal parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(decimal age) => age),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "number",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"age"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// datetime parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(DateTime date) => date),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["date"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["format"] = "date-time",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"date"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// datetimeoffset parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(DateTimeOffset date) => date),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["date"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["format"] = "date-time",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"date"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// enum parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(DayOfWeek day) => day),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["day"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty,
|
||||
["enum"] = new JsonArray()
|
||||
{
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday"
|
||||
},
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"day"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// array parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(int[] numbers) => numbers),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["numbers"] = new JsonObject()
|
||||
{
|
||||
["type"] = "array",
|
||||
["items"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer"
|
||||
},
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"numbers"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// list parameter type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(List<int> numbers) => numbers),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["numbers"] = new JsonObject()
|
||||
{
|
||||
["type"] = "array",
|
||||
["items"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer"
|
||||
},
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"numbers"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// class parameter type with no attributes
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Person person) => person),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Person).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name",
|
||||
"Age"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["person"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"person",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// nested class parameter type with no attributes
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Family family) => family),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Person).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name",
|
||||
"Age"
|
||||
}
|
||||
},
|
||||
[$"{typeof(Family).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Members"] = new JsonObject()
|
||||
{
|
||||
["type"] = "array",
|
||||
["items"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}"
|
||||
},
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Members"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["family"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Family).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"family",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
var family = new Family();
|
||||
|
||||
// parameters from instance method
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromInstanceMethod(TestToolName,TestToolDescription, family, nameof(family.AddMember)),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Person).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name",
|
||||
"Age"
|
||||
}
|
||||
},
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["member"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"member",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// parameters from static method
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromStaticMethod(TestToolName,TestToolDescription, typeof(Person), nameof(Person.Create)),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"name",
|
||||
"age",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// multiple parameters of same complex type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Person person1, Person person2) => person1),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Person).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name",
|
||||
"Age"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["person1"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["person2"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"person1",
|
||||
"person2"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// complex type with field
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Dad dad) => dad),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Dad).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Role"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Role"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["dad"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Dad).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"dad",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// complex type with members of same type
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(NuclearFamily family) => family),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Person).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Age"] = new JsonObject()
|
||||
{
|
||||
["type"] = "integer",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name",
|
||||
"Age"
|
||||
}
|
||||
},
|
||||
[$"{typeof(NuclearFamily).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Father"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
},
|
||||
["Mother"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Person).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Father",
|
||||
"Mother"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["family"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(NuclearFamily).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"family",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// string parameter type with custom name
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,([FunctionParameter("Person's Name", "Name", true)]string name) => name),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = "Person's Name"
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Name"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// string parameter with custom description
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,([FunctionParameter("The name of the person.", required: true)]string name) => name),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["name"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = "The name of the person."
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"name"
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
// complex type with attributes
|
||||
yield return new object[]
|
||||
{
|
||||
Tool.CreateFromFunction(TestToolName,TestToolDescription,(Rule rule) => rule),
|
||||
new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["definitions"] = new JsonObject()
|
||||
{
|
||||
[$"{typeof(Rule).FullName}"] = new JsonObject()
|
||||
{
|
||||
["type"] = "object",
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["Status"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = "Indicates the current status of the rule.",
|
||||
["default"] = "Active",
|
||||
["enum"] = new JsonArray()
|
||||
{
|
||||
"Inactive",
|
||||
"Active",
|
||||
}
|
||||
},
|
||||
["Type"] = new JsonObject()
|
||||
{
|
||||
["type"] = "string",
|
||||
["description"] = "The type of the rule.",
|
||||
["default"] = "Type A",
|
||||
["enum"] = new JsonArray()
|
||||
{
|
||||
"Type B",
|
||||
"Type A",
|
||||
}
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"Status"
|
||||
}
|
||||
}
|
||||
},
|
||||
["properties"] = new JsonObject()
|
||||
{
|
||||
["rule"] = new JsonObject()
|
||||
{
|
||||
["$ref"] = $"#/definitions/{typeof(Rule).FullName}",
|
||||
["description"] = string.Empty
|
||||
}
|
||||
},
|
||||
["required"] = new JsonArray()
|
||||
{
|
||||
"rule",
|
||||
},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
}
|
||||
|
||||
class Family
|
||||
{
|
||||
public List<Person> Members { get; } = [];
|
||||
|
||||
public bool AddMember(Person member)
|
||||
{
|
||||
Members.Add(member);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class NuclearFamily
|
||||
{
|
||||
public Person Father { get; } = new Person("Father", 40);
|
||||
public Person Mother { get; } = new Person("Mother", 38);
|
||||
}
|
||||
|
||||
class Person(string name, int age)
|
||||
{
|
||||
public string Name { get; } = name;
|
||||
public int Age { get; } = age;
|
||||
|
||||
public static Person Create(string name, int age) => new Person(name, age);
|
||||
}
|
||||
|
||||
class Dad
|
||||
{
|
||||
public string Role = "Father";
|
||||
}
|
||||
|
||||
class Rule
|
||||
{
|
||||
[FunctionProperty(
|
||||
"Indicates the current status of the rule.",
|
||||
true,
|
||||
"Active",
|
||||
new object[] { "Active", "Inactive" }
|
||||
)]
|
||||
public string Status { get; } = "Active";
|
||||
|
||||
[FunctionProperty(
|
||||
"The type of the rule.",
|
||||
false,
|
||||
"Type A",
|
||||
new object[] { "Type B" }
|
||||
)]
|
||||
public string Type { get; } = "Type A";
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace AnthropicClient.Tests.Unit.Utils;
|
||||
|
||||
public class JsonSchemaGeneratorTests
|
||||
|
||||
Reference in New Issue
Block a user