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.

    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 headers.

    HeaderRequiredDescription
    X-NCP-CLOVASTUDIO-API-KEYYAPI key issued when viewing code
    X-NCP-APIGW-API-KEYYAPI Gateway key issued when viewing code
    X-NCP-CLOVASTUDIO-REQUEST-IDNRequest ID for each request
    Content-TypeYapplication/json

    Request path parameters

    The following describes the parameters.

    FieldTypeRequiredDescription
    modelNamestringYName of the model to use <E.g.> HCX-003

    Request body

    The following describes the body.

    FieldTypeRequiredDescription
    messagesarray[ChatMessage]YList of conversation messages (target to be adjusted for maximum number of tokens)
    ChatMessage.roleenumYRole of conversation messages
  • system: directives that define roles (not deleted)
  • user: user utterances/questions
  • assistant: answers to user utterances/questions
  • ChatMessage.contentstringYConversation message content
    maxTokensintYMaximum number of generated tokens (adjusted so that the sum of the number of tokens entered in messages and the number of tokens entered in maxTokens does not exceed 4096 tokens, the maximum number of tokens)

    Request syntax

    The following is a sample syntax.

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

    Response

    The following describes the response format.

    Response body

    The following describes the body.

    FieldTypeRequiredDescription
    resultresult-Response result (adjusted for maximum number of tokens)
    result.roleenum-Role of conversation messages
  • system: directives that define roles (not deleted)
  • user: user utterances/questions
  • assistant: answers to user utterances/questions
  • result.contentstring-Conversation message content

    Response syntax

    The following is a sample syntax.

    Success

    The following is a sample syntax upon a successful call.

    {
        "status": {
            "code": "20000",
            "message": "OK"
        },
        "result": {
            "messages": [
                {
                    "role": "user",
                    "content": "hello"
                }
            ]
        }
    }
    

    Failure

    The following is a sample syntax 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.