semantic-kernel icon indicating copy to clipboard operation
semantic-kernel copied to clipboard

.Net Anthropic connector progress (Claude 3)

Open Krzysztof318 opened this issue 1 year ago • 13 comments

Progress of implementation of Anthropic Claude 3 family connector. Current implementation BRANCH

TODO

  1. 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
  1. Others
  • [x] Logging
  • [x] Telemetry

Krzysztof318 avatar Mar 28 '24 14:03 Krzysztof318

This issue is stale because it has been open for 90 days with no activity.

github-actions[bot] avatar Jun 27 '24 01:06 github-actions[bot]

Bump

Krzysztof318 avatar Jun 27 '24 05:06 Krzysztof318

Any update on this? @RogerBarreto

Pekket avatar Jul 04 '24 14:07 Pekket

@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 avatar Jul 04 '24 14:07 Krzysztof318

@Krzysztof318 Thanks for the work, looks good 🦸 Any idea when the stream chat will be implemented?

Pekket avatar Jul 05 '24 08:07 Pekket

@Pekket soon but before we merge claude to main brach I think it will take couple of weeks.

Krzysztof318 avatar Jul 05 '24 14:07 Krzysztof318

@Krzysztof318 We’re so excited for it.

rodion-m avatar Jul 18 '24 18:07 rodion-m

Hear hear! Claude support please!

celsound avatar Jul 18 '24 18:07 celsound

There is any update?

payoff avatar Aug 26 '24 09:08 payoff

Sorry, I have much work last time, but I started working on streaming. I hope I will publish PR this week.

Krzysztof318 avatar Aug 26 '24 10:08 Krzysztof318

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 avatar Sep 25 '24 15:09 payoff

@payoff I hope soon, currently I am waiting for review latest PR.

Krzysztof318 avatar Sep 25 '24 21:09 Krzysztof318

@payoff I hope soon, currently I am waiting for review latest PR.

Looks like 2 unit tests are failing?

therealpaulgg avatar Sep 27 '24 15:09 therealpaulgg

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.

kcrandall avatar Oct 18 '24 05:10 kcrandall

Is this up to date? Does the lack of function calling mean we can't use the new computer tool?

lostmsu avatar Oct 23 '24 17:10 lostmsu

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 avatar Oct 24 '24 08:10 nonoc

@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>());

lostmsu avatar Oct 24 '24 14:10 lostmsu

Any updates? really looking formward to use anthropic in my projects..

mhensen avatar Oct 27 '24 11:10 mhensen

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 avatar Oct 28 '24 05:10 lostmsu

@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 avatar Oct 28 '24 07:10 Krzysztof318

@Krzysztof318 sure, I didn't notice the branch until recently.

lostmsu avatar Oct 28 '24 14:10 lostmsu

@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 avatar Oct 28 '24 16:10 therealpaulgg

@therealpaulgg I haven't tested but I applied your suggestions.

Krzysztof318 avatar Oct 28 '24 19:10 Krzysztof318

Why we need to use .NET Standard 2.0 to use it?

nonoc avatar Nov 04 '24 17:11 nonoc

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.

giannik avatar Nov 13 '24 08:11 giannik

@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.

Krzysztof318 avatar Nov 13 '24 22:11 Krzysztof318

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?

Millmer avatar Dec 16 '24 13:12 Millmer

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());

rogerbarreto avatar Apr 18 '25 07:04 rogerbarreto