- Print
- PDF
Training model Chat Completions
- Print
- PDF
Available in Classic and VPC
Conversational sentences are generated using the training model. If the desired conversational sentence is not generated, consider refining your dataset and retraining. Alternatively, edit the request parameter values and call again to adjust the results closer to your intended output.
Requests
Describes the request format. The request format is as follows:
Method | URI |
---|---|
POST | /v1/tasks/{taskId}/chat-completions |
Header
The following describes the header.
Header | Required | Description |
---|---|---|
X-NCP-CLOVASTUDIO-API-KEY | Y | API key issued when creating a test app or service app |
X-NCP-APIGW-API-KEY | Y | API Gateway key issued when creating a test app or service app |
X-NCP-CLOVASTUDIO-REQUEST-ID | N | Request ID for each request |
Content-Type | Y | application/json |
Accept | N | text/event-stream |
- The response result is returned in JSON format by default, but when
Accept
is specified astext/event-stream
, the response result is returned in a stream format. - When using the response stream, use
https://clovastudio.stream.ntruss.com/
for the API URL.
Path parameters
The following describes the parameters.
Field | Type | Required | Description |
---|---|---|---|
taskId | string | Y | Training ID |
Body
The following describes each field in the request body.
Field | Type | Required | Description |
---|---|---|---|
messages | array | Y | Conversation messages |
messages.role | enum | Y | Role of the conversational message |
messages.content | string | Y | Content of the conversation message |
temperature | double | N | Degree of diversity for generated tokens (a higher setting generates more diverse sentences) |
topK | int | N | Selects and samples the top k token candidates with the highest probabilities from the generated token pool |
topP | double | N | Sample the generated token candidate group based on cumulative probability |
repeatPenalty | double | N | The degree of penalty applied when generating the same token (a higher setting reduces the likelihood of repeatedly generating the same result) |
stopBefore | string | N | Character that halts token generation |
maxTokens | int | N | Maximum number of tokens generated |
The sum of the number of tokens entered in messages
and the number of tokens entered in maxTokens
cannot exceed 4096 tokens. You can verify the number of tokens entered in messages
using the Chat Completions tokenizer API. The specifications for the Chat Completions tokenizer API can be found on CLOVA Studio website.
Syntax
The following is an example of syntax.
curl --location --request POST 'https://clovastudio.stream.ntruss.com/testapp/v1/tasks/{taskId}/chat-completions' \
--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' \
--header 'Accept: text/event-stream' \
--data '{
"topK" : 0,
"includeAiFilters" : true,
"maxTokens" : 100,
"temperature" : 0.3,
"messages" : [ {
"role" : "user",
"content": "How's the weather today?"
}, {
"role" : "assistant",
"content": "It's the calm before the storm."
}, {
"role" : "user",
"content": "How about the weather tomorrow?"
} ],
"stopBefore" : [ ],
"repeatPenalty" : 1,
"topP" : 0.8
}'
Responses
Describes the responses format.
Header
The following describes the header.
Header | Required | Description |
---|---|---|
Content-Type | - | application/json |
Body
The following describes each field in the body.
Field | Type | Required | Description |
---|---|---|---|
result | - | - | Response result |
result.message | array | Y | Conversation messages |
result.message.role | enum | Y | Role of the conversational message |
result.message.content | string | Y | Content of the conversation message |
result.stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
result.inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing unit) |
result.outputLength | int | - | Number of response tokens |
aiFilter | array | - | AI Filter result |
aiFilter.groupName | string | Y | AI Filter category group name |
aiFilter.name | string | Y | Detailed AI Filter category name |
aiFilter.score | string | Y | AI Filter score |
The AI Filter can analyze up to 500 characters. However, if the text for analysis contains many unconventional formats, emojis, special characters, and so on, it might not be analyzed accurately.
Syntax
The following is an example of syntax.
{
"status": {
"code": "20000",
"message": "OK"
},
"result": {
"message": {
"role": "assistant",
"content": "phrase: reflect on your day, jotting down the events that transpired, and prepare for tomorrow. A diary will enrich your life further.\n"
},
"stopReason": "LENGTH",
"inputLength": 100,
"outputLength": 10,
"aiFilter": [
{
"groupName": "curse",
"name": "insult",
"score": "1"
},
{
"groupName": "curse",
"name": "discrimination",
"score": "0"
},
{
"groupName": "unsafeContents",
"name": "sexualHarassment",
"score": "2"
}
]
}
}
Response stream
You can use token streaming to display the generated tokens one by one. It describes the token streaming format.
Header
The following describes the header.
Header | Required | Description |
---|---|---|
Accept | - | text/event-stream |
Body
The following describes the body.
StreamingChatCompletionsResultEvent
The following describes StreamingChatCompletionsResultEvent.
Field | Type | Required | Description |
---|---|---|---|
message | array | - | Conversation messages |
message.role | enum | - | Role of the conversational message |
message.content | string | - | Content of the conversation message |
stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing unit) |
outputLength | int | - | Number of response tokens |
aiFilter | array | - | AI Filter result |
aiFilter.groupName | string | Y | AI Filter category group name |
aiFilter.name | string | Y | AI Filter category detailed name |
aiFilter.score | string | Y | AI Filter score |
StreamingChatCompletionsTokenEvent
The following describes StreamingChatCompletionsResultEvent.
Field | Type | Required | Description |
---|---|---|---|
id | string | - | Event ID that identifies the request |
message | array | - | Conversation messages |
message.role | enum | - | Role of the conversational message |
message.content | string | - | Content of the conversation message |
inputLength | int | - | Number of input tokens (inclusive of special tokens like end of turn for billing unit) |
stopReason | enum | - | Token generation termination reasons (typically passed in the last event) |
ErrorEvent
The following describes ErrorEvent.
Field | Type | Required | Description |
---|---|---|---|
status | status | - | Response status |
SignalEvent
The following describes SignalEvent.
Field | Type | Required | Description |
---|---|---|---|
data | string | - | Signal data information to be transmitted |
Syntax
The following is an example of syntax.
id: aabdfe-dfgwr-edf-hpqwd-f2asd-g
event: token
data: {"message": {"role": "assistant", "content": "an"}}
id: aabdfe-dfgwr-edf-hpqwd-f1asd-g
event: result
data: {"message": {"role": "assistant", "content": "nyeong"}}