wppaste
WordPress

AbstractOpenAiCompatibleModelMetadataDirectory

Since
0.1.0
Source
wp-includes/php-ai-client/src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleModelMetadataDirectory.php:22
Base class for a model metadata directory for providers that implement OpenAI's API format.

Description

This abstract class is designed to work with any AI provider that offers an OpenAI-compatible models listing endpoint, including but not limited to Anthropic, Google, and other providers that have adopted OpenAI's models API specification as a standard interface.

Compatibility

WordPress
since 0.1.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in 2 of the 5 tracked releases, added in 0.1.0.

Methods · 4

Source code

abstract class AbstractOpenAiCompatibleModelMetadataDirectory extends AbstractApiBasedModelMetadataDirectory{    /**     * {@inheritDoc}     *     * @since 0.1.0     */    protected function sendListModelsRequest(): array    {        $httpTransporter = $this->getHttpTransporter();        $request = $this->createRequest(HttpMethodEnum::GET(), 'models');        $request = $this->getRequestAuthentication()->authenticateRequest($request);        $response = $httpTransporter->send($request);        $this->throwIfNotSuccessful($response);        $modelsMetadataList = $this->parseResponseToModelMetadataList($response);        $modelMetadataMap = [];        foreach ($modelsMetadataList as $modelMetadata) {            $modelMetadataMap[$modelMetadata->getId()] = $modelMetadata;        }        return $modelMetadataMap;    }    /**     * Creates a request object for the provider's API.     *     * @since 0.1.0     *     * @param HttpMethodEnum $method The HTTP method.     * @param string $path The API endpoint path, relative to the base URI.     * @param array<string, string|list<string>> $headers The request headers.     * @param string|array<string, mixed>|null $data The request data.     * @return Request The request object.     */    abstract protected function createRequest(HttpMethodEnum $method, string $path, array $headers = [], $data = null): Request;    /**     * Throws an exception if the response is not successful.     *     * @since 0.1.0     *     * @param Response $response The HTTP response to check.     * @throws ResponseException If the response is not successful.     */    protected function throwIfNotSuccessful(Response $response): void    {        /*         * While this method only calls the utility method, it's important to have it here as a protected method so         * that child classes can override it if needed.         */        ResponseUtil::throwIfNotSuccessful($response);    }    /**     * Parses the response from the API endpoint to list models into a list of model metadata objects.     *     * @since 0.1.0     *     * @param Response $response The response from the API endpoint to list models.     * @return list<ModelMetadata> List of model metadata objects.     */    abstract protected function parseResponseToModelMetadataList(Response $response): array;}

Changelog

Introduced in 0.1.0. Unchanged from 7.0.4 through 7.1.0.

  1. 7.0.4
  2. 7.1.0

Signature, return type and hooks compared across 2 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/php-ai-client/src/Providers/OpenAiCompatibleImplementation/AbstractOpenAiCompatibleModelMetadataDirectory.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.