Support for legacy OpenAI chat APIs (-lib openai)
Completion
Model response for a given text or image query
Operations
- BuildCompleteRequest
- Complete
- GetChoices
- GetCreatedAt
- GetFirstChoice
- GetId
- GetModel
- GetObject
- ParseCompletion
- SetMaxCompletionTokens
- ToString
BuildCompleteRequest # function
Builds the JSON body POSTed to the chat completions endpoint. The output cap is sent as 'max_completion_tokens': 'max_tokens' is deprecated there and is rejected by reasoning (o-series) models. Public so the request can be checked offline.
function : BuildCompleteRequest(model:String, messages:Vector<Pair<String,String>>) ~ JsonElementParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| messages | Vector<Pair<String,String>> | role and text pairs |
Return
| Type | Description |
|---|---|
| JsonElement | request body |
Complete # function
Model response for the given query
function : Complete(model:String, message:Pair<String,String>, token:String) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| message | Pair<String,String> | completion message and image query. |
| token | String | API token |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Example
token := "sk-...";
msg := Pair->New("user", "What is the speed of light?")<String, String>;
result := Completion->Complete("gpt-4o-mini", msg, token);
choice := result->GetFirstChoice();
choice->GetMessage()->GetSecond()->PrintLine();Complete # function
Model response for the given query
function : Complete(model:String, message:Pair<String,String>, max_tokens:Int, temperature:Float, top_p:Float, token:String) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| message | Pair<String,String> | completion message and image query |
| max_tokens | Int | maximum number of completion tokens returned by the API |
| temperature | Float | amount of randomness in the response, valued between 0 inclusive and 2 exclusive |
| top_p | Float | nucleus sampling threshold, valued between 0 and 1 inclusive |
| token | String | API token |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given query
function : Complete(model:String, messages:Vector<Pair<String,String>>) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| messages | Vector<Pair<String,String>> | list of messages comprising the conversation |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given query
function : Complete(model:String, messages:Vector<Pair<String,String>>) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| messages | Vector<Pair<String,String>> | list of messages comprising the conversation |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given image and query
function : Complete(model:String, message:Pair<String,API.OpenAI.ImageQuery>, token:String) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| message | Pair<String,APIOpenAIImageQuery> | completion message and image query. |
| token | String | API token |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given image and query
function : Complete(model:String, message:Pair<String,API.OpenAI.ImageQuery>, max_tokens:Int, temperature:Float, top_p:Float, token:String) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| message | Pair<String,APIOpenAIImageQuery> | completion message and image query |
| max_tokens | Int | maximum number of completion tokens returned by the API |
| temperature | Float | amount of randomness in the response, valued between 0 inclusive and 2 exclusive |
| top_p | Float | nucleus sampling threshold, valued between 0 and 1 inclusive |
| token | String | API token |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given image and query
function : Complete(model:String, messages:Vector<Pair<String,API.OpenAI.ImageQuery>>) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| messages | Vector<Pair<String,APIOpenAIImageQuery>> | list of messages comprising the conversation |
Return
| Type | Description |
|---|---|
| Completion | completion response |
Complete # function
Model response for the given images and query
function : Complete(model:String, messages:Vector<Pair<String,API.OpenAI.ImageQuery>>) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| model | String | ID of the model to use |
| messages | Vector<Pair<String,APIOpenAIImageQuery>> | list of messages comprising the conversation |
Return
| Type | Description |
|---|---|
| Completion | completion response |
GetChoices #
List of chat completion choices
method : public : GetChoices() ~ Vector<API.OpenAI.Chat.Choice>Return
| Type | Description |
|---|---|
| Vector<APIOpenAIChatChoice> | completion choices |
Example
choices := result->GetChoices();
each(choice in choices) {
choice->GetMessage()->GetSecond()->PrintLine();
};GetCreatedAt #
Unix timestamp (in seconds) of when the object instance was created
method : public : GetCreatedAt() ~ IntReturn
| Type | Description |
|---|---|
| Int | time with the object instance was created |
GetFirstChoice #
List of chat completion choices
method : public : GetFirstChoice() ~ API.OpenAI.Chat.ChoiceReturn
| Type | Description |
|---|---|
| Choice | completion choices |
Example
choice := result->GetFirstChoice();
role := choice->GetMessage()->GetFirst();
text := choice->GetMessage()->GetSecond();
"{$role}: {$text}"->PrintLine();GetId #
Get object instance API ID
method : public : GetId() ~ StringReturn
| Type | Description |
|---|---|
| String | instance ID |
GetModel #
ID of the model to use
method : public : GetModel() ~ StringReturn
| Type | Description |
|---|---|
| String | ID of the model to use |
GetObject #
Get the object type
method : public : GetObject() ~ StringReturn
| Type | Description |
|---|---|
| String | object type |
ParseCompletion # function
Parses a chat completions response body
function : ParseCompletion(body:String) ~ CompletionParameters
| Name | Type | Description |
|---|---|---|
| body | String | response body |
Return
| Type | Description |
|---|---|
| Completion | completion, or Nil on an error body (see GetLastError) |
SetMaxCompletionTokens # function
Sets the chat completions output cap ('max_completion_tokens'); a negative value omits it.
function : SetMaxCompletionTokens() ~ NilParameters
| Name | Type | Description |
|---|---|---|