TsgcHTTP_API_OpenAIMethods › CreateEdit

CreateEdit Method

Calls the OpenAI Edits endpoint to apply an instruction-based edit to an input text

Syntax

function CreateEdit(const aRequest: TsgcOpenAIClass_Request_Edit) : TsgcOpenAIClass_Response_Edit;

Parameters

NameTypeDescription
aRequestconst TsgcOpenAIClass_Request_EditRequest payload with the model, the original input text and the instruction describing the edit to apply.

Return Value

Parsed response object exposing the edited text choices and token usage. (TsgcOpenAIClass_Response_Edit)

Remarks

Issues a POST to the legacy /v1/edits endpoint, which takes an existing piece of text plus an instruction and returns the rewritten result. Use it with the text-davinci-edit-001 and code-davinci-edit-001 models for spelling, grammar or style corrections. Note that this endpoint has been deprecated by OpenAI in favour of Chat Completions; it is exposed here for backward compatibility with older integrations.

Example

oRequest := TsgcOpenAIClass_Request_Edit.Create;
try
  oRequest.Model := 'text-davinci-edit-001';
  oRequest.Input := 'What day of the wek is it?';
  oRequest.Instruction := 'Fix the spelling mistakes';
  oResponse := oAPI.CreateEdit(oRequest);
  ShowMessage(oResponse.Choices[0].Text);
finally
  oRequest.Free;
end;

Back to Methods