-
Notifications
You must be signed in to change notification settings - Fork 280
Expand file tree
/
Copy pathFoundryModelInfo.cs
More file actions
190 lines (143 loc) · 5.69 KB
/
FoundryModelInfo.cs
File metadata and controls
190 lines (143 loc) · 5.69 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
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
// --------------------------------------------------------------------------------------------------------------------
// <copyright company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace Microsoft.AI.Foundry.Local;
using System.Text.Json;
using System.Text.Json.Serialization;
public record PromptTemplate
{
[JsonPropertyName("assistant")]
public string Assistant { get; init; } = default!;
[JsonPropertyName("prompt")]
public string Prompt { get; init; } = default!;
}
public record Runtime
{
[JsonPropertyName("deviceType")]
public DeviceType DeviceType { get; init; } = default!;
[JsonPropertyName("executionProvider")]
public ExecutionProvider ExecutionProvider { get; init; } = default!;
}
public record ModelSettings
{
// The sample shows an empty array; keep it open‑ended.
[JsonPropertyName("parameters")]
public List<JsonElement> Parameters { get; init; } = [];
}
public record FoundryCachedModel(string Name, string? Id);
public record FoundryDownloadResult(bool Success, string? ErrorMessage);
internal sealed record FoundryModelDownload(
string Name,
string Uri,
string Path,
string ProviderType,
PromptTemplate PromptTemplate);
internal sealed record FoundryDownloadBody(FoundryModelDownload Model, bool IgnorePipeReport);
public record ModelInfo
{
[JsonPropertyName("name")]
public string ModelId { get; init; } = default!;
[JsonPropertyName("displayName")]
public string DisplayName { get; init; } = default!;
[JsonPropertyName("providerType")]
public string ProviderType { get; init; } = default!;
[JsonPropertyName("uri")]
public string Uri { get; init; } = default!;
[JsonPropertyName("version")]
public string Version { get; init; } = default!;
[JsonPropertyName("modelType")]
public string ModelType { get; init; } = default!;
[JsonPropertyName("promptTemplate")]
public PromptTemplate PromptTemplate { get; init; } = default!;
[JsonPropertyName("publisher")]
public string Publisher { get; init; } = default!;
[JsonPropertyName("task")]
public string Task { get; init; } = default!;
[JsonPropertyName("runtime")]
public Runtime Runtime { get; init; } = default!;
[JsonPropertyName("fileSizeMb")]
public long FileSizeMb { get; init; }
[JsonPropertyName("modelSettings")]
public ModelSettings ModelSettings { get; init; } = default!;
[JsonPropertyName("alias")]
public string Alias { get; init; } = default!;
[JsonPropertyName("supportsToolCalling")]
public bool SupportsToolCalling { get; init; }
[JsonPropertyName("license")]
public string License { get; init; } = default!;
[JsonPropertyName("licenseDescription")]
public string LicenseDescription { get; init; } = default!;
[JsonPropertyName("parentModelUri")]
public string ParentModelUri { get; init; } = default!;
[JsonPropertyName("maxOutputTokens")]
public long MaxOutputTokens { get; init; }
[JsonPropertyName("minFLVersion")]
public string MinFLVersion { get; init; } = default!;
}
internal sealed class DownloadRequest
{
internal sealed class ModelInfo
{
[JsonPropertyName("Name")]
public required string Name { get; set; }
[JsonPropertyName("Uri")]
public required string Uri { get; set; }
[JsonPropertyName("ProviderType")]
public required string ProviderType { get; set; }
[JsonPropertyName("PromptTemplate")]
public required PromptTemplate PromptTemplate { get; set; }
}
[JsonPropertyName("Model")]
public required ModelInfo Model { get; set; }
[JsonPropertyName("token")]
public required string Token { get; set; }
[JsonPropertyName("IgnorePipeReport")]
public required bool IgnorePipeReport { get; set; }
}
internal sealed class UpgradeRequest
{
internal sealed class UpgradeBody
{
[JsonPropertyName("Name")]
public required string Name { get; set; } = string.Empty;
[JsonPropertyName("Uri")]
public required string Uri { get; set; } = string.Empty;
[JsonPropertyName("Publisher")]
public required string Publisher { get; set; } = string.Empty;
[JsonPropertyName("ProviderType")]
public required string ProviderType { get; set; } = string.Empty;
[JsonPropertyName("PromptTemplate")]
public required PromptTemplate PromptTemplate { get; set; }
}
[JsonPropertyName("model")]
public required UpgradeBody Model { get; set; }
[JsonPropertyName("token")]
public required string Token { get; set; }
[JsonPropertyName("IgnorePipeReport")]
public required bool IgnorePipeReport { get; set; }
}
public record ModelDownloadProgress
{
public double Percentage { get; init; }
public bool IsCompleted { get; init; }
public ModelInfo? ModelInfo { get; init; }
public string? ErrorMessage { get; init; }
public static ModelDownloadProgress Progress(double percentage) =>
new()
{ Percentage = percentage, IsCompleted = false };
public static ModelDownloadProgress Completed(ModelInfo modelInfo) =>
new()
{ Percentage = 100, IsCompleted = true, ModelInfo = modelInfo };
public static ModelDownloadProgress Error(string errorMessage) =>
new()
{ IsCompleted = true, ErrorMessage = errorMessage };
}
[JsonSerializable(typeof(ModelInfo))]
[JsonSerializable(typeof(List<ModelInfo>))]
[JsonSerializable(typeof(int))]
[JsonSerializable(typeof(ModelDownloadProgress))]
public partial class ModelGenerationContext : JsonSerializerContext
{
}