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>(_schema: &AudioInputSchema, mut rng: R) -> Generator<R> {
12 let mut indices: Vec<usize> = (0..2).collect();
13 indices.shuffle(&mut rng);
14 Generator {
15 indices,
16 pos: 0,
17 rng,
18 }
19}
20
21pub struct Generator<R: Rng> {
22 indices: Vec<usize>,
23 pos: usize,
24 rng: R,
25}
26
27impl<R: Rng> Iterator for Generator<R> {
28 type Item = InputValue;
29 fn next(&mut self) -> Option<InputValue> {
30 if self.pos >= self.indices.len() {
31 self.indices.shuffle(&mut self.rng);
32 self.pos = 0;
33 }
34 let index = self.indices[self.pos];
35 self.pos += 1;
36 Some(InputValue::RichContentPart(RichContentPart::InputAudio {
37 input_audio: InputAudio {
38 data: super::string::random_string(&mut self.rng),
39 format: if index == 0 {
40 "wav".to_string()
41 } else {
42 "mp3".to_string()
43 },
44 },
45 }))
46 }
47}