TsgcHTTP_API_OpenAI › Methods › CreateCompletion
Calls the legacy OpenAI Completions endpoint for prompt-based text generation
function CreateCompletion(const aRequest : TsgcOpenAIClass_Request_Completion) : TsgcOpenAIClass_Response_Completion;
| Name | Type | Description |
|---|---|---|
aRequest | const TsgcOpenAIClass_Request_Completion | Request payload holding the model name, prompt, max tokens, temperature and other completion parameters. |
Parsed response object containing the generated choices, finish reasons and token usage. (TsgcOpenAIClass_Response_Completion)
Issues a POST to the legacy /v1/completions endpoint, which accepts a single prompt (or list of prompts) and returns one or more completion choices. This API is maintained for compatibility with instruct-style models such as gpt-3.5-turbo-instruct; for modern conversational workloads prefer CreateChatCompletion or CreateResponse. Streaming is supported by setting aRequest.Stream := True and handling OnHTTPAPISSE.
oRequest := TsgcOpenAIClass_Request_Completion.Create;
try
oRequest.Model := 'gpt-3.5-turbo-instruct';
oRequest.Prompt := 'Translate to French: Hello, how are you?';
oRequest.MaxTokens := 64;
oResponse := oAPI.CreateCompletion(oRequest);
ShowMessage(oResponse.Choices[0].Text);
finally
oRequest.Free;
end;