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
7 changes: 4 additions & 3 deletions src/Cellm.Models/Behaviors/CacheBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.Json;
using Cellm.Models.Prompts;
using Cellm.Models.Providers;
using MediatR;
using Microsoft.Extensions.Caching.Hybrid;
Expand All @@ -13,15 +14,15 @@ internal class CacheBehavior<TRequest, TResponse>(
HybridCache cache,
IOptionsMonitor<ProviderConfiguration> providerConfiguration,
ILogger<CacheBehavior<TRequest, TResponse>> logger) : IPipelineBehavior<TRequest, TResponse>
where TRequest : IModelRequest<TResponse>
where TResponse : IModelResponse
where TRequest : IPrompt
where TResponse : IPrompt
{
private readonly HybridCacheEntryOptions _cacheEntryOptions = new()
{
Expiration = TimeSpan.FromSeconds(providerConfiguration.CurrentValue.CacheTimeoutInSeconds)
};

private static readonly List<string> Tags = [nameof(IModelResponse)];
private static readonly List<string> Tags = [nameof(ProviderResponse)];

public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Cellm.Models/Behaviors/SentryBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cellm.AddIn;
using Cellm.Models.Prompts;
using Cellm.Models.Providers;
using Cellm.User;
using MediatR;
Expand All @@ -12,7 +13,7 @@ internal class SentryBehavior<TRequest, TResponse>(
IOptionsMonitor<ProviderConfiguration> providerConfiguration,
Account account,
ILogger<SentryBehavior<TRequest, TResponse>> logger) : IPipelineBehavior<TRequest, TResponse>
where TRequest : IModelRequest<TResponse>
where TRequest : IPrompt
{
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{
Expand Down
7 changes: 4 additions & 3 deletions src/Cellm.Models/Behaviors/ToolBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.CompilerServices;
using Cellm.Models.Prompts;
using Cellm.Models.Providers;
using Cellm.Tools.ModelContextProtocol;
using MediatR;
Expand All @@ -15,9 +16,10 @@ internal class ToolBehavior<TRequest, TResponse>(
IEnumerable<AIFunction> functions,
ILogger<ToolBehavior<TRequest, TResponse>> logger,
ILoggerFactory loggerFactory)
: IPipelineBehavior<TRequest, TResponse> where TRequest : IModelRequest<TResponse>
: IPipelineBehavior<TRequest, TResponse>
where TRequest : IPrompt
{
// TODO: Use HybridCache (await fix that McpLcientTool can't be serialized/deserialized)
// TODO: Use HybridCache
private Dictionary<string, IList<McpClientTool>> _poorMansCache = [];

public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
Expand Down Expand Up @@ -65,7 +67,6 @@ private List<AITool> GetNativeTools()
}

// TODO: Query servers in parallel

private async IAsyncEnumerable<AITool> GetModelContextProtocolTools([EnumeratorCancellation] CancellationToken cancellationToken)
{
foreach (var server in modelContextProtocolConfiguration.CurrentValue.Servers)
Expand Down
25 changes: 4 additions & 21 deletions src/Cellm.Models/Cellm.Models.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -13,39 +13,22 @@
<Compile Include="$(MSBuildThisFileDirectory)Behaviors\SentryBehavior.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Behaviors\ToolBehavior.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Client.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Exceptions\CellmModelException.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Prompts\IPrompt.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Requests\ProviderRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Requests\ProviderRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Requests\ProviderResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Prompts\Prompt.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Prompts\PromptBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Anthropic\AnthropicConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Anthropic\AnthropicRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Anthropic\AnthropicRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Anthropic\AnthropicResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Cellm\CellmConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Cellm\CellmRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Cellm\CellmRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Cellm\CellmResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\DeepSeek\DeepSeekConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IModelRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IModelRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IModelResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IProviderConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IProviderRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IProviderRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Mistral\MistralConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Ollama\OllamaConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Ollama\OllamaRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Ollama\OllamaRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Ollama\OllamaResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\ChatClientFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\IChatClientFactory.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAiCompatible\OpenAiCompatibleConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAiCompatible\OpenAiCompatibleRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAiCompatible\OpenAiCompatibleRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAiCompatible\OpenAiCompatibleResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAi\OpenAiConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAi\OpenAiRequest.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAi\OpenAiRequestHandler.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\OpenAi\OpenAiResponse.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\Provider.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Providers\ProviderConfiguration.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Resilience\CircuitBreakerConfiguration.cs" />
Expand Down
16 changes: 1 addition & 15 deletions src/Cellm.Models/Client.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using Cellm.Models.Prompts;
using Cellm.Models.Providers;
using Cellm.Models.Providers.Anthropic;
using Cellm.Models.Providers.Ollama;
using Cellm.Models.Providers.OpenAi;
using Cellm.Models.Providers.OpenAiCompatible;
using MediatR;
using Polly.Registry;

Expand All @@ -17,17 +13,7 @@ public async Task<Prompt> Send(Prompt prompt, Provider provider, CancellationTok

return await retryPipeline.Execute(async () =>
{
IModelResponse response = provider switch
{
Provider.Anthropic => await sender.Send(new AnthropicRequest(prompt), cancellationToken),
Provider.DeepSeek => await sender.Send(new OpenAiCompatibleRequest(prompt, Provider.DeepSeek), cancellationToken),
Provider.Mistral => await sender.Send(new OpenAiCompatibleRequest(prompt, Provider.Mistral), cancellationToken),
Provider.Ollama => await sender.Send(new OllamaRequest(prompt), cancellationToken),
Provider.OpenAi => await sender.Send(new OpenAiRequest(prompt), cancellationToken),
Provider.OpenAiCompatible => await sender.Send(new OpenAiCompatibleRequest(prompt, Provider.OpenAiCompatible), cancellationToken),
_ => throw new NotSupportedException($"Provider {provider} is not supported")
};

var response = await sender.Send(new ProviderRequest(prompt, provider));
return response.Prompt;
});
}
Expand Down
10 changes: 0 additions & 10 deletions src/Cellm.Models/Exceptions/CellmModelException.cs

This file was deleted.

6 changes: 6 additions & 0 deletions src/Cellm.Models/Prompts/IPrompt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Cellm.Models.Prompts;

internal interface IPrompt
{
public Prompt Prompt { get; }
}
5 changes: 0 additions & 5 deletions src/Cellm.Models/Providers/Anthropic/AnthropicRequest.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/Cellm.Models/Providers/Anthropic/AnthropicRequestHandler.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/Cellm.Models/Providers/Anthropic/AnthropicResponse.cs

This file was deleted.

7 changes: 0 additions & 7 deletions src/Cellm.Models/Providers/Cellm/CellmRequest.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/Cellm.Models/Providers/Cellm/CellmRequestHandler.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/Cellm.Models/Providers/Cellm/CellmResponse.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Cellm.Models/Providers/ChatClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.Extensions.DependencyInjection;


namespace Cellm.Models.Providers.OpenAiCompatible;
namespace Cellm.Models.Providers;

public class ChatClientFactory(IServiceProvider serviceProvider) : IChatClientFactory
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm.Models/Providers/IChatClientFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.AI;

namespace Cellm.Models.Providers.OpenAiCompatible;
namespace Cellm.Models.Providers;

public interface IChatClientFactory
{
Expand Down
8 changes: 0 additions & 8 deletions src/Cellm.Models/Providers/IModelRequestHandler.cs

This file was deleted.

7 changes: 0 additions & 7 deletions src/Cellm.Models/Providers/IProviderRequest.cs

This file was deleted.

8 changes: 0 additions & 8 deletions src/Cellm.Models/Providers/IProviderRequestHandler.cs

This file was deleted.

6 changes: 5 additions & 1 deletion src/Cellm.Models/Providers/Ollama/OllamaConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Cellm.Models.Providers.Ollama;
using Microsoft.Extensions.AI;

namespace Cellm.Models.Providers.Ollama;

internal class OllamaConfiguration : IProviderConfiguration
{
Expand All @@ -9,4 +11,6 @@ internal class OllamaConfiguration : IProviderConfiguration
public List<string> Models { get; init; } = [];

public int MaxInputTokens { get; init; } = 16364;

public AdditionalPropertiesDictionary AdditionalProperties { get; init; } = [];
}
5 changes: 0 additions & 5 deletions src/Cellm.Models/Providers/Ollama/OllamaRequest.cs

This file was deleted.

30 changes: 0 additions & 30 deletions src/Cellm.Models/Providers/Ollama/OllamaRequestHandler.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/Cellm.Models/Providers/Ollama/OllamaResponse.cs

This file was deleted.

5 changes: 0 additions & 5 deletions src/Cellm.Models/Providers/OpenAi/OpenAiRequest.cs

This file was deleted.

24 changes: 0 additions & 24 deletions src/Cellm.Models/Providers/OpenAi/OpenAiRequestHandler.cs

This file was deleted.

6 changes: 0 additions & 6 deletions src/Cellm.Models/Providers/OpenAi/OpenAiResponse.cs

This file was deleted.

This file was deleted.

Loading