Skip to content

Commit

Permalink
bug: Fix llamafile health uri (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspermarstal authored Sep 19, 2024
1 parent a33979b commit 78ca510
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Cellm/Models/Llamafile/LlamafileClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ private async Task WaitForLlamafile(Process process)
var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(1));
var startTime = DateTime.UtcNow;

while ((DateTime.UtcNow - startTime).TotalSeconds < 30) // Max 30 seconds timeout
// 30 seconds timeout
while ((DateTime.UtcNow - startTime).TotalSeconds < 30)
{
if (process.HasExited)
{
Expand All @@ -136,10 +137,11 @@ private async Task WaitForLlamafile(Process process)

try
{
var response = await _httpClient.GetAsync($"{_openAiConfiguration.BaseAddress}/health", cancellationTokenSource.Token);
var response = await _httpClient.GetAsync(new Uri(_openAiConfiguration.BaseAddress, "health"), cancellationTokenSource.Token);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return; // Server is healthy
// Server is ready
return;
}
}
catch (TaskCanceledException)
Expand All @@ -149,9 +151,11 @@ private async Task WaitForLlamafile(Process process)
{
}

await Task.Delay(500); // Wait for 500ms before next attempt
// Wait for before next attempt
await Task.Delay(500);
}

process.Kill();
throw new CellmException("Timeout waiting for Llamafile server to be ready");
}
}
Expand Down

0 comments on commit 78ca510

Please sign in to comment.