# auto-alt-text/2.1.0/src/App/AIProviders/OpenAI/OpenAIVision.php

Auto Alt Text, version 2.1.0. 31 lines.

- Page: https://pluginprobe.com/plugins/auto-alt-text/2.1.0/code/src/App/AIProviders/OpenAI/OpenAIVision.php
- Raw: https://pluginprobe.com/plugins/auto-alt-text/2.1.0/raw/src/App/AIProviders/OpenAI/OpenAIVision.php
- Modified: 2024-06-11T22:08:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/auto-alt-text/2.1.0/code/src/App/AIProviders/OpenAI/OpenAIVision.php#L10-L20`.

```php
<?php

namespace AATXT\App\AIProviders\OpenAI;

use OpenAI;
use OpenAI\Client;
use OpenAI\Exceptions\ErrorException;
use AATXT\App\Exceptions\OpenAI\OpenAIException;
use AATXT\Config\Constants;

class OpenAIVision extends OpenAIResponse
{
    public static function make(): OpenAIVision
    {
        return new self();
    }

    /**
     *  Make a request to OpenAI Chat APIs to retrieve a description for the image passed
     * @param string $imageUrl
     * @return string
     * @throws OpenAIException
     */
    public function response(string $imageUrl): string
    {
        $prompt = parent::prompt();
        $requestBody = parent::prepareRequestBody(Constants::AATXT_OPENAI_VISION_MODEL, $prompt, $imageUrl);
        $decodedBody = parent::decodedResponseBody($requestBody, Constants::AATXT_OPENAI_CHAT_COMPLETION_ENDPOINT);
        return $this->cleanString($decodedBody['choices'][0]['message']['content']);
    }
}
```
