Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Cellm/AddIn/CellmAddIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static ServiceCollection ConfigureServices(ServiceCollection services)
.Configure<AccountConfiguration>(configuration.GetRequiredSection(nameof(AccountConfiguration)))
.Configure<AnthropicConfiguration>(configuration.GetRequiredSection(nameof(AnthropicConfiguration)))
.Configure<CellmConfiguration>(configuration.GetRequiredSection(nameof(CellmConfiguration)))
.Configure<GoogleGeminiConfiguration>(configuration.GetRequiredSection(nameof(GoogleGeminiConfiguration)))
.Configure<GeminiConfiguration>(configuration.GetRequiredSection(nameof(GeminiConfiguration)))
.Configure<DeepSeekConfiguration>(configuration.GetRequiredSection(nameof(DeepSeekConfiguration)))
.Configure<CellmAddInConfiguration>(configuration.GetRequiredSection(nameof(CellmAddInConfiguration)))
.Configure<MistralConfiguration>(configuration.GetRequiredSection(nameof(MistralConfiguration)))
Expand Down Expand Up @@ -135,7 +135,7 @@ private static ServiceCollection ConfigureServices(ServiceCollection services)
.AddAnthropicChatClient()
.AddCellmChatClient()
.AddDeepSeekChatClient()
.AddGoogleGeminiChatClient()
.AddGeminiChatClient()
.AddMistralChatClient()
.AddOllamaChatClient()
.AddOpenAiChatClient()
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/AddIn/UserInterface/Ribbon/RibbonModelGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private class ProviderItem
private readonly Dictionary<int, ProviderItem> _providerItems = new()
{
[0] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.Anthropic)}", Image = $"{ResourcesBasePath}/anthropic.png", Label = nameof(Provider.Anthropic), Entitlement = Entitlement.EnableAnthropicProvider },
[1] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.GoogleGemini)}", Image = $"{ResourcesBasePath}/google.png", Label = nameof(Provider.GoogleGemini), Entitlement = Entitlement.EnableGoogleGeminiProvider },
[1] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.Gemini)}", Image = $"{ResourcesBasePath}/google.png", Label = nameof(Provider.Gemini), Entitlement = Entitlement.EnableGeminiProvider },
[2] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.DeepSeek)}", Image = $"{ResourcesBasePath}/deepseek.png", Label = nameof(Provider.DeepSeek), Entitlement = Entitlement.EnableDeepSeekProvider },
[3] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.Mistral)}", Image = $"{ResourcesBasePath}/mistral.png", Label = nameof(Provider.Mistral), Entitlement = Entitlement.EnableMistralProvider },
[4] = new ProviderItem { Id = $"{nameof(Provider)}.{nameof(Provider.Ollama)}", Image = $"{ResourcesBasePath}/ollama.png", Label = nameof(Provider.Ollama), Entitlement = Entitlement.EnableOllamaProvider },
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Cellm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<PackageReference Include="MediatR" Version="12.5.0" />
<PackageReference Include="Microsoft.Extensions.AI" Version="9.5.0" />
<PackageReference Include="Microsoft.Extensions.AI.Abstractions" Version="9.5.0" />
<PackageReference Include="Microsoft.Extensions.AI.Ollama" Version="9.4.4-preview.1.25259.16" />
<PackageReference Include="Microsoft.Extensions.AI.OpenAI" Version="9.4.4-preview.1.25259.16" />
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.5.0" />
<PackageReference Include="Microsoft.Extensions.Compliance.Redaction" Version="9.5.0" />
Expand All @@ -55,6 +54,7 @@
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.5" />
<PackageReference Include="Mistral.SDK" Version="2.2.0" />
<PackageReference Include="ModelContextProtocol" Version="0.1.0-preview.11" />
<PackageReference Include="OllamaSharp" Version="5.2.2" />
<PackageReference Include="PdfPig" Version="0.1.10" />
<PackageReference Include="Sentry.Extensions.Logging" Version="5.5.1" />
<PackageReference Include="Sentry.Profiling" Version="5.5.1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Cellm.Models.Providers.Google;

internal class GoogleGeminiConfiguration
internal class GeminiConfiguration
{
public Uri BaseAddress => new("https://generativelanguage.googleapis.com/v1beta/openai/");

Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Models/Providers/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum Provider
Anthropic,
Cellm,
DeepSeek,
GoogleGemini,
Gemini,
Mistral,
Ollama,
OpenAi,
Expand Down
35 changes: 17 additions & 18 deletions src/Cellm/Models/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Mistral.SDK;
using OllamaSharp;
using OpenAI;
using Polly;
using Polly.Retry;
Expand Down Expand Up @@ -144,7 +145,7 @@ public static IServiceCollection AddAnthropicChatClient(this IServiceCollection
.AddKeyedChatClient(Provider.Anthropic, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableAnthropicProvider);
account.ThrowIfNotEntitled(Entitlement.EnableAnthropicProvider);

var anthropicConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<AnthropicConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");
Expand All @@ -165,7 +166,7 @@ public static IServiceCollection AddCellmChatClient(this IServiceCollection serv
.AddKeyedChatClient(Provider.Cellm, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableCellmProvider);
account.ThrowIfNotEntitled(Entitlement.EnableCellmProvider);

var cellmConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<CellmConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");
Expand All @@ -192,7 +193,7 @@ public static IServiceCollection AddDeepSeekChatClient(this IServiceCollection s
.AddKeyedChatClient(Provider.DeepSeek, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableDeepSeekProvider);
account.ThrowIfNotEntitled(Entitlement.EnableDeepSeekProvider);

var deepSeekConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<DeepSeekConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");
Expand All @@ -212,26 +213,26 @@ public static IServiceCollection AddDeepSeekChatClient(this IServiceCollection s
return services;
}

public static IServiceCollection AddGoogleGeminiChatClient(this IServiceCollection services)
public static IServiceCollection AddGeminiChatClient(this IServiceCollection services)
{
services
.AddKeyedChatClient(Provider.GoogleGemini, serviceProvider =>
.AddKeyedChatClient(Provider.Gemini, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableGoogleGeminiProvider);
account.ThrowIfNotEntitled(Entitlement.EnableGeminiProvider);

var googleGeminiConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<GoogleGeminiConfiguration>>();
var geminiConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<GeminiConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");

var openAiClient = new OpenAIClient(
new ApiKeyCredential(googleGeminiConfiguration.CurrentValue.ApiKey),
new ApiKeyCredential(geminiConfiguration.CurrentValue.ApiKey),
new OpenAIClientOptions
{
Transport = new HttpClientPipelineTransport(resilientHttpClient),
Endpoint = googleGeminiConfiguration.CurrentValue.BaseAddress
Endpoint = geminiConfiguration.CurrentValue.BaseAddress
});

return openAiClient.GetChatClient(googleGeminiConfiguration.CurrentValue.DefaultModel).AsIChatClient();
return openAiClient.GetChatClient(geminiConfiguration.CurrentValue.DefaultModel).AsIChatClient();
}, ServiceLifetime.Transient)
.UseFunctionInvocation();

Expand All @@ -244,7 +245,7 @@ public static IServiceCollection AddMistralChatClient(this IServiceCollection se
.AddKeyedChatClient(Provider.Mistral, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableMistralProvider);
account.ThrowIfNotEntitled(Entitlement.EnableMistralProvider);

var mistralConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<MistralConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");
Expand All @@ -262,15 +263,13 @@ public static IServiceCollection AddOllamaChatClient(this IServiceCollection ser
.AddKeyedChatClient(Provider.Ollama, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableOllamaProvider);
account.ThrowIfNotEntitled(Entitlement.EnableOllamaProvider);

var ollamaConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<OllamaConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");

return new OllamaChatClient(
return new OllamaApiClient(
ollamaConfiguration.CurrentValue.BaseAddress,
ollamaConfiguration.CurrentValue.DefaultModel,
resilientHttpClient);
ollamaConfiguration.CurrentValue.DefaultModel);
}, ServiceLifetime.Transient)
.UseFunctionInvocation();

Expand All @@ -283,7 +282,7 @@ public static IServiceCollection AddOpenAiChatClient(this IServiceCollection ser
.AddKeyedChatClient(Provider.OpenAi, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableOpenAiProvider);
account.ThrowIfNotEntitled(Entitlement.EnableOpenAiProvider);

var openAiConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<OpenAiConfiguration>>();

Expand All @@ -302,7 +301,7 @@ public static IServiceCollection AddOpenAiCompatibleChatClient(this IServiceColl
.AddKeyedChatClient(Provider.OpenAiCompatible, serviceProvider =>
{
var account = serviceProvider.GetRequiredService<Account>();
account.RequireEntitlement(Entitlement.EnableOpenAiCompatibleProvider);
account.ThrowIfNotEntitled(Entitlement.EnableOpenAiCompatibleProvider);

var openAiCompatibleConfiguration = serviceProvider.GetRequiredService<IOptionsMonitor<OpenAiCompatibleConfiguration>>();
var resilientHttpClient = serviceProvider.GetKeyedService<HttpClient>("ResilientHttpClient") ?? throw new NullReferenceException("ResilientHttpClient");
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Users/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ internal async Task RequireEntitlementAsync(Entitlement entitlement)
}
}

internal void RequireEntitlement(Entitlement entitlement)
internal void ThrowIfNotEntitled(Entitlement entitlement)
{
Task.Run(async () => await RequireEntitlementAsync(entitlement)).GetAwaiter().GetResult();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Users/Entitlement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public enum Entitlement
EnableAnthropicProvider,
EnableCellmProvider,
EnableDeepSeekProvider,
EnableGoogleGeminiProvider,
EnableGeminiProvider,
EnableMistralProvider,
EnableOllamaProvider,
EnableOpenAiProvider,
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"MediumModel": "deepseek-chat",
"LargeModel": "deepseek-reasoner"
},
"GoogleGeminiConfiguration": {
"GeminiConfiguration": {
"DefaultModel": "gemini-2.5-flash-preview-05-20",
"ApiKey": "",
"MediumModel": "gemini-2.5-flash-preview-05-20",
Expand Down
20 changes: 9 additions & 11 deletions src/Cellm/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@
"resolved": "9.5.0",
"contentHash": "Y46j1S4zOPtLAHCUzhHIm1IhCMr7764754bLYupyc1JZcvLNXjUk+VC7H3Bou20S2hHgDJnfox7X/H/3BYEvzA=="
},
"Microsoft.Extensions.AI.Ollama": {
"type": "Direct",
"requested": "[9.4.4-preview.1.25259.16, )",
"resolved": "9.4.4-preview.1.25259.16",
"contentHash": "+h8u6Zm+Gca/hIFmbxWUucJRhuf2Jgd1VG8/PRS+BvXw6vSdlYFtrhvpD9hrHa5feadIq6lvVYoaUNjnVKe+eA==",
"dependencies": {
"Microsoft.Extensions.AI.Abstractions": "9.4.4-preview.1.25259.16",
"System.Net.Http.Json": "9.0.4",
"System.Text.Json": "9.0.4"
}
},
"Microsoft.Extensions.AI.OpenAI": {
"type": "Direct",
"requested": "[9.4.4-preview.1.25259.16, )",
Expand Down Expand Up @@ -256,6 +245,15 @@
"System.Net.ServerSentEvents": "10.0.0-preview.2.25163.2"
}
},
"OllamaSharp": {
"type": "Direct",
"requested": "[5.2.2, )",
"resolved": "5.2.2",
"contentHash": "7K4cza2hQQjMsovNx6Axw2EoyALJuG2PM14nDtcW7dhxWHt9yl7hXgd/jTMJ5PeoxPGrgnxjSB99HJUF3O+mtA==",
"dependencies": {
"Microsoft.Extensions.AI.Abstractions": "9.5.0"
}
},
"PdfPig": {
"type": "Direct",
"requested": "[0.1.10, )",
Expand Down
Loading