objectiveai_sdk/functions/check/example_inputs/
file.rs1use rand::Rng;
2use rand::seq::SliceRandom;
3
4use crate::agent::completions::message::{File, RichContentPart};
5use crate::functions::expression::{FileInputSchema, InputValue};
6
7pub const fn permutations(_schema: &FileInputSchema) -> usize {
8 16usize
9}
10
11pub fn generate<R: Rng>(_schema: &FileInputSchema, mut rng: R) -> Generator<R> {
12 let mut indices: Vec<usize> = (0..16).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 let mask = index as u32;
37 let rng = &mut self.rng;
38 let file = File {
39 file_data: if mask & 1 != 0 {
40 Some(super::string::random_string(rng))
41 } else {
42 None
43 },
44 file_id: if mask & 2 != 0 {
45 Some(super::string::random_string(rng))
46 } else {
47 None
48 },
49 filename: if mask & 4 != 0 {
50 Some(super::string::random_string(rng))
51 } else {
52 None
53 },
54 file_url: if mask & 8 != 0 {
55 Some(super::string::random_string(rng))
56 } else {
57 None
58 },
59 };
60 Some(InputValue::RichContentPart(RichContentPart::File { file }))
61 }
62}