gloq/response

Types

An error response from the GroqCloud API.

pub type ApiError {
  ApiError(
    message: String,
    error_type: String,
    code: option.Option(String),
  )
}

Constructors

  • ApiError(
      message: String,
      error_type: String,
      code: option.Option(String),
    )

A full chat completion response from the GroqCloud API.

pub type ChatCompletion {
  ChatCompletion(
    id: String,
    model: String,
    choices: List(Choice),
    usage: Usage,
  )
}

Constructors

  • ChatCompletion(
      id: String,
      model: String,
      choices: List(Choice),
      usage: Usage,
    )

A single completion choice. Most requests return exactly one choice.

pub type Choice {
  Choice(
    index: Int,
    message: ResponseMessage,
    finish_reason: option.Option(String),
  )
}

Constructors

The assistant message returned in a completion choice.

pub type ResponseMessage {
  ResponseMessage(role: String, content: String)
}

Constructors

  • ResponseMessage(role: String, content: String)

Token usage statistics returned with every completion.

pub type Usage {
  Usage(
    prompt_tokens: Int,
    completion_tokens: Int,
    total_tokens: Int,
  )
}

Constructors

  • Usage(
      prompt_tokens: Int,
      completion_tokens: Int,
      total_tokens: Int,
    )

Values

pub fn all_contents(completion: ChatCompletion) -> List(String)

Extract text content from all choices in a completion.

pub fn content(completion: ChatCompletion) -> String

Extract the text content from the first choice in a completion. Returns an empty string if there are no choices.

pub fn decode(
  json_string: String,
) -> Result(ChatCompletion, json.DecodeError)

Decode a JSON response string into a ChatCompletion. Returns an error if the JSON is malformed or missing required fields.

pub fn decode_error(
  json_string: String,
) -> Result(ApiError, json.DecodeError)

Decode an API error response. Use this when decode fails to check whether the server returned a structured error object.

Search Document