class AbstractApiBasedModel {}

In this article

Base class for an API-based model for a provider.

Description

While this class contains no abstract methods, it is still abstract to ensure that each model class can actually perform generative AI tasks by implementing the corresponding interfaces.

Methods

NameDescription
AbstractApiBasedModel::__constructConstructor.
AbstractApiBasedModel::getConfig{@inheritDoc}
AbstractApiBasedModel::getRequestOptions{@inheritDoc}
AbstractApiBasedModel::metadata{@inheritDoc}
AbstractApiBasedModel::providerMetadata{@inheritDoc}
AbstractApiBasedModel::setConfig{@inheritDoc}
AbstractApiBasedModel::setRequestOptions{@inheritDoc}

Source

abstract class AbstractApiBasedModel implements ApiBasedModelInterface, WithHttpTransporterInterface, WithRequestAuthenticationInterface
{
    use WithHttpTransporterTrait;
    use WithRequestAuthenticationTrait;
    /**
     * @var ModelMetadata The metadata for the model.
     */
    private ModelMetadata $metadata;
    /**
     * @var ProviderMetadata The metadata for the model's provider.
     */
    private ProviderMetadata $providerMetadata;
    /**
     * @var ModelConfig The configuration for the model.
     */
    private ModelConfig $config;
    /**
     * @var RequestOptions|null The request options for HTTP transport.
     */
    private ?RequestOptions $requestOptions = null;
    /**
     * Constructor.
     *
     * @since 0.1.0
     *
     * @param ModelMetadata $metadata The metadata for the model.
     * @param ProviderMetadata $providerMetadata The metadata for the model's provider.
     */
    public function __construct(ModelMetadata $metadata, ProviderMetadata $providerMetadata)
    {
        $this->metadata = $metadata;
        $this->providerMetadata = $providerMetadata;
        $this->config = ModelConfig::fromArray([]);
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.1.0
     */
    final public function metadata(): ModelMetadata
    {
        return $this->metadata;
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.1.0
     */
    final public function providerMetadata(): ProviderMetadata
    {
        return $this->providerMetadata;
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.1.0
     */
    final public function setConfig(ModelConfig $config): void
    {
        $this->config = $config;
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.1.0
     */
    final public function getConfig(): ModelConfig
    {
        return $this->config;
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.3.0
     */
    final public function setRequestOptions(RequestOptions $requestOptions): void
    {
        $this->requestOptions = $requestOptions;
    }
    /**
     * {@inheritDoc}
     *
     * @since 0.3.0
     */
    final public function getRequestOptions(): ?RequestOptions
    {
        return $this->requestOptions;
    }
}

Changelog

VersionDescription
0.1.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.