-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathComfyApiServices.cs
43 lines (40 loc) · 1.27 KB
/
ComfyApiServices.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
using AiServer.ServiceInterface.Comfy;
using AiServer.ServiceModel;
using AiServer.ServiceModel.Types;
using ServiceStack;
using ServiceStack.Jobs;
namespace AiServer.ServiceInterface;
public class ComfyApiServices(AppData appData) : Service
{
public async Task<object> Any(GetComfyModels request)
{
try
{
var comfyClient = new ComfyClient(request.ApiBaseUrl!, request.ApiKey);
var response = await comfyClient.GetModelsListAsync(default);
return new GetComfyModelsResponse
{
Results = response.Select(x => x.Name).ToList()
};
}
catch (Exception e)
{
Console.WriteLine(e);
throw HttpError.BadRequest(e.Message);
}
}
public async Task<object> Any(GetComfyModelMappings request)
{
var models = appData.MediaModelsMap
.Where(x => x.Value.ApiModels.ContainsKey("ComfyUI"))
.Select(x => new KeyValuePair<string, string>(x.Value.ApiModels["ComfyUI"], x.Key))
// Filter out duplicates
.GroupBy(x => x.Key)
.Select(x => x.First())
.ToDictionary();
return new GetComfyModelMappingsResponse
{
Models = models
};
}
}