From 1a5cdfe74c0a1e9ab08ac2b678deb3cdf060d2e4 Mon Sep 17 00:00:00 2001 From: Konstantin S Date: Thu, 20 Jul 2023 06:18:34 +0400 Subject: [PATCH] docs: Updated README. --- README.md | 14 ++++++++++ src/tests/Anthropic.IntegrationTests/Tests.cs | 27 ++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7a824d9..f07d24c 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,20 @@ var response = await api.CompleteAsync(new CreateCompletionRequest Max_tokens_to_sample = 250, }); Console.WriteLine(response.Completion); + +// or use history syntax + +var response = await api.CompleteAsync(new CreateCompletionRequest +{ + Model = ModelIds.ClaudeInstant, + Prompt = new[] + { + "What's the weather like today?".AsHumanMessage(), + "Sure! Could you please provide me with your location?".AsAssistantMessage(), + "Dubai, UAE".AsHumanMessage(), + }.AsPrompt(), + Max_tokens_to_sample = 300, +}); ``` ## Support diff --git a/src/tests/Anthropic.IntegrationTests/Tests.cs b/src/tests/Anthropic.IntegrationTests/Tests.cs index 615ca37..5627248 100755 --- a/src/tests/Anthropic.IntegrationTests/Tests.cs +++ b/src/tests/Anthropic.IntegrationTests/Tests.cs @@ -4,7 +4,7 @@ namespace Anthropic.IntegrationTests; public class GeneralTests { [TestMethod] - public async Task ListModels() + public async Task Complete() { var apiKey = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") ?? @@ -22,4 +22,29 @@ public async Task ListModels() response.Completion.Should().NotBeNullOrEmpty(); response.Stop_reason.Should().Be(CreateCompletionResponseStop_reason.Stop_sequence); } + + [TestMethod] + public async Task CompleteHistory() + { + var apiKey = + Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY") ?? + throw new AssertInconclusiveException("ANTHROPIC_API_KEY environment variable is not found."); + + using var client = new HttpClient(); + var api = new AnthropicApi(apiKey, client); + var response = await api.CompleteAsync(new CreateCompletionRequest + { + Model = ModelIds.ClaudeInstant, + Prompt = new [] + { + "What's the weather like today?".AsHumanMessage(), + "Sure! Could you please provide me with your location?".AsAssistantMessage(), + "Dubai, UAE".AsHumanMessage(), + }.AsPrompt(), + Max_tokens_to_sample = 300, + }); + response.Model.Should().Be(ModelIds.ClaudeInstant); + response.Completion.Should().NotBeNullOrEmpty(); + response.Stop_reason.Should().Be(CreateCompletionResponseStop_reason.Stop_sequence); + } }