semantic-kernel
semantic-kernel copied to clipboard
.Net Anthropic connector progress (Claude 3)
Progress of implementation of Anthropic Claude 3 family connector. Current implementation BRANCH
TODO
- ChatCompletionService
- [x] Get chat
- [x] Create examples
- [x] Stream chat
- [x] Create examples
- [x] Add DI extensions
- [x] Provide metadata from response
- [ ] Function calling POSTPONED
- [ ] Create examples
- [x] Pass images with prompt
- Others
- [x] Logging
- [x] Telemetry
This issue is stale because it has been open for 90 days with no activity.
Bump
Any update on this? @RogerBarreto
@Pekket I held with developing connector until function calling abstraction will be ready. But probably fca won't be ready fast, so yesterday we decided with @RogerBarreto to deploy connector now without fc functionality. I am working currently on connector code.
@Krzysztof318 Thanks for the work, looks good 🦸 Any idea when the stream chat will be implemented?
@Pekket soon but before we merge claude to main brach I think it will take couple of weeks.
@Krzysztof318 We’re so excited for it.
Hear hear! Claude support please!
There is any update?
Sorry, I have much work last time, but I started working on streaming. I hope I will publish PR this week.
I wanted to check in and see if there are any updates on the current development status. Specifically, I would like to know if there is an estimated date when the ongoing work will be merged into the master branch.
Thank you for your time and support. Mik
@payoff I hope soon, currently I am waiting for review latest PR.
@payoff I hope soon, currently I am waiting for review latest PR.
Looks like 2 unit tests are failing?
Any plans to support prompt caching at some point?
https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
Might want to just want to have users add a flag to the ChatMessageContent metadata object and then add it to the payload when you serialize before sending.
Is this up to date? Does the lack of function calling mean we can't use the new computer tool?
Hi guys, I'm having a hard time finding a way to connect to Anthropic. It's something that's actually implemented in the latest versions of SemanticKernel. I'm currently working with version 1.72, which is the most stable, using KernelFactory. I don't really know why higher versions don't work with KernelFactory, and with Anthropic I have a connection error. It's something that's being tested. Thank you all very much.
@nonoc Funny you ask, I started implementing computer use tool off where this work was stopped, have prototype here: https://github.com/BorgGames/semantic-kernel/tree/AnthropicTools (fork of this repo)
Beta package is here: https://www.nuget.org/packages/Lost.SemanticKernel.Connectors.Anthropic/1.22.0-alpha0
Usage
var chatHistory = new ChatHistory();
chatHistory.AddUserMessage("Open Notepad and type Hi!");
var sut = new AnthropicChatCompletionService(this.AnthropicGetModel(), this.AnthropicGetApiKey(), new(beta: ComputerUse_2024_10_22.Beta));
var kernel = new Kernel();
kernel.Plugins.Add(ComputerUse_2024_10_22.ComputerPlugin(NoOpComputer.Instance));
// Act
var response = await sut.GetChatMessageContentsAsync(chatHistory, kernel: kernel);
// Assert
var lastMessage = response[^1];
var metadata = lastMessage.Metadata as AnthropicMetadata;
Assert.NotNull(metadata);
this.Output.WriteLine($"FinishReason: {metadata.FinishReason}");
Assert.Equal(AnthropicFinishReason.ToolUse, metadata.FinishReason);
var supposedlyScreenshotCall = lastMessage.Items
.OfType<FunctionCallContent>()
.FirstOrDefault();
Assert.NotNull(supposedlyScreenshotCall);
Assert.Equal("computer", supposedlyScreenshotCall.FunctionName);
if (supposedlyScreenshotCall.Arguments?["action"] is not JsonElement action)
{
Assert.Fail("action is not supplied or wrong type");
return;
}
Assert.Equal("screenshot", action.Deserialize<string>());
Any updates? really looking formward to use anthropic in my projects..
Just updated the alpha to the latest official release 1.25.0, and enabled an option to auto execute Computer Use tool.
https://www.nuget.org/packages/Lost.SemanticKernel.Connectors.Anthropic/1.25.0-alpha2#readme-body-tab
@lostmsu hi, nice to see you are working also on this connector. But instead of creating own repo could you contribute to anthropic branch and create PR in SK?
@Krzysztof318 sure, I didn't notice the branch until recently.
@Krzysztof318 have you tested on Google vertex? For me earlier I was having issues unless I made changes, which I commented on your PR.
@therealpaulgg I haven't tested but I applied your suggestions.
Why we need to use .NET Standard 2.0 to use it?
Will the Anthropic connector eventually get into semantic kernel repository? I'm asking because I saw the Ai.extensions released and got me thinking if this pr will be postponed. I hope not.
@glanik it will, PR is waiting for final review. AI.extensions is designed to integration with existing .net sdk of model providers. But anthropic doesn't have .net sdk.
I noticed that the related PR (https://github.com/microsoft/semantic-kernel/pull/7364) to introduce Anthropic support for C# was recently closed. Could you clarify what this means for the expected timeline for supporting Anthropic models in C# independently of Bedrock?
This PR was closed after Microsoft.Extensions.AI.IChatClient abstractions were introduced, and became supported in the C# ecosystem, where you can convert a IChatClient to a SK.IChatCompletionService transparently.
In a near future such conversion will not be needed and you will be able to use IChatClients directly with Kernel.
We already have IChatClient implementations of Anthropic in the community and following, we encourage the community growth by pointing towards those implementations instead of centralizing all the support on our repository.
For reference if you want to use Anthropic directly with SK you can go for:
https://github.com/tghamm/Anthropic.SDK
And use a implementation like:
using Microsoft.SemanticKernel;
var skChatService = new AnthropicClient().Messages.AsChatCompletionService();
// OR
var builder = Kernel.CreateBuilder();
builder.Services.AddTransient<IChatCompletionService>((sp) => new AnthropicClient().Messages.AsChatCompletionService());