Skip to main content

objectiveai_sdk/functions/alpha_vector/expression/
input_value.rs

1use crate::functions;
2use indexmap::IndexMap;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6pub type ScalarFunctionInputValueExpression = functions::expression::Expression;
7
8pub mod scalar_function_input_value_expression {
9    use crate::functions;
10    pub fn transpile(
11        this: super::ScalarFunctionInputValueExpression,
12    ) -> functions::expression::WithExpression<
13        functions::expression::InputValueExpression,
14    > {
15        functions::expression::WithExpression::Expression(this)
16    }
17}
18
19#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema, arbitrary::Arbitrary)]
20#[schemars(rename = "functions.alpha_vector.expression.VectorFunctionInputValueExpression")]
21pub struct VectorFunctionInputValueExpression {
22    #[serde(skip_serializing_if = "Option::is_none")]
23    #[schemars(extend("omitempty" = true))]
24    pub context: Option<functions::expression::Expression>,
25    pub items: functions::expression::Expression,
26}
27
28impl VectorFunctionInputValueExpression {
29    pub fn transpile(
30        self,
31    ) -> functions::expression::WithExpression<
32        functions::expression::InputValueExpression,
33    > {
34        functions::expression::WithExpression::Value(
35            functions::expression::InputValueExpression::Object({
36                let mut map =
37                    IndexMap::with_capacity(if self.context.is_some() {
38                        2
39                    } else {
40                        1
41                    });
42                if let Some(context) = self.context {
43                    map.insert(
44                        "context".to_string(),
45                        functions::expression::WithExpression::Expression(
46                            context,
47                        ),
48                    );
49                }
50                map.insert(
51                    "items".to_string(),
52                    functions::expression::WithExpression::Expression(
53                        self.items,
54                    ),
55                );
56                map
57            }),
58        )
59    }
60}
61
62pub type ScalarFunctionInputValue = IndexMap<String, functions::expression::InputValue>;
63
64pub mod scalar_function_input_value {
65    use crate::functions;
66    pub fn transpile(
67        this: super::ScalarFunctionInputValue,
68    ) -> functions::expression::InputValue {
69        functions::expression::InputValue::Object(this)
70    }
71}
72
73#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, JsonSchema)]
74#[schemars(rename = "functions.alpha_vector.expression.VectorFunctionInputValue")]
75pub struct VectorFunctionInputValue {
76    #[serde(skip_serializing_if = "Option::is_none")]
77    #[schemars(extend("omitempty" = true))]
78    pub context: Option<IndexMap<String, functions::expression::InputValue>>,
79    pub items: Vec<functions::expression::InputValue>,
80}
81
82impl VectorFunctionInputValue {
83    pub fn transpile(self) -> functions::expression::InputValue {
84        functions::expression::InputValue::Object({
85            let mut map = IndexMap::with_capacity(if self.context.is_some() {
86                2
87            } else {
88                1
89            });
90            if let Some(context) = self.context {
91                map.insert(
92                    "context".to_string(),
93                    functions::expression::InputValue::Object(context),
94                );
95            }
96            map.insert(
97                "items".to_string(),
98                functions::expression::InputValue::Array(self.items),
99            );
100            map
101        })
102    }
103}