- Print
- PDF
Completions
- Print
- PDF
Available in Classic and VPC
This is a guide to the Completions API available through the normal mode (LK model) of the Playground.
Request
The following describes the request format for the endpoint. The request format is as follows:
Method | URI |
---|---|
POST | /v1/completions/{model} |
When using a task that has been tuning trained, it should be called in the form /v1/tasks/{taskId}/completions
. You can check the taskID
required for calling in the response body of Create training API.
Request headers
The following describes the headers.
Headers | Required | Description |
---|---|---|
X-NCP-CLOVASTUDIO-API-KEY | Y | API key issued when creating the test app or service app |
X-NCP-APIGW-API-KEY | Y | API Gateway key issued when creating the test app or service app |
X-NCP-CLOVASTUDIO-REQUEST-ID | N | Request ID for each request |
Content-Type | Y | application/json |
Request path parameters
The following describes the parameters.
Field | Type | Required | Description |
---|---|---|---|
model | string | Y | Model name to use (e.g., LK-D2) |
The following describes the parameters for a task that has been tuning trained.
Field | Type | Required | Description |
---|---|---|---|
taskId | string | Y | Training ID |
You can check the taskID
required for calling in the response body of Create training API.
Request body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
text | string | Y | User input (prompt); new sentence is generated based on this text |
topK | int | N | Top K value; List tokens in order of increasing probability and use only those tokens that are in the range of the top K |
topP | float | N | Top P value; Select tokens with top P in the range of cumulative probability values as candidates |
repeatPenalty | float | N | Penalty value for tokens with repeated expressions |
stopBefore | array | N | Character to abort token generation |
start | string | N | Text to be attached behind the user input value |
restart | string | N | Text to be attached behind the output value |
maxTokens | int | N | Maximum number of tokens to be used when generating the result value |
includeTokens | boolean | N | Whether input_tokens and output_tokens will be included in the response |
temperature | float | N | The randomness of the results; the higher the value, the more likely it is that random results will be generated |
includeAiFilters | boolean | N | Degree of the generated results in categories such as profanity, degradation/discrimination/hate, sexual harassment/obscenity, etc. |
When entering some fields, check the following.
- The sum of the number of tokens entered in text and the number of tokens entered in maxTokens cannot exceed 2048 tokens.
- The number of tokens entered in the text can be checked in CLOVA Studio web by calling the Token Calculator API in the Explorer > Tools tab menu.
- topP, temperature: Display to two decimal places.
Request syntax
The following is a sample syntax.
curl --location --request POST 'https://clovastudio.apigw.ntruss.com/testapp/v1/completions/LK-D2' \
--header 'X-NCP-CLOVASTUDIO-API-KEY: <X-NCP-CLOVASTUDIO-API-KEY>' \
--header 'X-NCP-APIGW-API-KEY: <X-NCP-APIGW-API-KEY>' \
--header 'X-NCP-CLOVASTUDIO-REQUEST-ID: <X-NCP-CLOVASTUDIO-REQUEST-ID>' \
--header 'Content-Type: application/json' \
--data '{
"start": "\nEnglish: ",
"stopBefore": ["\nKorean: "],
"text": "Korean: 사과\nEnglish: Apple\nKorean: 바나나",
"includeAiFilters": true
}'
Response
The following describes the response format.
Response headers
The following describes the headers.
Headers | Required | Description |
---|---|---|
Content-Type | - | application/json |
Response body
The following describes the body.
Field | Type | Required | Description |
---|---|---|---|
text | string | - | Created token. It includes both the prompt and result value |
stopReason | string | - | Reason for stopping results generation
|
inputLength | integer | - | Number of tokens input |
inputTokens | string array | - | Entered token information |
outputLength | integer | - | Number of response tokens |
outputTokens | string array | - | Generated token information |
probs | float | - | Probability of each created token being selected |
aiFilter | array | - | AI Filter result |
aiFilter.groupName | string | - | AI Filter category group name |
aiFilter.name | string | - | AI Filter category detailed name |
aiFilter.score | string | - | AI Filter score |
aiFilter.result | string | - | Whether AI Filter is operating properly |
AI Filter can analyze up to 500 characters. However, if the text being analyzed contains many unusual formats, emojis, or special characters, it may not be analyzed correctly.
Response syntax
The following is a sample syntax.
Succeeded
The following is a sample syntax upon a successful call.
{
"status": {
"code": "20000",
"message": "OK"
},
"result": {
"text": "Write emotional marketing copy\n\nProduct: lotion\nText: Moisturizes as soon as it touches your skin\n###\nProduct: planner\nText: a gift I give to myself",
"stopReason": "end_token",
"startLength": 33,
"inputText": "Write emotional marketing copy\n\nProduct: lotion\nText: Moisturizes as soon as it touches your skin\n###\nProduct: planner",
"inputLength": 33,
"inputTokens": ["Wr", "ite", " emo", "tion", "al", " market","ing", " copy", "\n",
"\n", "Product", ":", " lotion", "\n", "Text", ":"," Moisturizes", " as", " soon", " as", " it", " touches", " your skin"
"\n", "##", "#", "\n", "Product", ":", " planner", "\n", "Text", ":"
],
"outputText": "\nText: a gift I give to myself",
"outputLength": 7,
"outputTokens": ["a", "gift", "I", "give", "to", "myself",""
],
"probs": [],
"ok": true,
"aiFilter": [
{
"groupName": "curse",
"name": "insult",
"score": "2"
},
{
"groupName": "curse",
"name": "discrimination",
"score": "1"
},
{
"groupName": "unsafeContents",
"name": "sexualHarassment",
"score": "2"
}
]
}
}
Failure
The following is a sample syntax upon a failed call.