gloq

Functions

pub fn groq_request(
  key: String,
  user: String,
  context: String,
  model: String,
) -> String

Makes a request to the GroqCloud API for chat completions.

This function sends a POST request to the Groq API endpoint for chat completions. It constructs the request body with the provided user message and context, sets the necessary headers including the API key, and handles the response.

Parameters:

  • key: String - The API key for authentication with Groq.
  • user: String - The role of the message sender (e.g., “user” or “system”).
  • context: String - The content of the message or prompt.
  • model: String - The name of the Groq model to use for the completion.

Returns:

  • String - The response body from the API if successful, or an error message if the request fails.

Note: This function uses the hackney HTTP client for making the request.

Search Document