-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathUnavailableAIChatService.cs
More file actions
46 lines (41 loc) · 1.8 KB
/
UnavailableAIChatService.cs
File metadata and controls
46 lines (41 loc) · 1.8 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using ModelContextProtocol.Client;
using OpenAI.Responses;
namespace EssentialCSharp.Chat.Common.Services;
public sealed class UnavailableAIChatService : IAIChatService
{
private static AIChatUnavailableException CreateException() =>
new(AIConfigurationState.DevelopmentUnavailableMessage);
public Task<(string response, string responseId)> GetChatCompletion(
string prompt,
string? systemPrompt = null,
string? previousResponseId = null,
IMcpClient? mcpClient = null,
#pragma warning disable OPENAI001
IEnumerable<ResponseTool>? tools = null,
ResponseReasoningEffortLevel? reasoningEffortLevel = null,
#pragma warning restore OPENAI001
bool enableContextualSearch = false,
CancellationToken cancellationToken = default) =>
Task.FromException<(string response, string responseId)>(CreateException());
public IAsyncEnumerable<(string text, string? responseId)> GetChatCompletionStream(
string prompt,
string? systemPrompt = null,
string? previousResponseId = null,
IMcpClient? mcpClient = null,
#pragma warning disable OPENAI001
IEnumerable<ResponseTool>? tools = null,
ResponseReasoningEffortLevel? reasoningEffortLevel = null,
#pragma warning restore OPENAI001
bool enableContextualSearch = false,
CancellationToken cancellationToken = default) =>
ThrowUnavailable(cancellationToken);
private static async IAsyncEnumerable<(string text, string? responseId)> ThrowUnavailable(
[System.Runtime.CompilerServices.EnumeratorCancellation] CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
throw CreateException();
#pragma warning disable CS0162
yield break;
#pragma warning restore CS0162
}
}