Unofficial Groq API Rust Client Library
This library provides the ability to interact with the Groq API. It allows you to send requests to the API and receive responses via the GroqClient
interface.
How to Install
To install the groq-api-rust
crate, add it to your Rust project's dependencies by running the following command in your project's directory:
cargo add groq-api-rust
Usage
-
Import the
groq-api-rust
crate into your Rust project. -
Create an instance of the
GroqClient
struct by callingGroqClient::new()
and providing your Groq API key and an optional endpoint URL. -
Use the
chat_completion()
method on theGroqClient
instance to perform chat completions. Create aChatCompletionRequest
struct with the desired model, messages, and other parameters, and pass it to thechat_completion()
method. -
Use the
speech_to_text()
method on theGroqClient
instance to perform speech-to-text conversions. Create aSpeechToTextRequest
struct with the audio file data and other parameters, and pass it to thespeech_to_text()
method.
Examples
Chat Completion
use ;
let api_key = var.unwrap;
let client = new;
let messages = vec!;
let request = new;
let response = client.chat_completion.unwrap;
println!;
assert!;
Speech To Text
use ;
use ;
let api_key = var.unwrap;
let client = new;
let audio_file_path = "audio_file.mp3";
let mut file = open.expect;
let mut audio_data = Vec new;
file.read_to_end
.expect;
let request = new
.temperature
.language
.model;
let response = client
.speech_to_text
.expect;
println!;
Async Chat Completion
use ;
use tokio;
let api_key = var.unwrap;
let client = new;
let messages1 = vec!;
let request1 = new;
let messages2 = vec!;
let request2 = new;
let = join!;
let response1 = response1.expect;
let response2 = response2.expect;
println!;
println!;
Async Speech To Text
use ;
use tokio;
let api_key = var.unwrap;
let client = new;
let audio_file_path1 = "onepiece_demo.mp4";
let audio_file_path2 = "save.ogg";
let = join!;
let audio_data1 = audio_data1.expect;
let audio_data2 = audio_data2.expect;
let = ;
let = join!;
let response1 = response1.expect;
let response2 = response2.expect;
println!;
println!;
TODO:
- Implement streaming of requests.
Contributing
Contributions are welcome! If you have an issue or want to suggest improvements, please open an issue or submit a pull request.
License
This library is licensed under the Apache License 2.0 License. See the LICENSE file for more information.