getRequestOptions() ); } /** * {@inheritDoc} */ public function getRequestAuthentication(): RequestAuthenticationInterface { try { $core_auth = parent::getRequestAuthentication(); } catch ( \Exception $exception ) { $core_auth = null; } return AmazeeIoAiProvider::resolveRequestAuthentication( $core_auth ); } /** * {@inheritDoc} * * Drops parameters the selected model does not support, based on the * `supported_openai_params` list the amazee.ai endpoint reports per * model. Prevents API errors from e.g. sending `temperature` to a * model that rejects it. * * @param array $prompt Prompt parts to generate text for. */ protected function prepareGenerateTextParams( array $prompt ): array { $params = parent::prepareGenerateTextParams( $prompt ); $supported = AmazeeIoModelDirectory::getSupportedApiParams( $this->metadata()->getId() ); if ( null === $supported ) { return $params; } foreach ( array_keys( $params ) as $key ) { if ( ! in_array( $key, self::ESSENTIAL_PARAMS, true ) && ! in_array( $key, $supported, true ) ) { unset( $params[ $key ] ); } } return $params; } /** * {@inheritDoc} * * Maps amazee.ai budget errors to an actionable message. * * @param Response $response HTTP response to check. * @throws ClientException If the amazee.ai budget has been exceeded. */ protected function throwIfNotSuccessful( Response $response ): void { AmazeeIoAiProvider::throwOnBudgetError( $response ); parent::throwIfNotSuccessful( $response ); } /** * {@inheritDoc} * * @param array|null $output_schema JSON schema for the expected output, if any. */ protected function prepareResponseFormatParam( ?array $output_schema ): array { if ( null === $output_schema ) { return array( 'type' => 'json_object' ); } return array( 'type' => 'json_schema', 'json_schema' => array( 'name' => 'outputSchema', 'schema' => $output_schema, ), ); } }