From dce84522bf5edeca2527722707d2fcbf350b4ea8 Mon Sep 17 00:00:00 2001
From: Haiping Chen <101423@smsassist.com>
Date: Tue, 8 Oct 2024 11:01:20 -0500
Subject: [PATCH] Upgrade Anthropic.SDK to v4
---
.../BotSharp.Plugin.AnthropicAI.csproj | 2 +-
.../Providers/ChatCompletionProvider.cs | 15 +++++++++++----
2 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj
index 5574afe5..c5bd88d0 100644
--- a/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj
+++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/BotSharp.Plugin.AnthropicAI.csproj
@@ -11,7 +11,7 @@
-
+
diff --git a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs
index dc9df32a..047cc246 100644
--- a/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs
+++ b/src/Plugins/BotSharp.Plugin.AnthropicAI/Providers/ChatCompletionProvider.cs
@@ -179,8 +179,15 @@ public class ChatCompletionProvider : IChatCompletion
Model = settings.Name,
Stream = false,
Temperature = temperature,
- SystemMessage = instruction,
- Tools = new List() { }
+ Tools = new List()
+ };
+
+ if (!string.IsNullOrEmpty(instruction))
+ {
+ parameters.System = new List()
+ {
+ new SystemMessage(instruction)
+ };
};
JsonSerializerOptions jsonSerializationOptions = new()
@@ -221,7 +228,7 @@ public class ChatCompletionProvider : IChatCompletion
private string GetPrompt(MessageParameters parameters)
{
- var prompt = $"{parameters.SystemMessage}\r\n";
+ var prompt = $"{string.Join("\r\n", parameters.System.Select(x => x.Text))}\r\n";
prompt += "\r\n[CONVERSATION]";
var verbose = string.Join("\r\n", parameters.Messages
@@ -264,7 +271,7 @@ public class ChatCompletionProvider : IChatCompletion
{
var functions = string.Join("\r\n", parameters.Tools.Select(x =>
{
- return $"\r\n{x.Name}: {x.Description}\r\n{JsonSerializer.Serialize(x.Parameters)}";
+ return $"\r\n{x.Function.Name}: {x.Function.Description}\r\n{JsonSerializer.Serialize(x.Function.Parameters)}";
}));
prompt += $"\r\n[FUNCTIONS]\r\n{functions}\r\n";
}