-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathAiProviderFactory.cs
32 lines (26 loc) · 1.19 KB
/
AiProviderFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using AiServer.ServiceModel;
namespace AiServer.ServiceInterface;
public record OpenAiChatResult(OpenAiChatResponse Response, int DurationMs);
public interface IOpenAiProvider
{
Task<bool> IsOnlineAsync(AiProvider provider, CancellationToken token = default);
Task<OpenAiChatResult> ChatAsync(AiProvider provider, OpenAiChat request, CancellationToken token = default);
}
public record OllamaGenerationResult(OllamaGenerateResponse Response, int DurationMs);
public interface IOllamaAiProvider
{
Task<OllamaGenerationResult> GenerateAsync(AiProvider provider, OllamaGenerate request, CancellationToken token = default);
}
public class AiProviderFactory(OpenAiProvider openAiProvider, OllamaAiProvider ollamaAiProvider, GoogleAiProvider googleProvider, AnthropicAiProvider anthropicAiProvider)
{
public IOpenAiProvider GetOpenAiProvider(AiProviderType aiProviderType=AiProviderType.OpenAiProvider)
{
return aiProviderType switch
{
AiProviderType.OllamaAiProvider => ollamaAiProvider,
AiProviderType.GoogleAiProvider => googleProvider,
AiProviderType.AnthropicAiProvider => anthropicAiProvider,
_ => openAiProvider
};
}
}