-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathTestOllamaApiClient.cs
111 lines (89 loc) · 3.47 KB
/
TestOllamaApiClient.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#pragma warning disable CS8424 // The EnumeratorCancellationAttribute will have no effect. The attribute is only effective on a parameter of type CancellationToken in an async-iterator method returning IAsyncEnumerable
using System.Runtime.CompilerServices;
using OllamaSharp;
using OllamaSharp.Models;
using OllamaSharp.Models.Chat;
namespace Tests;
public class TestOllamaApiClient : IOllamaApiClient
{
private ChatResponseStream[] _expectedChatResponses = [];
private GenerateResponseStream[] _expectedGenerateResponses = [];
public Uri Uri { get; } = new("http://localhost");
public string SelectedModel { get; set; } = string.Empty;
internal void SetExpectedChatResponses(params ChatResponseStream[] responses)
{
_expectedChatResponses = responses;
}
internal void SetExpectedGenerateResponses(params GenerateResponseStream[] responses)
{
_expectedGenerateResponses = responses;
}
public async IAsyncEnumerable<ChatResponseStream?> ChatAsync(ChatRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var response in _expectedChatResponses)
{
await Task.Yield();
yield return response;
}
}
public Task CopyModelAsync(CopyModelRequest request, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public IAsyncEnumerable<CreateModelResponse?> CreateModelAsync(CreateModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task DeleteModelAsync(DeleteModelRequest request, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<EmbedResponse> EmbedAsync(EmbedRequest request, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public async IAsyncEnumerable<GenerateResponseStream?> GenerateAsync(GenerateRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
foreach (var response in _expectedGenerateResponses)
{
await Task.Yield();
yield return response;
}
}
public Task<Version> GetVersionAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task PushBlobAsync(string digest, byte[] bytes, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<bool> IsBlobExistsAsync(string digest, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<bool> IsRunningAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<IEnumerable<Model>> ListLocalModelsAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<IEnumerable<RunningModel>> ListRunningModelsAsync(CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public IAsyncEnumerable<PullModelResponse?> PullModelAsync(PullModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public IAsyncEnumerable<PushModelResponse?> PushModelAsync(PushModelRequest request, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
public Task<ShowModelResponse> ShowModelAsync(ShowModelRequest request, CancellationToken cancellationToken = default)
{
throw new NotImplementedException();
}
}