Make LocalAI Stable Diffusion work in plugin.

This commit is contained in:
hibobmaster 2023-12-24 22:44:02 +08:00
parent 625c47ab44
commit 49a3185585
Signed by: bobmaster
SSH key fingerprint: SHA256:5ZYgd8fg+PcNZNy4SzcSKu5JtqZyBF8kUhY7/k2viDk

View file

@ -66,22 +66,10 @@ class dalle extends GenericController
protected function prepare($opts)
{
if (filter_var($this->job['request'], FILTER_VALIDATE_URL)) {
// https://platform.openai.com/docs/api-reference/images/create-variation
// The image to use as the basis for the variation(s). Must be a valid PNG file, less than 4MB, and square.
$image = curl_file_create($this->job['request'], 'image/png');
$opts += [
'image' => $image,
'n' => $this->cfg->n,
'response_format' => $this->cfg->response_format,
];
} else {
$opts += [
'prompt' => trim($this->job['request']),
'n' => $this->cfg->n,
'response_format' => $this->cfg->response_format,
];
}
$opts += [
'prompt' => trim($this->job['request']),
];
return $opts;
}
@ -93,13 +81,7 @@ class dalle extends GenericController
$result = new resultSubmit();
if (empty($opts['image'])) {
// https://api.openai.com/v1/images/generations
$result->response = $api->sendRequest($this->cfg->url_generations, 'POST', $opts);
} else {
// https://api.openai.com/v1/images/variations
$result->response = $api->sendRequest($this->cfg->url_variations, 'POST', $opts);
}
$result->response = $api->sendRequest($this->cfg->url_generations, 'POST', $opts);
$result->responseCodes = $api->responseCodes;
@ -173,4 +155,4 @@ class dalle extends GenericController
return $result;
}
}
}