objectiveai_sdk/functions/check/example_inputs/
audio.rs1use rand::Rng;
2use rand::seq::SliceRandom;
3
4use crate::agent::completions::message::{InputAudio, RichContentPart};
5use crate::functions::expression::{AudioInputSchema, InputValue};
6
7pub const fn permutations(_schema: &AudioInputSchema) -> usize {
8 2usize
9}
10
11pub fn generate<R: Rng>(
12 _schema: &AudioInputSchema,
13 mut rng: R,
14) -> Generator<R> {
15 let mut indices: Vec<usize> = (0..2).collect();
16 indices.shuffle(&mut rng);
17 Generator {
18 indices,
19 pos: 0,
20 rng,
21 }
22}
23
24pub struct Generator<R: Rng> {
25 indices: Vec<usize>,
26 pos: usize,
27 rng: R,
28}
29
30impl<R: Rng> Iterator for Generator<R> {
31 type Item = InputValue;
32 fn next(&mut self) -> Option<InputValue> {
33 if self.pos >= self.indices.len() {
34 self.indices.shuffle(&mut self.rng);
35 self.pos = 0;
36 }
37 let index = self.indices[self.pos];
38 self.pos += 1;
39 Some(InputValue::RichContentPart(RichContentPart::InputAudio {
40 input_audio: InputAudio {
41 data: super::string::random_string(&mut self.rng),
42 format: if index == 0 {
43 "wav".to_string()
44 } else {
45 "mp3".to_string()
46 },
47 },
48 }))
49 }
50}