|null $output_schema The output schema. * @return array The prepared response format parameter. */ protected function prepareResponseFormatParam( ?array $output_schema ): array { if ( is_array( $output_schema ) ) { return array( 'type' => 'json_schema', 'json_schema' => array( 'name' => 'response_schema', 'schema' => $output_schema, ), ); } return array( 'type' => 'json_object', ); } /** * {@inheritDoc} * * @since 1.0.0 */ protected function createRequest( HttpMethodEnum $method, string $path, array $headers = array(), $data = null ): Request { $request_options = $this->prepareRequestOptionsForTextGeneration(); // Keep transport-only timeout options out of the OpenAI-compatible payload. if ( is_array( $data ) ) { unset( $data['ollama.request_timeout'], $data['ollama.connect_timeout'] ); } // Ollama supports OpenAI-compatible endpoints at /v1/. $path = ltrim( (string) preg_replace( '#^v1/?#', '', ltrim( $path, '/' ) ), '/' ); $path = '/v1/' . $path; return new Request( $method, OllamaProvider::url( $path ), $headers, $data, $request_options ); } /** * Prepares request options for text generation with a longer default timeout. * * Supported custom options: * - ollama.request_timeout (seconds) * - ollama.connect_timeout (seconds) * * @since 1.1.0 * * @return \WordPress\AiClient\Providers\Http\DTO\RequestOptions Prepared request options. */ private function prepareRequestOptionsForTextGeneration(): RequestOptions { return $this->prepareRequestOptions( 60.0, 10.0 ); } }