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