$prompt The prompt to generate text for. * @return array The parameters for the API request. */ protected function prepareGenerateTextParams(array $prompt): array { $params = parent::prepareGenerateTextParams($prompt); /* * An empty array signals "send no response_format" (see prepareResponseFormatParam()); leaving * the key in place would send `"response_format": []`, which is a 400. */ if (isset($params['response_format']) && $params['response_format'] === []) { unset($params['response_format']); } if (CommandCodeModelCatalog::rejectsSamplingParameters($this->metadata()->getId())) { // These families return a 400 when a non-default sampling value is sent. unset( $params['temperature'], $params['top_p'], $params['presence_penalty'], $params['frequency_penalty'], $params['logprobs'], $params['top_logprobs'] ); } return $params; } /** * {@inheritDoc} * * Fixes the request shape for structured output, which the SDK base class gets wrong. * * The base class sends `{"type":"json_schema","json_schema":}`, but the OpenAI API — and * therefore the Command Code gateway — expects the schema wrapped in a named object: * `{"type":"json_schema","json_schema":{"name":...,"schema":{...}}}`. Without the wrapper the * gateway answers `400 invalid_request_error, param: response_format`, which is what the AI * plugin's Editorial Notes feature (an `as_json_response()` call) was hitting. * * @param array|null $outputSchema The output schema, or null for plain JSON mode. * @return array The response format parameter, or an empty array to send none. */ protected function prepareResponseFormatParam(?array $outputSchema): array { $mode = CommandCodeConfig::getStructuredOutputMode(); if ($mode === 'none') { return []; } if ($mode === 'json_object' || !is_array($outputSchema)) { return ['type' => 'json_object']; } return [ 'type' => 'json_schema', 'json_schema' => [ 'name' => 'command_code_response', 'schema' => $outputSchema, ], ]; } }