forked from LykosAI/StabilityMatrix
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathComfyInputInfo.cs
More file actions
64 lines (50 loc) · 1.75 KB
/
ComfyInputInfo.cs
File metadata and controls
64 lines (50 loc) · 1.75 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
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
namespace StabilityMatrix.Core.Models.Api.Comfy;
public class ComfyInputInfo
{
[JsonPropertyName("required")]
public Dictionary<string, JsonNode>? Required { get; set; }
[JsonPropertyName("optional")]
public Dictionary<string, JsonNode>? Optional { get; set; }
public List<string>? GetRequiredValueAsNestedList(string key)
{
var value = Required?[key];
// value usually is a [["a", "b"]] array
// but can also be [["a", "b"], {"x": "y"}] array
// or sometimes ["COMBO", {"options": ["a", "b"]}] array
var outerArray = value?.Deserialize<JsonArray>();
if (
outerArray?.Count > 1
&& outerArray.FirstOrDefault() is JsonValue jsonValue
&& jsonValue.ToString().Equals("COMBO")
)
{
var options = outerArray[1]?["options"];
if (options is JsonArray optionsArray)
{
return optionsArray.Deserialize<List<string>>();
}
}
if (outerArray?.FirstOrDefault() is not { } innerNode)
{
return null;
}
var innerList = innerNode.Deserialize<List<string>>();
return innerList;
}
public List<string>? GetOptionalValueAsNestedList(string key)
{
var value = Optional?[key];
// value usually is a [["a", "b"]] array
// but can also be [["a", "b"], {"x": "y"}] array
var outerArray = value?.Deserialize<JsonArray>();
if (outerArray?.FirstOrDefault() is not { } innerNode)
{
return null;
}
var innerList = innerNode.Deserialize<List<string>>();
return innerList;
}
}