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
2 changes: 1 addition & 1 deletion src/Cellm/AddIn/Functions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static async Task<string> CallModelAsync(Prompt prompt, string? provider
{
try
{
var client = ServiceLocator.Get<IClient>();
var client = ServiceLocator.Get<Client>();
var response = await client.Send(prompt, provider, baseAddress);
var content = response.Messages.Last().Content;
return content;
Expand Down
7 changes: 2 additions & 5 deletions src/Cellm/Models/Anthropic/AnthropicRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@ internal class AnthropicRequestHandler : IModelRequestHandler<AnthropicRequest,
private readonly AnthropicConfiguration _anthropicConfiguration;
private readonly CellmConfiguration _cellmConfiguration;
private readonly HttpClient _httpClient;
private readonly ICache _cache;
private readonly ISerde _serde;
private readonly Serde _serde;

public AnthropicRequestHandler(
IOptions<AnthropicConfiguration> anthropicConfiguration,
IOptions<CellmConfiguration> cellmConfiguration,
HttpClient httpClient,
ICache cache,
ISerde serde)
Serde serde)
{
_anthropicConfiguration = anthropicConfiguration.Value;
_cellmConfiguration = cellmConfiguration.Value;
_httpClient = httpClient;
_cache = cache;
_serde = serde;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Models/Cache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Cellm.Models;

internal class Cache : ICache
internal class Cache
{
private readonly IMemoryCache _memoryCache;
private readonly MemoryCacheEntryOptions _memoryCacheEntryOptions;
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Models/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace Cellm.Models;

internal class Client : IClient
internal class Client
{
private readonly CellmConfiguration _cellmConfiguration;
private readonly ISender _sender;
Expand Down
4 changes: 2 additions & 2 deletions src/Cellm/Models/GoogleAi/GoogleAiRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ internal class GoogleAiRequestHandler : IModelRequestHandler<GoogleAiRequest, Go
private readonly GoogleAiConfiguration _googleAiConfiguration;
private readonly CellmConfiguration _cellmConfiguration;
private readonly HttpClient _httpClient;
private readonly ISerde _serde;
private readonly Serde _serde;

public GoogleAiRequestHandler(
IOptions<GoogleAiConfiguration> googleAiConfiguration,
IOptions<CellmConfiguration> cellmConfiguration,
HttpClient httpClient,
ISerde serde)
Serde serde)
{
_googleAiConfiguration = googleAiConfiguration.Value;
_cellmConfiguration = cellmConfiguration.Value;
Expand Down
8 changes: 0 additions & 8 deletions src/Cellm/Models/ICache.cs

This file was deleted.

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

This file was deleted.

10 changes: 0 additions & 10 deletions src/Cellm/Models/ISerde.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Cellm/Models/ModelRequestBehavior/CachingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Cellm.Models.PipelineBehavior;
internal class CachingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
where TRequest : IModelRequest<TResponse>
{
private readonly ICache _cache;
private readonly Cache _cache;

public CachingBehavior(ICache cache)
public CachingBehavior(Cache cache)
{
_cache = cache;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Cellm/Models/OpenAi/OpenAiRequestHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ internal class OpenAiRequestHandler : IModelRequestHandler<OpenAiRequest, OpenAi
private readonly CellmConfiguration _cellmConfiguration;
private readonly HttpClient _httpClient;
private readonly ToolRunner _toolRunner;
private readonly ISerde _serde;
private readonly Serde _serde;

public OpenAiRequestHandler(
IOptions<OpenAiConfiguration> openAiConfiguration,
IOptions<CellmConfiguration> cellmConfiguration,
HttpClient httpClient,
ToolRunner toolRunner,
ISerde serde)
Serde serde)
{
_openAiConfiguration = openAiConfiguration.Value;
_cellmConfiguration = cellmConfiguration.Value;
Expand Down
2 changes: 1 addition & 1 deletion src/Cellm/Models/Serde.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Cellm.Models;

internal class Serde : ISerde
internal class Serde
{
private readonly JsonSerializerOptions _defaultOptions = new()
{
Expand Down
20 changes: 12 additions & 8 deletions src/Cellm/Services/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,28 +83,26 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
sentryLoggingOptions.ExperimentalMetrics = new ExperimentalMetricsOptions { EnableCodeLocations = true };
sentryLoggingOptions.AddIntegration(new ProfilingIntegration());
});
})
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(SentryBehavior<,>));
});

// Internals
services
.AddSingleton(configuration)
.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()))
.AddTransient<ArgumentParser>()
.AddSingleton<IClient, Client>()
.AddSingleton<ISerde, Serde>();
.AddSingleton<Client>()
.AddSingleton<Serde>();

// Cache
services
.AddMemoryCache()
.AddSingleton<ICache, Cache>()
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>));
.AddSingleton<Cache>();


// Tools
services
.AddSingleton<ToolRunner>()
.AddSingleton<ToolFactory>()
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(ToolBehavior<,>));
.AddSingleton<ToolFactory>();

// Model Providers
var rateLimiterConfiguration = configuration.GetRequiredSection(nameof(RateLimiterConfiguration)).Get<RateLimiterConfiguration>()
Expand Down Expand Up @@ -150,6 +148,12 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
.AddSingleton<LlamafileRequestHandler>()
.AddSingleton<LLamafileProcessManager>();

// Model request pipeline
services
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(SentryBehavior<,>))
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>))
.AddSingleton(typeof(IPipelineBehavior<,>), typeof(ToolBehavior<,>));

return services;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Cellm/Tools/ToolRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ namespace Cellm.Tools;
internal class ToolRunner
{
private readonly ISender _sender;
private readonly ISerde _serde;
private readonly Serde _serde;
private readonly ToolFactory _toolFactory;
private readonly IEnumerable<Type> _toolTypes;

public ToolRunner(ISender sender, ISerde serde, ToolFactory toolFactory)
public ToolRunner(ISender sender, Serde serde, ToolFactory toolFactory)
{
_sender = sender;
_serde = serde;
Expand Down