# auto-alt-text/2.1.0/src/App/AIProviders/OpenAI/Fallback.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/Fallback.php
- Raw: https://pluginprobe.com/plugins/auto-alt-text/2.1.0/raw/src/App/AIProviders/OpenAI/Fallback.php
- Modified: 2024-06-11T22:12:12+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/Fallback.php#L10-L20`.

```php
<?php
namespace AATXT\App\AIProviders\OpenAI;

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

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

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