WordPress\AiClient\Providers\OpenAiCompatibleImplementation
AbstractOpenAiCompatibleImageGenerationModel::parseResponseChoiceToCandidate
Parses a single choice from the API response into a Candidate object.
Метод класса: AbstractOpenAiCompatibleImageGenerationModel{}
Хуков нет.
Возвращает
Candidate. The parsed candidate.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->parseResponseChoiceToCandidate( $choiceData, $index, $expectedMimeType ): Candidate;
- $choiceData(ChoiceData) (обязательный)
- The choice data from the API response.
- $index(int) (обязательный)
- The index of the choice in the choices array.
- $expectedMimeType(строка)
- The expected MIME type the response is in.
По умолчанию:'image/png'
Список изменений
| С версии 0.1.0 | Введена. |
Код AbstractOpenAiCompatibleImageGenerationModel::parseResponseChoiceToCandidate() AbstractOpenAiCompatibleImageGenerationModel::parseResponseChoiceToCandidate WP 7.1.2
protected function parseResponseChoiceToCandidate(array $choiceData, int $index, string $expectedMimeType = 'image/png'): Candidate
{
if (isset($choiceData['url']) && is_string($choiceData['url'])) {
$imageFile = new File($choiceData['url'], $expectedMimeType);
} elseif (isset($choiceData['b64_json']) && is_string($choiceData['b64_json'])) {
$imageFile = new File($choiceData['b64_json'], $expectedMimeType);
} else {
throw ResponseException::fromInvalidData($this->providerMetadata()->getName(), "choices[{$index}]", 'The value must contain either a url or b64_json key with a string value.');
}
$parts = [new MessagePart($imageFile)];
$message = new Message(MessageRoleEnum::model(), $parts);
return new Candidate($message, FinishReasonEnum::stop());
}