Understanding the Response

Understanding the Response

When you send a request to Konko's API, the response you receive is structured in a specific way. Let's delve into this response format and understand each part of it.

ChatCompletion Object

The ChatCompletion object represents the response returned by the model, based on the provided input. The main components of this object include:

  • id: A unique identifier for the chat completion.
  • object: Always set to chat.completion, indicating the object type.
  • created: A unix timestamp representing when the chat completion was created.
  • model: The specific model that was used for generating the chat completion.
  • choices: An array containing chat completion choices. There might be more than one choice if the n parameter is set to a value greater than 1. Each choice in this array includes:
    • index: The position of the choice in the array.
    • message: The content of the message generated by the model, including the role (e.g., "assistant") and content (the actual text response).
    • finish_reason: The reason the model ceased generating tokens. This could be:
      • stop: The model reached a natural endpoint or a specified stop sequence.
      • length: The max number of tokens specified in the request was met.
      • function_call: The model decided to execute a function.
      • content_filter: Content was omitted due to a flag from content filters.
      • null: The response is still ongoing or incomplete.
  • usage: Provides statistics about the request:
    • prompt_tokens: The number of tokens in the original prompt.
    • completion_tokens: The number of tokens in the model-generated completion.
    • total_tokens: The combined number of tokens used in the request.

To extract the assistant's reply from a ChatCompletion response in Python, you can use:
response.choices[0].message.content.

Example Response

ChatCompletion(
  id='014c221a-b3fa-478f-aebc-c07af842ae43',
  choices=[
    Choice(
      finish_reason=None,
      index=0,
      logprobs=None,
      message=ChatCompletionMessage(
        content=" The Foundation is a science fiction novel by Isaac Asimov that follows the story of a mathematician named Hari Seldon who predicts the fall of the Galactic Empire and the rise of a new empire called the Second Foundation. The novel explores the concept of psychohistory, a mathematical science that can predict the behavior of large groups of people, and the idea that individual actions can have unintended consequences. The story follows a group of characters who are tasked with saving the Second Foundation from destruction and uncovering the truth behind Hari Seldon's predictions.",
        role='assistant',
        function_call=None,
        tool_calls=None
      )
    )
  ],
  created=1704902334,
  model='mistralai/mistral-7b-instruct-v0.1',
  object='chat.completion',
  system_fingerprint=None,
  usage=None
)


Whatโ€™s Next