groq-api-rust 0.3.1

This library provides the ability to interact with the Groq API.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
mod message;
use futures::StreamExt;
pub use message::*;
use reqwest::{
    Client as AClient, Response as AResponse,
    blocking::multipart::{Form, Part},
    blocking::{Client, Response},
    multipart::{Form as AForm, Part as APart},
};
use serde_json::{Deserializer, StreamDeserializer, Value, json};
use std::sync::Arc;

/// An asynchronous client for interacting with the Groq API.
///
/// # Parameters
///
/// - `api_key`: The API key for authenticating with the Groq API.
/// - `endpoint`: The URL of the Groq API endpoint. If not provided, it defaults to <https://api.groq.com/openai/v1>.
///
/// # Returns
///
/// An instance of `AsyncGroqClient` configured with the provided API key and endpoint.
///
/// # Example
///
///```
/// use groq_client::AsyncGroqClient;
///
/// let client = AsyncGroqClient::new("my_api_key".to_string(), None).await;
///```
pub struct AsyncGroqClient {
    api_key: String,
    client: Arc<AClient>,
    endpoint: String,
}

impl AsyncGroqClient {
    /// Creates a new `AsyncGroqClient`
    pub async fn new(api_key: String, endpoint: Option<String>) -> Self {
        let ep = endpoint.unwrap_or_else(|| String::from("https://api.groq.com/openai/v1"));
        Self {
            api_key,
            client: Arc::new(AClient::new()),
            endpoint: ep,
        }
    }

    /// Sends a request to the Groq API with the provided JSON body and returns the parsed response.
    ///
    /// # Parameters
    ///
    /// - `body`: The JSON body to send in the request.
    /// - `link`: The URL link to send the request to.
    ///
    /// # Returns
    ///
    /// The parsed JSON response from the Groq API.
    async fn send_request(&self, body: Value, link: &str) -> Result<reqwest::Response, GroqError> {
        let res = self
            .client
            .post(link)
            .header("Content-Type", "application/json")
            .header("Authorization", &format!("Bearer {}", self.api_key))
            .json(&body)
            .send()
            .await?;
        Ok(res)
    }

    /// Sends a speech-to-text request to the Groq API and returns the parsed response.
    ///
    /// # Parameters
    ///
    /// - `request`: The `SpeechToTextRequest` containing the audio file, temperature, language, and other options.
    ///
    /// # Returns
    ///
    /// The parsed `SpeechToTextResponse` from the Groq API.
    pub async fn speech_to_text(
        &self,
        request: SpeechToTextRequest,
    ) -> Result<SpeechToTextResponse, GroqError> {
        let file = request.file;
        let temperature = request.temperature;
        let language = request.language;
        let english_text = request.english_text;
        let model = request.model;

        let mut form = AForm::new().part("file", APart::bytes(file).file_name("audio.wav"));
        if let Some(temp) = temperature {
            form = form.text("temperature", temp.to_string());
        }
        if let Some(lang) = language {
            form = form.text("language", lang);
        }

        let link_addition = if english_text {
            "/audio/translations"
        } else {
            "/audio/transcriptions"
        };
        if let Some(mdl) = model {
            form = form.text("model", mdl);
        }

        let link = format!("{}{}", self.endpoint, link_addition);
        let response = self
            .client
            .post(&link)
            .header("Authorization", &format!("Bearer {}", self.api_key))
            .multipart(form)
            .send()
            .await?;

        let speech_to_text_response: SpeechToTextResponse = response.json().await?;
        Ok(speech_to_text_response)
    }

    /// Internal function which sends a request to the Groq API and returns the raw response.
    ///
    /// # Parameters
    ///
    /// - `request`: The `ChatCompletionRequest` containing the model, messages, temperature, max tokens, top-p, and other options.
    ///
    /// # Returns
    ///
    /// The parsed `ChatCompletionResponse` from the Groq API.
    async fn send_response(
        &self,
        request: ChatCompletionRequest,
        stream: bool,
    ) -> Result<reqwest::Response, GroqError> {
        let messages = request
            .messages
            .iter()
            .map(|m| {
                let mut msg_json = json!({
                    "role": m.role,
                    "content": m.content,
                });
                if let Some(name) = &m.name {
                    msg_json["name"] = json!(name);
                }
                msg_json
            })
            .collect::<Vec<Value>>();

        let mut body = json!({
            "model": request.model,
            "messages": messages,
            "temperature": request.temperature.unwrap_or(1.0),
            "max_tokens": request.max_tokens.unwrap_or(1024),
            "top_p": request.top_p.unwrap_or(1.0),
            "stream": request.stream.unwrap_or(stream),
        });

        if let Some(stop) = &request.stop {
            body["stop"] = json!(stop);
        }
        if let Some(seed) = &request.seed {
            body["seed"] = json!(seed);
        }

        let response = self
            .send_request(body, &format!("{}/chat/completions", self.endpoint))
            .await?;
        Ok(response)
    }

    /// Sends a chat completion request to the Groq API and returns the parsed response.
    ///
    /// # Parameters
    ///
    /// - `request`: The `ChatCompletionRequest` containing the model, messages, temperature, max tokens, top-p, and other options.
    ///
    /// # Returns
    ///
    /// The parsed `ChatCompletionResponse` from the Groq API.
    pub async fn chat_completion(
        &self,
        request: ChatCompletionRequest,
    ) -> Result<ChatCompletionResponse, GroqError> {
        if Some(true) == request.stream {
            return Err(GroqError::InvalidRequest(
                "Stream parameter must be set to false for non-streaming responses.".to_string(),
            ));
        }
        let response = self.send_response(request, false).await?;
        let response = self.parse_response(response).await?;

        let chat_completion_response: ChatCompletionResponse = serde_json::from_value(response)?;
        Ok(chat_completion_response)
    }

    /// Streams to the Groq API and returns a stream of responses.
    ///
    /// # Parameters
    ///
    /// - `request`: The `ChatCompletionRequest` containing the model, messages, temperature, max tokens, top-p, and other options.
    ///
    /// # Returns
    ///
    /// A stream of `ChatCompletionDeltaResponse` from the Groq API.
    pub async fn stream(
        &self,
        request: ChatCompletionRequest,
    ) -> Result<
        impl futures::Stream<Item = Result<ChatCompletionDeltaResponse, GroqError>>,
        GroqError,
    > {
        if Some(false) == request.stream {
            return Err(GroqError::InvalidRequest(
                "Stream parameter must be set to true for streaming responses.".to_string(),
            ));
        }
        let response = self.send_response(request, true).await?;
        let stream_response = response.bytes_stream();

        // Returns a stream that outputs everything returned from groq
        // resp_string is the current state of what has been returned
        // stream_response is what groq has currently sent
        let prefix = "data: ";
        Ok(futures::stream::unfold(
            (stream_response, String::new()),
            move |(mut stream_response, mut resp_string)| async move {
                loop {
                    // Remove prefix if it exists
                    resp_string = resp_string
                        .strip_prefix(&prefix)
                        .unwrap_or(&resp_string)
                        .to_string();

                    // Attempts to deserialize resp_string
                    let mut stream: StreamDeserializer<_, ChatCompletionDeltaResponse> =
                        Deserializer::from_slice(resp_string.as_bytes()).into_iter();

                    if let Some(line) = stream.next() {
                        // If resp_string has a valid ChatCompletionDeltaResponse, return it
                        // If erroring, check that it does not equal [DONE]
                        if let Ok(line) = line {
                            let offset = stream.byte_offset();
                            resp_string = resp_string[offset..].trim().to_string();
                            return Some((Ok(line), (stream_response, resp_string)));
                        } else if resp_string == "[DONE]" {
                            return None;
                        }
                    }

                    if let Some(chunk) = stream_response.next().await {
                        // Get the next chunk from the groq stream,
                        // append it to resp_string and continue the loop to try and deserialize
                        if let Err(e) = chunk {
                            return Some((Err(GroqError::from(e)), (stream_response, resp_string)));
                        }
                        let chunk = String::from_utf8_lossy(&chunk.unwrap()).trim().to_string();
                        resp_string.push_str(&chunk);
                        continue;
                    } else if resp_string.is_empty() {
                        return None;
                    } else {
                        // If the stream has ended, and resp_string is not empty/[DONE]
                        // then parsing must have failed, and there must be a deserialization error
                        return Some((
                            Err(GroqError::DeserializationError {
                                message: resp_string.clone(),
                                type_: "DeserializationError".to_string(),
                            }),
                            (stream_response, resp_string),
                        ));
                    }
                }
            },
        ))
    }

    /// Parses the response from a Groq API request and returns the response body as a JSON value.
    ///
    /// # Parameters
    ///
    /// - `response`: The HTTP response from the Groq API request.
    ///
    /// # Returns
    ///
    /// The parsed JSON value from the response body, or a `GroqError` if the response was not successful.
    async fn parse_response(&self, response: AResponse) -> Result<Value, GroqError> {
        let status = response.status();
        let body: Value = response.json().await?;

        if !status.is_success()
            && let Some(error) = body.get("error")
        {
            return Err(GroqError::ApiError {
                message: error["message"]
                    .as_str()
                    .unwrap_or("Unknown error")
                    .to_string(),
                type_: error["type"]
                    .as_str()
                    .unwrap_or("unknown_error")
                    .to_string(),
            });
        }

        Ok(body)
    }
}

/// An client for interacting with the Groq API.
///
/// # Parameters
///
/// - `api_key`: The API key for authenticating with the Groq API.
/// - `endpoint`: The URL of the Groq API endpoint. If not provided, it defaults to <https://api.groq.com/openai/v1>.
///
/// # Returns
///
/// An instance of `GroqClient` configured with the provided API key and endpoint.
///
/// # Example
///
///```
/// use groq_client::GroqClient;
///
/// let client = GroqClient::new("my_api_key".to_string(), None);
///```
pub struct GroqClient {
    api_key: String,
    client: Client,
    endpoint: String,
}

impl GroqClient {
    /// Constructs a new `GroqClient` instance with the provided API key and optional endpoint.
    ///
    /// # Parameters
    ///
    /// - `api_key`: The API key for authenticating with the Groq API.
    /// - `endpoint`: The URL of the Groq API endpoint. If not provided, it defaults to <https://api.groq.com/openai/v1>.
    ///
    /// # Returns
    ///
    /// A new `GroqClient` instance configured with the provided API key and endpoint.
    pub fn new(api_key: String, endpoint: Option<String>) -> Self {
        let ep = endpoint.unwrap_or_else(|| String::from("https://api.groq.com/openai/v1"));
        Self {
            api_key,
            client: Client::new(),
            endpoint: ep,
        }
    }

    /// Sends a request to the Groq API with the provided JSON body and returns the parsed response.
    ///
    /// # Parameters
    ///
    /// - `body`: The JSON body to send in the request.
    /// - `link`: The URL link to send the request to.
    ///
    /// # Returns
    ///
    /// The parsed response from the Groq API as a `Value`.
    ///
    /// # Errors
    ///
    /// Returns a `GroqError` if there is an issue sending the request or parsing the response.
    fn send_request(&self, body: Value, link: &str) -> Result<Value, GroqError> {
        let res = self
            .client
            .post(link)
            .header("Content-Type", "application/json")
            .header("Authorization", &format!("Bearer {}", self.api_key))
            .json(&body)
            .send()?;

        parse_response(res)
    }

    /// Sends a speech-to-text request to the Groq API and returns the parsed response.
    ///
    /// # Parameters
    ///
    /// - `request`: A `SpeechToTextRequest` containing the necessary parameters for the speech-to-text request.
    ///
    /// # Returns
    ///
    /// The parsed `SpeechToTextResponse` from the Groq API.
    ///
    /// # Errors
    ///
    /// Returns a `GroqError` if there is an issue sending the request or parsing the response.
    pub fn speech_to_text(
        &self,
        request: SpeechToTextRequest,
    ) -> Result<SpeechToTextResponse, GroqError> {
        // Extract values from request
        let file = request.file;
        let temperature = request.temperature;
        let language = request.language;
        let english_text = request.english_text;
        let model = request.model;
        let prompt = request.prompt;
        let mut form = Form::new().part("file", Part::bytes(file).file_name("audio.wav"));

        if let Some(temp) = temperature {
            form = form.text("temperature", temp.to_string());
        }

        if let Some(lang) = language {
            form = form.text("language", lang);
        }

        let link_addition = if english_text {
            "/audio/translations"
        } else {
            "/audio/transcriptions"
        };

        if let Some(mdl) = model {
            form = form.text("model", mdl);
        }
        if let Some(prompt) = prompt {
            form = form.text("prompt", prompt.to_string());
        }

        let link = format!("{}{}", self.endpoint, link_addition);
        let response = self
            .client
            .post(link)
            .header("Authorization", &format!("Bearer {}", self.api_key))
            .multipart(form)
            .send()?;

        let speech_to_text_response: SpeechToTextResponse = response.json()?;
        Ok(speech_to_text_response)
    }

    /// Sends a chat completion request to the GROQ API and returns the response.
    ///
    /// # Parameters
    ///
    /// - `request` - A `ChatCompletionRequest` containing the details of the chat completion request.
    ///
    /// # Errors
    ///
    /// Returns a `GroqError` if there is an issue sending the request or parsing the response.
    pub fn chat_completion(
        &self,
        request: ChatCompletionRequest,
    ) -> Result<ChatCompletionResponse, GroqError> {
        let messages = request
            .messages
            .iter()
            .map(|m| {
                let mut msg_json = json!({
                    "role": m.role,
                    "content": m.content,
                });
                if let Some(name) = &m.name {
                    msg_json["name"] = json!(name);
                }
                msg_json
            })
            .collect::<Vec<_>>();

        let mut body = json!({
            "model": request.model,
            "messages": messages,
            "temperature": request.temperature.unwrap_or(1.0),
            "max_tokens": request.max_tokens.unwrap_or(1024),
            "top_p": request.top_p.unwrap_or(1.0),
            "stream": request.stream.unwrap_or(false),
        });

        if let Some(stop) = &request.stop {
            body["stop"] = json!(stop);
        }
        if let Some(seed) = &request.seed {
            body["seed"] = json!(seed);
        }

        let response = self.send_request(body, &format!("{}/chat/completions", self.endpoint))?;
        let chat_completion_response: ChatCompletionResponse = serde_json::from_value(response)?;
        Ok(chat_completion_response)
    }
}

/// Parses the response from a GROQ API request and returns the response body as a JSON value.
///
/// # Parameters
///
/// - `response` - The HTTP response from the GROQ API request.
///
/// # Errors
///
/// Returns a `GroqError` if the response status is not successful or if there is an error parsing the response body.
///
/// # Returns
///
/// The response body as a JSON value.
fn parse_response(response: Response) -> Result<Value, GroqError> {
    let status = response.status();
    let body: Value = response.json()?;

    if !status.is_success()
        && let Some(error) = body.get("error")
    {
        return Err(GroqError::ApiError {
            message: error["message"]
                .as_str()
                .unwrap_or("Unknown error")
                .to_string(),
            type_: error["type"]
                .as_str()
                .unwrap_or("unknown_error")
                .to_string(),
        });
    }

    Ok(body)
}

#[cfg(test)]
mod tests {
    use super::*;
    use std::fs::File;
    use std::io::Read;
    use tokio;

    #[test]
    fn test_chat_completion() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = GroqClient::new(api_key.to_string(), None);
        let messages = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "Hello".to_string(),
            name: None,
        }];
        let request = ChatCompletionRequest::new("llama3-70b-8192", messages);
        let response = client.chat_completion(request).unwrap();
        println!("{:?}", response);
        assert!(!response.choices.is_empty());
    }

    #[test]
    fn test_speech_to_text() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = GroqClient::new(api_key.to_string(), None);
        let audio_file_path = "onepiece_demo.mp4";
        let mut file = File::open(audio_file_path).expect("Failed to open audio file");
        let mut audio_data = Vec::new();
        file.read_to_end(&mut audio_data)
            .expect("Failed to read audio file");
        let request = SpeechToTextRequest::new(audio_data)
            .temperature(0.7)
            .language("en")
            .model("whisper-large-v3");
        let response = client
            .speech_to_text(request)
            .expect("Failed to get response");
        println!("Speech to Text Response: {}", response.text);
        assert!(!response.text.is_empty());
    }

    #[tokio::test]
    async fn test_async_chat_completion() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = AsyncGroqClient::new(api_key, None).await;

        let messages1 = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "Hello".to_string(),
            name: None,
        }];
        let request1 = ChatCompletionRequest::new("llama-3.3-70b-versatile", messages1);

        let messages2 = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "How are you?".to_string(),
            name: None,
        }];
        let request2 = ChatCompletionRequest::new("llama-3.3-70b-versatile", messages2);

        let (response1, response2) = tokio::join!(
            client.chat_completion(request1),
            client.chat_completion(request2)
        );

        let response1 = response1.expect("Failed to get response for request 1");
        let response2 = response2.expect("Failed to get response for request 2");

        println!("Response 1: {}", response1.choices[0].message.content);
        println!("Response 2: {}", response2.choices[0].message.content);

        assert!(!response1.choices.is_empty());
        assert!(!response2.choices.is_empty());
    }

    #[tokio::test]
    async fn test_async_stream() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = AsyncGroqClient::new(api_key, None).await;

        let messages1 = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "Hello!".to_string(),
            name: None,
        }];
        let request1 =
            ChatCompletionRequest::new("llama-3.3-70b-versatile", messages1).stream(true);

        let messages2 = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "How are you?".to_string(),
            name: None,
        }];
        let request2 =
            ChatCompletionRequest::new("llama-3.3-70b-versatile", messages2).stream(true);

        let (stream1, stream2) = tokio::join!(client.stream(request1), client.stream(request2));

        let stream1 = stream1.expect("Failed to get response for request 1");
        let stream2 = stream2.expect("Failed to get response for request 2");

        let mut response1 = String::new();
        let mut response2 = String::new();

        tokio::pin!(stream1);
        tokio::pin!(stream2);

        while let Some(item) = stream1.next().await {
            let delta = item.expect("Failed to get delta from stream 1");
            if let Some(content) = &delta.choices[0].delta.content {
                response1.push_str(&content);
            }
        }
        println!();
        while let Some(item) = stream2.next().await {
            let delta = item.expect("Failed to get delta from stream 2");
            if let Some(content) = &delta.choices[0].delta.content {
                response2.push_str(&content);
            }
        }
        println!();

        println!("Response 1: {}", response1);
        println!("Response 2: {}", response2);

        assert!(!response1.is_empty());
        assert!(!response2.is_empty());
    }

    #[tokio::test]
    async fn test_async_stream_fail() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = AsyncGroqClient::new(api_key, None).await;

        let messages1 = vec![ChatCompletionMessage {
            role: ChatCompletionRoles::User,
            content: "Hello!".to_string(),
            name: None,
        }];
        let request = ChatCompletionRequest::new("llama3-70b-8192", messages1).stream(true);

        let stream = client
            .stream(request)
            .await
            .expect("Failed to get response");

        tokio::pin!(stream);

        while let Some(item) = stream.next().await {
            if let Err(e) = item {
                let expected_message = r#"Deserialization error: {"error":{"message":"The model `llama3-70b-8192` has been decommissioned and is no longer supported. Please refer to https://console.groq.com/docs/deprecations for a recommendation on which model to use instead.","type":"invalid_request_error","code":"model_decommissioned"}}"#;
                assert_eq!(e.to_string(), expected_message);
                return;
            } else {
                panic!("Expected an error but got a successful response");
            }
        }
    }

    #[tokio::test]
    async fn test_async_speech_to_text() {
        let api_key = std::env::var("GROQ_API_KEY").unwrap();
        let client = AsyncGroqClient::new(api_key, None).await;

        let audio_file_path1 = "onepiece_demo.mp4";
        let audio_file_path2 = "save.ogg";

        let (audio_data1, audio_data2) = tokio::join!(
            tokio::fs::read(audio_file_path1),
            tokio::fs::read(audio_file_path2)
        );

        let audio_data1 = audio_data1.expect("Failed to read first audio file");
        let audio_data2 = audio_data2.expect("Failed to read second audio file");

        let (request1, request2) = (
            SpeechToTextRequest::new(audio_data1)
                .temperature(0.7)
                .language("en")
                .model("whisper-large-v3"),
            SpeechToTextRequest::new(audio_data2)
                .temperature(0.7)
                .language("en")
                .model("whisper-large-v3"),
        );
        let (response1, response2) = tokio::join!(
            client.speech_to_text(request1),
            client.speech_to_text(request2)
        );

        let response1 = response1.expect("Failed to get response for first audio");
        let response2 = response2.expect("Failed to get response for second audio");

        println!("Speech to Text Response 1: {:?}", response1);
        println!("Speech to Text Response 2: {:?}", response2);

        assert!(!response1.text.is_empty());
        assert!(!response2.text.is_empty());
    }
}