Skip to content

Commit

Permalink
fix: Increase timeouts for local LLMs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspermarstal committed Nov 17, 2024
1 parent 82437ef commit 201400b
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 13 deletions.
2 changes: 2 additions & 0 deletions src/Cellm/AddIn/CellmConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class CellmConfiguration

public int MaxOutputTokens { get; init; }

public int HttpTimeoutInSeconds { get; init; }

public int CacheTimeoutInSeconds { get; init; }
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net;
using System.Threading.RateLimiting;
using Cellm.AddIn;
using Polly;
using Polly.CircuitBreaker;
using Polly.Retry;
Expand All @@ -9,11 +10,13 @@ namespace Cellm.Services.Configuration;

public class ResiliencePipelineConfigurator
{
private readonly CellmConfiguration _cellmConfiguration;

Check warning on line 13 in src/Cellm/Services/Configuration/ResiliencePipelineConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build

Field 'ResiliencePipelineConfigurator._cellmConfiguration' is never assigned to, and will always have its default value null
private readonly RateLimiterConfiguration _rateLimiterConfiguration;
private readonly CircuitBreakerConfiguration _circuitBreakerConfiguration;
private readonly RetryConfiguration _retryConfiguration;

public ResiliencePipelineConfigurator(

Check warning on line 18 in src/Cellm/Services/Configuration/ResiliencePipelineConfigurator.cs

View workflow job for this annotation

GitHub Actions / Lint

Non-nullable field '_cellmConfiguration' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 18 in src/Cellm/Services/Configuration/ResiliencePipelineConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable field '_cellmConfiguration' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 18 in src/Cellm/Services/Configuration/ResiliencePipelineConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build

Non-nullable field '_cellmConfiguration' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
CellmConfiguration cellmConfiguration,
RateLimiterConfiguration rateLimiterConfiguration,
CircuitBreakerConfiguration circuitBreakerConfiguration,
RetryConfiguration retryConfiguration)
Expand Down Expand Up @@ -54,7 +57,7 @@ public void ConfigureResiliencePipeline(ResiliencePipelineBuilder<HttpResponseMe
MinimumThroughput = _circuitBreakerConfiguration.MinimumThroughput,
BreakDuration = TimeSpan.FromSeconds(_circuitBreakerConfiguration.BreakDurationInSeconds),
})
.AddTimeout(TimeSpan.FromSeconds(_retryConfiguration.RequestTimeoutInSeconds))
.AddTimeout(TimeSpan.FromSeconds(_cellmConfiguration.HttpTimeoutInSeconds))
.Build();
}

Expand Down
4 changes: 0 additions & 4 deletions src/Cellm/Services/Configuration/RetryConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ public class RetryConfiguration
public int MaxRetryAttempts { get; init; }

public int DelayInSeconds { get; init; }

public int RequestTimeoutInSeconds { get; init; }

public int TimeoutInSeconds { get; init; }
}
5 changes: 4 additions & 1 deletion src/Cellm/Services/ServiceLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
?? throw new NullReferenceException(nameof(RetryConfiguration));

var resiliencePipelineConfigurator = new ResiliencePipelineConfigurator(
rateLimiterConfiguration, circuitBreakerConfiguration, retryConfiguration);
cellmConfiguration, rateLimiterConfiguration, circuitBreakerConfiguration, retryConfiguration);

var anthropicConfiguration = configuration.GetRequiredSection(nameof(AnthropicConfiguration)).Get<AnthropicConfiguration>()
?? throw new NullReferenceException(nameof(AnthropicConfiguration));
Expand All @@ -122,6 +122,7 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
anthropicHttpClient.BaseAddress = anthropicConfiguration.BaseAddress;
anthropicHttpClient.DefaultRequestHeaders.Add("x-api-key", anthropicConfiguration.ApiKey);
anthropicHttpClient.DefaultRequestHeaders.Add("anthropic-version", anthropicConfiguration.Version);
anthropicHttpClient.Timeout = TimeSpan.FromSeconds(cellmConfiguration.HttpTimeoutInSeconds + 1);
}).AddResilienceHandler($"{nameof(AnthropicRequestHandler)}ResiliencePipeline", resiliencePipelineConfigurator.ConfigureResiliencePipeline);

var googleAiConfiguration = configuration.GetRequiredSection(nameof(GoogleAiConfiguration)).Get<GoogleAiConfiguration>()
Expand All @@ -130,6 +131,7 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
services.AddHttpClient<IRequestHandler<GoogleAiRequest, GoogleAiResponse>, GoogleAiRequestHandler>(googleHttpClient =>
{
googleHttpClient.BaseAddress = googleAiConfiguration.BaseAddress;
googleHttpClient.Timeout = TimeSpan.FromSeconds(cellmConfiguration.HttpTimeoutInSeconds + 1);
}).AddResilienceHandler($"{nameof(GoogleAiRequestHandler)}ResiliencePipeline", resiliencePipelineConfigurator.ConfigureResiliencePipeline);

var openAiConfiguration = configuration.GetRequiredSection(nameof(OpenAiConfiguration)).Get<OpenAiConfiguration>()
Expand All @@ -139,6 +141,7 @@ private static IServiceCollection ConfigureServices(IServiceCollection services)
{
openAiHttpClient.BaseAddress = openAiConfiguration.BaseAddress;
openAiHttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {openAiConfiguration.ApiKey}");
openAiHttpClient.Timeout = TimeSpan.FromSeconds(cellmConfiguration.HttpTimeoutInSeconds + 1);
}).AddResilienceHandler($"{nameof(OpenAiRequestHandler)}ResiliencePipeline", resiliencePipelineConfigurator.ConfigureResiliencePipeline);

services
Expand Down
3 changes: 2 additions & 1 deletion src/Cellm/appsettings.Local.Anthropic.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ApiKey": "YOUR_ANTHROPIC_APIKEY"
},
"CellmConfiguration": {
"DefaultProvider": "Anthropic"
"DefaultProvider": "Anthropic",
"HttpTimeoutInSeconds": 30
}
}
3 changes: 2 additions & 1 deletion src/Cellm/appsettings.Local.GoogleAi.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"ApiKey": "YOUR_GOOGLEAI_APIKEY"
},
"CellmConfiguration": {
"DefaultProvider": "GoogleAI"
"DefaultProvider": "GoogleAI",
"HttpTimeoutInSeconds": 30
}
}
3 changes: 2 additions & 1 deletion src/Cellm/appsettings.Local.Mistral.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"ApiKey": "YOUR_MISTRAL_APIKEY"
},
"CellmConfiguration": {
"DefaultProvider": "OpenAI"
"DefaultProvider": "OpenAI",
"HttpTimeoutInSeconds": 30
}
}
3 changes: 2 additions & 1 deletion src/Cellm/appsettings.Local.OpenAi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"ApiKey": "YOUR_OPENAI_APIKEY"
},
"CellmConfiguration": {
"DefaultProvider": "OpenAI"
"DefaultProvider": "OpenAI",
"HttpTimeoutInSeconds": 30
}
}
6 changes: 3 additions & 3 deletions src/Cellm/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"DefaultProvider": "OpenAI",
"DefaultTemperature": 0,
"MaxOutputTokens": 256,
"CacheTimeoutInSeconds": 300
"HttpTimeoutInSeconds": 600,
"CacheTimeoutInSeconds": 3600
},
"RateLimiterConfiguration": {
"TokenLimit": 4,
Expand All @@ -33,8 +34,7 @@
},
"RetryConfiguration": {
"MaxRetryAttempts": 5,
"DelayInSeconds": 4,
"RequestTimeoutInSeconds": 60
"DelayInSeconds": 4
},
"SentryConfiguration": {
"IsEnabled": false,
Expand Down

0 comments on commit 201400b

Please sign in to comment.