Completions
    • PDF

    Completions

    • PDF

    Article summary

    Available in Classic and VPC

    Generate conversational sentences utilizing the normal mode (LK model) of Playground.

    Request

    The following describes the request format for the endpoint. The request format is as follows:

    MethodURI
    POST
    • /v1/chat-completions/{modelName}
      • When generating sentences using the model
    • /v1/tasks/{taskId}/chat-completions
      • When generating sentences using tuning trained jobs

    Request headers

    The following describes the request headers.

    HeadersRequiredDescription
    X-NCP-CLOVASTUDIO-API-KEYRequiredAPI key issued when creating the test app or service app
    X-NCP-APIGW-API-KEYRequiredAPI Gateway key issued when creating the test app or service app
    X-NCP-CLOVASTUDIO-REQUEST-IDOptionalRequest ID for the request
    Content-TypeRequiredRequest data format
    • application/json

    Request path parameters

    The following describes the request path parameters.

    FieldTypeRequiredDescription
    modelStringConditionalModel name
    • When using a model to generate sentences
    • <e.g.> LK-D2
    taskIdStringConditionalTraining ID
    • When using tuning trained job to generate sentences
    • Can be checked in the response body of the Create training API

    Request body

    The following describes the request body.

    FieldTypeRequiredDescription
    textStringRequiredUser input (prompt)
    • New sentence is generated based on this prompt
    topKIntegerOptionalSample K high-probability candidates from the pool of generated token candidates
  • 0 ≤ topK ≤ 128 (default: 0)
  • topPFloatOptionalSample generated token candidates based on cumulative probability
    • 0.00 < topP ≤ 1.00 (default: 0.80)
      • Display to two decimal places
    repeatPenaltyFloatOptionalDegree of penalty for generating the same token (the higher the setting, the less likely it is to generate the same result repeatedly)
  • 0.0 < repeatPenalty ≤ 10.0 (default: 5.0)
  • stopBeforeArrayOptionalCharacter to abort token generation
  • [] (default)
  • restartStringOptionalText to be attached behind the generated result value
    startStringOptionalText to be attached behind the user input value
    maxTokensIntegerOptionalMaximum number of generated tokens
  • 0 < maxTokens ≤ 2048 (default: 100)
  • includeTokensBooleanOptionalWhether input_tokens and output_tokens will be included in the response
    • false | true (default)
      • false: do not include
      • true: include
    temperatureFloatOptionalDegree of diversity for the generated tokens (higher values generate more diverse sentences)
    • 0.00 < temperature ≤ 1.00 (default: 0.50)
      • Display to two decimal places
    includeAiFiltersBooleanOptionalWhether to display the AI Filter results (degree of the generated results in categories such as profanity, degradation/discrimination/hate, sexual harassment/obscenity, etc.)
    • false (default) | true
      • false: not display
      • true: display
    Note

    When entering some fields, check the following.

    • text: The sum of the number of tokens entered and the number of tokens entered in maxTokens can't exceed 2048 tokens.

    Request example

    The following is a sample request.

    curl --location --request POST 'https://clovastudio.apigw.ntruss.com/testapp/v1/completions/LK-D2' \
    --header 'X-NCP-CLOVASTUDIO-API-KEY: {CLOVA Studio API Key}' \
    --header 'X-NCP-APIGW-API-KEY: {API Gateway API Key}' \
    --header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {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 response headers.

    HeadersRequiredDescription
    Content-Type-Response data format
    • application/json

    Response body

    The following describes the response body.

    FieldTypeRequiredDescription
    statusObject-Response status
    resultObject-Response result
    result.textString-Generated token (prompt and generated result value)
    result.stopReasonString-Reason for stopping results generation
    • length | end_token | stop_before
      • length: length limit
      • end_token: token count limit
      • stop_before: character specified in stopBefore occurred during answer generation
    result.startLengthInteger-Input token count
    inputTextString-User input value (prompt)
    result.inputLengthInteger-Number of input tokens (including special tokens such as END OF TURN based on billing)
    result.inputTokensArray-Entered token information
    result.outputTextInteger-Generated result value
    result.outputLengthInteger-Generated token count
    result.outputTokensArray-Generated token information
    result.probsArray-Candidate tokens for response tokens and probability values for candidate tokens
    result.okBoolean-Whether response was successful
    • false | true
      • false: Response failed. An error message is returned
      • true: Response successful
    aiFilterArray-AI Filter result

    aiFilter

    The following describes aiFilter.

    FieldTypeRequiredDescription
    groupNameString-AI Filter category
    • curse | unsafeContents
      • curse: degradation, discrimination, hate, and profanity
      • unsafeContents: sexual harassment, obscenity
    nameString-AI Filter subcategory
    • discrimination | insult | sexualHarassment
      • discrimination: degradation, discrimination, hate
      • insult: profanity
      • sexualHarassment: sexual harassment, obscenity
    scoreString-AI Filter score
    • -1 | 0 | 1 | 2
      • -1: AI Filter error occurred
      • 0: Conversation messages are more likely to contain sensitive/hazardous language
      • 1: Conversation messages are likely to contain sensitive/hazardous language
      • 2: Conversation messages are unlikely to contain sensitive/hazardous language
    resultString-Whether AI Filter is operating properly
    • OK | ERROR
      • OK: normal operation
      • ERROR: error occurred
    Note

    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 example

    The following is a sample example.

    Succeeded

    The following is a sample response 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 response upon a failed call.


    Was this article helpful?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.