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 single completion choice. Most requests return exactly one choice.
pub type Choice {
Choice(
index: Int,
message: ResponseMessage,
finish_reason: option.Option(String),
)
}
Constructors
-
Choice( index: Int, message: ResponseMessage, finish_reason: option.Option(String), )
The assistant message returned in a completion choice.
pub type ResponseMessage {
ResponseMessage(role: String, content: String)
}
Constructors
-
ResponseMessage(role: String, content: String)
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.