Fix Krea image generation by removing unsupported batchSize
Krea removed the batchSize parameter ("Generation batch size is no longer
supported, submit one request per output"), so every image request failed
with HTTP 422 — breaking session/agent avatar generation. Drop batchSize
from the payload and instead send one request per requested image in a
loop, collecting all returned jobs. Endpoint paths, Bearer auth and base
URL are unchanged.
- KreaService: remove batchSize from payload
- KreaService: loop record.BatchSize times, one POST per image, aggregate
jobs (handles both array and single-object responses)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
c32d1e004f
commit
1641bf11b6
1 file changed
+18
-8
+18
-8
@@ -92,9 +92,10 @@ namespace Gott.Services
|
||||
};
|
||||
|
||||
// Build payload
|
||||
// Hinweis: Krea unterstützt 'batchSize' nicht mehr ("batch size is no longer supported,
|
||||
// submit one request per output") -> wir senden pro gewünschtem Bild eine eigene Anfrage.
|
||||
var payload = new Dictionary<string, object>();
|
||||
payload["prompt"] = prompt;
|
||||
payload["batchSize"] = record.BatchSize;
|
||||
|
||||
if (!MINIMAL_MODELS.Contains(model))
|
||||
{
|
||||
@@ -117,16 +118,25 @@ namespace Gott.Services
|
||||
client.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (compatible; Gott/1.0)");
|
||||
|
||||
var json = JsonSerializer.Serialize(payload);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var response = await client.PostAsync($"{BASE_URL}{endpoint}", content);
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
// Eine Anfrage pro gewünschtem Bild (batchSize wird serverseitig nicht mehr akzeptiert).
|
||||
var jobs = new List<JsonNode>();
|
||||
for (int b = 0; b < record.BatchSize; b++)
|
||||
{
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception($"Krea API Fehler {(int)response.StatusCode}: {responseBody}");
|
||||
var response = await client.PostAsync($"{BASE_URL}{endpoint}", content);
|
||||
var responseBody = await response.Content.ReadAsStringAsync();
|
||||
|
||||
var jobsNode = JsonNode.Parse(responseBody);
|
||||
var jobs = jobsNode is JsonArray arr ? arr.ToList() : new List<JsonNode> { jobsNode };
|
||||
if (!response.IsSuccessStatusCode)
|
||||
throw new Exception($"Krea API Fehler {(int)response.StatusCode}: {responseBody}");
|
||||
|
||||
var node = JsonNode.Parse(responseBody);
|
||||
if (node is JsonArray arr)
|
||||
jobs.AddRange(arr.Where(j => j != null));
|
||||
else if (node != null)
|
||||
jobs.Add(node);
|
||||
}
|
||||
|
||||
// Wait for all jobs
|
||||
var allUrls = new List<string>();
|
||||
|
||||
Reference in new issue
Block a user