Skip to content

Commit adc3081

Browse files
authored
Add Anthropic (Claude) integration (#81)
* Add Claude LLM integration and example usage * Refactor ClaudeService to remove memory dependencies * Add Claude chat completion support to MCP service Introduces ClaudeChatCompletionService and KernelBuilderExtensions to enable Anthropic Claude model integration in the MCP service. Updates McpService to support Claude as a backend, including prompt execution settings and service registration. * Rename Claude integration to Anthropic throughout codebase * Change Claude to Anthropic in file names * versioning
1 parent b2046a1 commit adc3081

File tree

16 files changed

+735
-10
lines changed

16 files changed

+735
-10
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Examples.Utils;
2+
using MaIN.Core.Hub;
3+
4+
namespace Examples;
5+
6+
public class ChatExampleAnthropic : IExample
7+
{
8+
public async Task Start()
9+
{
10+
AnthropicExample.Setup(); //We need to provide Anthropic API key
11+
Console.WriteLine("(Anthropic) ChatExample is running!");
12+
13+
await AIHub.Chat()
14+
.WithModel("claude-sonnet-4-20250514")
15+
.WithMessage("Write a haiku about programming on Monday morning.")
16+
.CompleteAsync(interactive: true);
17+
}
18+
}

Examples/Examples/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void RegisterExamples(IServiceCollection services)
7373
services.AddTransient<ChatWithReasoningDeepSeekExample>();
7474
services.AddTransient<ChatWithTextToSpeechExample>();
7575
services.AddTransient<ChatExampleGroqCloud>();
76+
services.AddTransient<ChatExampleAnthropic>();
7677
}
7778

7879
async Task RunSelectedExample(IServiceProvider serviceProvider)
@@ -163,6 +164,7 @@ public class ExampleRegistry(IServiceProvider serviceProvider)
163164
("\u25a0 Gemini Chat with files", serviceProvider.GetRequiredService<ChatWithFilesExampleGemini>()),
164165
("\u25a0 DeepSeek Chat with reasoning", serviceProvider.GetRequiredService<ChatWithReasoningDeepSeekExample>()),
165166
("\u25a0 GroqCloud Chat", serviceProvider.GetRequiredService<ChatExampleGroqCloud>()),
167+
("\u25a0 Anthropic Chat", serviceProvider.GetRequiredService<ChatExampleAnthropic>()),
166168
("\u25a0 McpClient example", serviceProvider.GetRequiredService<McpExample>()),
167169
("\u25a0 McpAgent example", serviceProvider.GetRequiredService<McpAgentsExample>()),
168170
("\u25a0 Chat with TTS example", serviceProvider.GetRequiredService<ChatWithTextToSpeechExample>()),
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using MaIN.Core;
2+
using MaIN.Domain.Configuration;
3+
4+
namespace Examples.Utils;
5+
6+
public class AnthropicExample
7+
{
8+
public static void Setup()
9+
{
10+
MaINBootstrapper.Initialize(configureSettings: (options) =>
11+
{
12+
options.BackendType = BackendType.Anthropic;
13+
options.AnthropicKey = "<YOUR_ANTHROPIC_KEY>";
14+
});
15+
}
16+
}

Releases/0.5.1.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 0.5.1 release
2+
3+
Anthropic integration has been added.

src/MaIN.Core/.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package>
33
<metadata>
44
<id>MaIN.NET</id>
5-
<version>0.5.0</version>
5+
<version>0.5.1</version>
66
<authors>Wisedev</authors>
77
<owners>Wisedev</owners>
88
<icon>favicon.png</icon>

src/MaIN.Domain/Configuration/MaINSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class MaINSettings
1111
public string? OpenAiKey { get; set; }
1212
public string? GeminiKey { get; set; }
1313
public string? DeepSeekKey { get; set; }
14+
public string? AnthropicKey { get; set; }
1415
public string? GroqCloudKey { get; set; }
1516
public MongoDbSettings? MongoDbSettings { get; set; }
1617
public FileSystemSettings? FileSystemSettings { get; set; }
@@ -26,4 +27,5 @@ public enum BackendType
2627
Gemini = 2,
2728
DeepSeek = 3,
2829
GroqCloud = 4,
30+
Anthropic = 5,
2931
}

src/MaIN.InferPage/Program.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Net.Mime;
21
using MaIN.Core;
32
using MaIN.Domain.Configuration;
43
using MaIN.Domain.Models;
@@ -71,6 +70,12 @@
7170
apiKeyVariable = "GROQ_API_KEY";
7271
apiName = "GroqCloud";
7372
break;
73+
74+
case "anthropic":
75+
Utils.Anthropic = true;
76+
apiKeyVariable = "ANTHROPIC_API_KEY";
77+
apiName = "Anthropic";
78+
break;
7479
}
7580

7681
var key = Environment.GetEnvironmentVariable(apiKeyVariable);
@@ -116,6 +121,13 @@
116121
settings.BackendType = BackendType.GroqCloud;
117122
});
118123
}
124+
else if(Utils.Anthropic)
125+
{
126+
builder.Services.AddMaIN(builder.Configuration, settings =>
127+
{
128+
settings.BackendType = BackendType.Anthropic;
129+
});
130+
}
119131
else
120132
{
121133
if (Utils.Path == null && !KnownModels.IsModelSupported(Utils.Model!))

src/MaIN.InferPage/Utils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public static class Utils
1111
public static bool Gemini { get; set; }
1212
public static bool DeepSeek { get; set; }
1313
public static bool GroqCloud { get; set; }
14+
public static bool Anthropic { get; set; }
1415
public static string? Path { get; set; }
1516
public static bool Reason { get; set; }
1617
}

src/MaIN.Services/Constants/ServiceConstants.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public static class HttpClients
99
public const string GeminiClient = "GeminiClient";
1010
public const string DeepSeekClient = "DeepSeekClient";
1111
public const string GroqCloudClient = "GroqCloudClient";
12+
public const string AnthropicClient = "AnthropicClient";
1213
public const string ImageDownloadClient = "ImageDownloadClient";
1314
public const string ModelContextDownloadClient = "ModelContextDownloadClient";
1415
}
@@ -28,10 +29,13 @@ public static class ApiUrls
2829
public const string GeminiModels = "https://generativelanguage.googleapis.com/v1beta/models";
2930

3031
public const string DeepSeekOpenAiChatCompletions = "https://api.deepseek.com/v1/chat/completions";
31-
public const string DeepSeekModels = "https://api.deepseek.com/models";
32+
public const string DeepSeekModels = "https://api.deepseek.com/models";
3233

3334
public const string GroqCloudOpenAiChatCompletions = "https://api.groq.com/openai/v1/chat/completions";
3435
public const string GroqCloudModels = "https://api.groq.com/openai/v1/models";
36+
37+
public const string AnthropicChatMessages = "https://api.anthropic.com/v1/messages";
38+
public const string AnthropicModels = "https://api.anthropic.com/v1/models";
3539
}
3640

3741
public static class Messages

0 commit comments

Comments
 (0)