openai/src/98e59bdf-81a2-41ef-a3a6-6a8.../code.power

58 lines
1.3 KiB
Plaintext

/**
* Create a new edit using OpenAI Edit API.
* API Ref: https://platform.openai.com/docs/api-reference/edits
*
* @param string $model The model to use.
* @param string $instruction The instruction for the edit.
* @param string|null $input The input text (optional).
* @param int|null $n How many edits to generate (optional).
* @param float|null $temperature The sampling temperature (optional).
* @param float|null $topP Nucleus sampling parameter (optional).
*
* @return object|null
* @since 3.2.0
**/
public function create(
string $model,
string $instruction,
?string $input = null,
?int $n = null,
?float $temperature = null,
?float $topP = null
): ?object
{
// Build the request path.
$path = "/edits";
// Set the data.
$data = new \stdClass();
$data->model = $model;
$data->instruction = $instruction;
if ($input !== null)
{
$data->input = $input;
}
if ($n !== null)
{
$data->n = $n;
}
if ($temperature !== null)
{
$data->temperature = $temperature;
}
if ($topP !== null)
{
$data->top_p = $topP;
}
// Send the post request.
return $this->response->get(
$this->http->post(
$this->uri->get($path), json_encode($data)
)
);
}