-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathSettings.cs
49 lines (42 loc) · 1.41 KB
/
Settings.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
using System.Text.Json;
using System.Text.Json.Serialization;
namespace AIShell.Ollama.Agent;
internal class Settings
{
public string Model { get; }
public string Endpoint { get; }
public bool Stream { get; }
public Settings(ConfigData configData)
{
// Validate Model and Endpoint for null or empty values
if (string.IsNullOrWhiteSpace(configData.Model))
{
throw new ArgumentException("\"Model\" key is missing.");
}
if (string.IsNullOrWhiteSpace(configData.Endpoint))
{
throw new ArgumentException("\"Endpoint\" key is missing.");
}
Model = configData.Model;
Endpoint = configData.Endpoint;
Stream = configData.Stream;
}
}
internal class ConfigData
{
public string Model { get; set; }
public string Endpoint { get; set; }
public bool Stream { get; set; }
}
/// <summary>
/// Use source generation to serialize and deserialize the setting file.
/// Both metadata-based and serialization-optimization modes are used to gain the best performance.
/// </summary>
[JsonSourceGenerationOptions(
WriteIndented = true,
AllowTrailingCommas = true,
PropertyNameCaseInsensitive = true,
ReadCommentHandling = JsonCommentHandling.Skip,
UseStringEnumConverter = true)]
[JsonSerializable(typeof(ConfigData))]
internal partial class SourceGenerationContext : JsonSerializerContext { }