-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathChatClientConfiguration.cs
373 lines (322 loc) · 8.49 KB
/
ChatClientConfiguration.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// Copyright (c) Rodel. All rights reserved.
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace RodelChat.Models.Client;
/// <summary>
/// 聊天客户端配置.
/// </summary>
public sealed class ChatClientConfiguration
{
/// <summary>
/// Open AI 客户端配置.
/// </summary>
[JsonPropertyName("openai")]
public OpenAIClientConfig? OpenAI { get; set; }
/// <summary>
/// Azure Open AI 客户端配置.
/// </summary>
[JsonPropertyName("azure_openai")]
public AzureOpenAIClientConfig? AzureOpenAI { get; set; }
/// <summary>
/// 智谱客户端配置.
/// </summary>
[JsonPropertyName("zhipu")]
public ZhiPuClientConfig? ZhiPu { get; set; }
/// <summary>
/// 零一万物客户端配置.
/// </summary>
[JsonPropertyName("lingyi")]
public LingYiClientConfig? LingYi { get; set; }
/// <summary>
/// 月之暗面客户端配置.
/// </summary>
[JsonPropertyName("moonshot")]
public MoonshotClientConfig? Moonshot { get; set; }
/// <summary>
/// 阿里灵积客户端配置.
/// </summary>
[JsonPropertyName("dash_scope")]
public DashScopeClientConfig? DashScope { get; set; }
/// <summary>
/// DeepSeek 客户端配置.
/// </summary>
[JsonPropertyName("deep_seek")]
public DeepSeekClientConfig? DeepSeek { get; set; }
/// <summary>
/// 千帆客户端配置.
/// </summary>
[JsonPropertyName("qianfan")]
public QianFanClientConfig? QianFan { get; set; }
/// <summary>
/// 讯飞星火客户端配置.
/// </summary>
[JsonPropertyName("spark_desk")]
public SparkDeskClientConfig? SparkDesk { get; set; }
/// <summary>
/// Gemini 客户端配置.
/// </summary>
[JsonPropertyName("gemini")]
public GeminiClientConfig? Gemini { get; set; }
/// <summary>
/// Groq 客户端配置.
/// </summary>
[JsonPropertyName("groq")]
public GroqClientConfig? Groq { get; set; }
/// <summary>
/// Mistral AI 客户端配置.
/// </summary>
[JsonPropertyName("mistral_ai")]
public MistralAIClientConfig? MistralAI { get; set; }
/// <summary>
/// Perplexity 客户端配置.
/// </summary>
[JsonPropertyName("perplexity")]
public PerplexityClientConfig? Perplexity { get; set; }
/// <summary>
/// Together AI 客户端配置.
/// </summary>
[JsonPropertyName("together_ai")]
public TogetherAIClientConfig? TogetherAI { get; set; }
/// <summary>
/// Open Router 客户端配置.
/// </summary>
[JsonPropertyName("open_router")]
public OpenRouterClientConfig? OpenRouter { get; set; }
/// <summary>
/// Anthropic 客户端配置.
/// </summary>
[JsonPropertyName("anthropic")]
public AnthropicClientConfig? Anthropic { get; set; }
/// <summary>
/// Ollama 客户端配置.
/// </summary>
[JsonPropertyName("ollama")]
public OllamaClientConfig? Ollama { get; set; }
/// <summary>
/// 混元客户端配置.
/// </summary>
[JsonPropertyName("hunyuan")]
public HunYuanClientConfig? HunYuan { get; set; }
/// <summary>
/// 硅动客户端配置.
/// </summary>
[JsonPropertyName("silicon_flow")]
public SiliconFlowClientConfig? SiliconFlow { get; set; }
/// <summary>
/// 豆包客户端配置.
/// </summary>
[JsonPropertyName("doubao")]
public DouBaoClientConfig? DouBao { get; set; }
}
/// <summary>
/// Open AI 客户端配置.
/// </summary>
public class OpenAIClientConfig : ClientEndpointConfigBase
{
/// <summary>
/// 组织 ID.
/// </summary>
[JsonPropertyName("organization")]
public string? OrganizationId { get; set; }
}
/// <summary>
/// Azure Open AI 客户端配置.
/// </summary>
public class AzureOpenAIClientConfig : ClientEndpointConfigBase
{
/// <inheritdoc/>
public override bool IsValid()
{
return base.IsValid()
&& !string.IsNullOrEmpty(Endpoint)
&& CustomModels != null
&& CustomModels.Count > 0;
}
}
/// <summary>
/// 千帆客户端配置.
/// </summary>
public class QianFanClientConfig : ClientConfigBase
{
/// <summary>
/// 密匙.
/// </summary>
[JsonPropertyName("secret")]
public string Secret { get; set; }
/// <inheritdoc/>
public override bool IsValid()
=> base.IsValid() && !string.IsNullOrEmpty(Secret);
}
/// <summary>
/// 讯飞星火服务配置.
/// </summary>
public sealed class SparkDeskClientConfig : QianFanClientConfig
{
/// <summary>
/// 应用程序 ID.
/// </summary>
[JsonPropertyName("app_id")]
public string AppId { get; set; }
/// <inheritdoc/>
public override bool IsValid()
=> base.IsValid() && !string.IsNullOrEmpty(AppId);
}
/// <summary>
/// 混元客户端配置.
/// </summary>
public sealed class HunYuanClientConfig : ClientConfigBase
{
/// <summary>
/// 密匙 ID.
/// </summary>
[JsonPropertyName("secret_id")]
public string SecretId { get; set; }
/// <inheritdoc/>
public override bool IsValid()
=> base.IsValid() && !string.IsNullOrEmpty(SecretId);
}
/// <summary>
/// 豆包大模型配置.
/// </summary>
public sealed class DouBaoClientConfig : ClientConfigBase
{
/// <inheritdoc/>
public override bool IsValid()
=> base.IsValid() && IsCustomModelNotEmpty();
}
/// <summary>
/// 智谱客户端配置.
/// </summary>
public sealed class ZhiPuClientConfig : ClientConfigBase
{
}
/// <summary>
/// 零一万物客户端配置.
/// </summary>
public sealed class LingYiClientConfig : ClientConfigBase
{
}
/// <summary>
/// 月之暗面客户端配置.
/// </summary>
public sealed class MoonshotClientConfig : ClientConfigBase
{
}
/// <summary>
/// 阿里灵积客户端配置.
/// </summary>
public sealed class DashScopeClientConfig : ClientConfigBase
{
}
/// <summary>
/// Gemini 客户端配置.
/// </summary>
public sealed class GeminiClientConfig : ClientEndpointConfigBase
{
}
/// <summary>
/// Groq 客户端配置.
/// </summary>
public sealed class GroqClientConfig : ClientConfigBase
{
}
/// <summary>
/// Mistral AI 客户端配置.
/// </summary>
public sealed class MistralAIClientConfig : ClientConfigBase
{
}
/// <summary>
/// Perplexity 客户端配置.
/// </summary>
public sealed class PerplexityClientConfig : ClientConfigBase
{
}
/// <summary>
/// Together AI 客户端配置.
/// </summary>
public sealed class TogetherAIClientConfig : ClientConfigBase
{
}
/// <summary>
/// Open Router 客户端配置.
/// </summary>
public sealed class OpenRouterClientConfig : ClientConfigBase
{
}
/// <summary>
/// DeepSeek 客户端配置.
/// </summary>
public sealed class DeepSeekClientConfig : ClientConfigBase
{
}
/// <summary>
/// Anthropic 客户端配置.
/// </summary>
public sealed class AnthropicClientConfig : ClientEndpointConfigBase
{
}
/// <summary>
/// 硅动客户端配置.
/// </summary>
public sealed class SiliconFlowClientConfig : ClientConfigBase
{
}
/// <summary>
/// Ollama 客户端配置.
/// </summary>
public sealed class OllamaClientConfig : ClientEndpointConfigBase
{
/// <summary>
/// Initializes a new instance of the <see cref="OllamaClientConfig"/> class.
/// </summary>
public OllamaClientConfig() => Key = "ollama";
/// <inheritdoc/>
public override bool IsValid()
=> IsCustomModelNotEmpty() && !string.IsNullOrEmpty(Endpoint);
}
/// <summary>
/// 配置基类.
/// </summary>
public abstract class ConfigBase
{
/// <summary>
/// 自定义模型列表.
/// </summary>
[JsonPropertyName("models")]
public List<ChatModel>? CustomModels { get; set; }
/// <summary>
/// 自定义模型是否不为空.
/// </summary>
/// <returns>是否不为空.</returns>
public bool IsCustomModelNotEmpty()
=> CustomModels != null && CustomModels.Count > 0;
}
/// <summary>
/// 客户端配置基类.
/// </summary>
public abstract class ClientConfigBase : ConfigBase
{
/// <summary>
/// 访问密钥.
/// </summary>
[JsonPropertyName("key")]
public string? Key { get; set; }
/// <summary>
/// 是否有效.
/// </summary>
/// <returns>配置是否有效.</returns>
public virtual bool IsValid()
=> !string.IsNullOrEmpty(Key);
}
/// <summary>
/// 客户端终结点配置基类.
/// </summary>
public abstract class ClientEndpointConfigBase : ClientConfigBase
{
/// <summary>
/// 终结点.
/// </summary>
[JsonPropertyName("endpoint")]
public string? Endpoint { get; set; }
}