1pub mod groq {
2 use reqwest::blocking::Client;
3
4 pub struct Groq {
5 api_key: String,
6 client: Client,
7 }
8
9 impl Groq {
10 pub fn new(api_key: String) -> Self {
11 Self {
12 api_key,
13 client: Client::new(),
14 }
15 }
16
17 pub fn test_request(&self) -> String {
18 let response = self.client
19 .post("https://api.groq.com/openai/v1/chat/completions")
20 .header("Authorization", format!("Bearer {}", self.api_key))
21 .header("Content-Type", "application/json")
22 .body("{\"messages\": [{\"role\": \"user\", \"content\": \"Explain the importance of fast language models\"}], \"model\": \"mixtral-8x7b-32768\"}")
23 .send().unwrap();
24
25 response.text().unwrap()
26 }
27 }
28}
29
30#[cfg(test)]
31mod tests {
32 use std::env;
33
34 use crate::groq::Groq;
35
36 #[test]
37 fn basic_test() {
38 let api_key = env::var("GROQ_API_KEY").unwrap();
39 let groq = Groq::new(api_key);
40
41 println!("{}", groq.test_request())
42 }
43}