Sliding window

Prev Next

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

This section describes the request format. The method and URI are as follows:

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

Request headers

The following describes the request headers.

Field Required Description
Authorization Required API key for authentication <e.g.,> Bearer nv-************
X-NCP-CLOVASTUDIO-REQUEST-ID Optional Request ID
Content-Type Required Request data format
  • application/json

Request path parameters

You can use the following path parameters with your request:

Field Type Required Description
modelName String Required Model name
  • <e.g.> HCX-003

Request body

You can include the following data in the body of your request:

Field Type Required Description
maxTokens Integer Required Maximum number of generated tokens
  • 0 < maxTokens ≤ 4096 (default: 100)
  • messages Array Required Conversation message list
    • Need to be adjusted for maximum number of tokens
    messages.role Enum Required Role of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers to user utterances/questions
    messages.content String Required Content 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 request example is as follows:

    curl --location --request POST 'https://clovastudio.stream.ntruss.com/v1/api-tools/sliding/chat-messages/{modelName}' \
    --header 'Authorization: Bearer {API Key}' \
    --header 'X-NCP-CLOVASTUDIO-REQUEST-ID: {Request ID}' \
    --header 'Content-Type: application/json' \
    --data '{
          "maxTokens" : 200,
          "messages" : [ {
            "role" : "user",
            "content" : "hello"
          } ]
    }'
    

    Response

    This section describes the response format.

    Response body

    The following describes the body.

    Field Type Required Description
    result Object - Response result
    • Result of adjusting for the maximum number of tokens
    result.messages Array - Conversation message list
    result.messages.role Enum - Role of conversation messages
    • system | user | assistant
      • system: directives that define roles
      • user: user utterances/questions
      • assistant: answers to user utterances/questions
    result.messages.content String - Content of conversation messages

    Response example

    The response example is as follows:

    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.