Skip to content

Commit

Permalink
refactor: Add provider enum
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspermarstal committed Oct 23, 2024
1 parent 0cc6423 commit 31fc3ce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Cellm/Models/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,18 @@ public async Task<Prompt> Send(Prompt prompt, string? provider, Uri? baseAddress
{
provider ??= _cellmConfiguration.DefaultProvider;

IModelResponse response = provider.ToLower() switch
if (!Enum.TryParse<Providers>(provider, true, out var parsedProvider))
{
"anthropic" => await _sender.Send(new AnthropicRequest(prompt, provider, baseAddress)),
"googleai" => await _sender.Send(new GoogleAiRequest(prompt, provider, baseAddress)),
"llamafile" => await _sender.Send(new LlamafileRequest(prompt)),
"openai" => await _sender.Send(new OpenAiRequest(prompt, provider, baseAddress)),
_ => throw new ArgumentException($"Unsupported client type: {provider}")
throw new ArgumentException($"Unsupported provider: {provider}");
}

IModelResponse response = parsedProvider switch
{
Providers.Anthropic => await _sender.Send(new AnthropicRequest(prompt, provider, baseAddress)),
Providers.GoogleAi => await _sender.Send(new GoogleAiRequest(prompt, provider, baseAddress)),
Providers.Llamafile => await _sender.Send(new LlamafileRequest(prompt)),
Providers.OpenAi => await _sender.Send(new OpenAiRequest(prompt, provider, baseAddress)),
_ => throw new InvalidOperationException($"Provider {parsedProvider} is defined but not implemented")
};

return response.Prompt;
Expand Down
9 changes: 9 additions & 0 deletions src/Cellm/Models/Providers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Cellm.Models;

public enum Providers
{
Anthropic,
GoogleAi,
Llamafile,
OpenAi
}

0 comments on commit 31fc3ce

Please sign in to comment.