WordPress\AiClient\Providers\OpenAiCompatibleImplementation

AbstractOpenAiCompatibleImageGenerationModel::preparePromptParam │ protected │ WP 0.1.0

Prepares the prompt parameter for the API request.

Метод класса: AbstractOpenAiCompatibleImageGenerationModel{}

Хуков нет.

Возвращает

string. The prepared prompt parameter.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->preparePromptParam( $messages ): string;
$messages(list) (обязательный)
The messages to prepare. However as of today, OpenAI compatible image generation endpoints only support a single user message.

Список изменений

С версии 0.1.0 Введена.

Код AbstractOpenAiCompatibleImageGenerationModel::preparePromptParam() WP 7.1.2

protected function preparePromptParam(array $messages): string
{
    if (count($messages) !== 1) {
        throw new InvalidArgumentException('The API requires a single user message as prompt.');
    }
    $message = $messages[0];
    if (!$message->getRole()->isUser()) {
        throw new InvalidArgumentException('The API requires a user message as prompt.');
    }
    $text = null;
    foreach ($message->getParts() as $part) {
        $text = $part->getText();
        if ($text !== null) {
            break;
        }
    }
    if ($text === null) {
        throw new InvalidArgumentException('The API requires a single text message part as prompt.');
    }
    return $text;
}