Completions
    • PDF

    Completions

    • PDF

    Article summary

    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:

    MethodURI
    POST/v1/completions/{model}
    Note

    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.

    HeadersRequiredDescription
    X-NCP-CLOVASTUDIO-API-KEYYAPI key issued when creating the test app or service app
    X-NCP-APIGW-API-KEYYAPI Gateway key issued when creating the test app or service app
    X-NCP-CLOVASTUDIO-REQUEST-IDNRequest ID for each request
    Content-TypeYapplication/json

    Request path parameters

    The following describes the parameters.

    FieldTypeRequiredDescription
    modelstringYModel name to use (e.g., LK-D2)

    The following describes the parameters for a task that has been tuning trained.

    FieldTypeRequiredDescription
    taskIdstringYTraining ID
    Note

    You can check the taskID required for calling in the response body of Create training API.

    Request body

    The following describes the body.

    FieldTypeRequiredDescription
    textstringYUser input (prompt); new sentence is generated based on this text
    topKintNTop K value; List tokens in order of increasing probability and use only those tokens that are in the range of the top K
  • 0 ≤ topk ≤ 128 (default: 0)
  • topPfloatNTop P value; Select tokens with top P in the range of cumulative probability values as candidates
  • 0.00 < topP ≤ 1.00 (default: 0.80)
  • repeatPenaltyfloatNPenalty value for tokens with repeated expressions
  • 0.0 < repeatPenalty ≤ 10.0 (default: 5.0)
  • stopBeforearrayNCharacter to abort token generation
  • [] (default)
  • startstringNText to be attached behind the user input value
    restartstringNText to be attached behind the output value
    maxTokensintNMaximum number of tokens to be used when generating the result value
  • 0 < maxTokens ≤ 2048 (default: 100)
  • includeTokensbooleanNWhether input_tokens and output_tokens will be included in the response
  • false: do not include
  • true: include (default)
  • temperaturefloatNThe randomness of the results; the higher the value, the more likely it is that random results will be generated
  • 0.00 < temperature ≤ 1.00 (default: 0.50)
  • includeAiFiltersbooleanNDegree of the generated results in categories such as profanity, degradation/discrimination/hate, sexual harassment/obscenity, etc.
  • false (default)
  • true
  • Note

    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.

    HeadersRequiredDescription
    Content-Type-application/json

    Response body

    The following describes the body.

    FieldTypeRequiredDescription
    textstring-Created token. It includes both the prompt and result value
    stopReasonstring-Reason for stopping results generation
    • length: reached the maximum length set
    • end_token: reached the maximum number of tokens available
    • stop_before: reached the set stop sequence
    inputLengthinteger-Number of tokens input
    inputTokensstring array-Entered token information
    outputLengthinteger-Number of response tokens
    outputTokensstring array-Generated token information
    probsfloat-Probability of each created token being selected
    aiFilterarray-AI Filter result
    aiFilter.groupNamestring-AI Filter category group name
  • curse
  • unsafeContents
  • aiFilter.namestring-AI Filter category detailed name
  • discrimination: degradation, discrimination, hate (curse)
  • insult: profanity (curse)
  • sexualHarassment: sexual harassment, obscenity (unsafeContents)
  • aiFilter.scorestring-AI Filter score
  • 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
  • -1: AI Filter error occurred
  • aiFilter.resultstring-Whether AI Filter is operating properly
  • 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 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.


    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.