Sliding window
    • PDF

    Sliding window

    • PDF

    Article summary

    Available in Classic and VPC

    Delete sentences that exceed the maximum number of tokens when using Chat completions API. The oldest conversation turns are deleted to free up tokens so that conversations can be created without interruption.

    Note

    For a detailed description of how the sliding window works and how to work with it, see Utilize API of the CLOVA Studio user guide.

    Request

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

    MethodURI
    POST/v1/api-tools/sliding/chat-messages/{modelName}

    Request headers

    The following describes the request headers.

    FieldRequiredDescription
    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
    Content-TypeRequiredRequest data format
    • application/json

    Request path parameters

    The following describes the request path parameters.

    FieldTypeRequiredDescription
    modelNameStringRequiredModel name
    • <e.g.> HCX-003

    Request body

    The following describes the request body.

    FieldTypeRequiredDescription
    maxTokensIntegerRequiredMaximum number of generated tokens
  • 0 < maxTokens ≤ 4096 (default: 100)
  • messagesArrayRequiredConversation message list
    • Need to be adjusted for maximum number of tokens
    messages.roleEnumRequiredRole of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers to user utterances/questions
    messages.contentStringRequiredContent of conversation messages
    Note

    When entering some fields, check the following.

  • `messages`: The sum of the number of tokens entered and the number of tokens entered in `maxTokens` can't exceed 4096 tokens. The number of tokens entered in `messages` can be checked by calling the Token calculation API.
  • Request example

    The following is a sample request.

    curl --location --request POST 'https://clovastudio.apigw.ntruss.com/v1/api-tools/sliding/chat-messages/{modelName}' \
    --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 '{
          "maxTokens" : 200,
          "messages" : [ {
            "role" : "user",
            "content" : "hello"
          } ]
    }'
    

    Response

    The following describes the response format.

    Response body

    The following describes the body.

    FieldTypeRequiredDescription
    resultObject-Response result
    • Result of adjusting for the maximum number of tokens
    result.messagesArray-Conversation message list
    result.messages.roleEnum-Role of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers to user utterances/questions
    result.messages.contentString-Content of conversation messages

    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": {
            "messages": [
                {
                    "role": "user",
                    "content": "hello"
                }
            ]
        }
    }
    

    Failure

    The following is a sample response upon a failed call.


    Was this article helpful?

    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.