Skip to main content

objectiveai_sdk/functions/inventions/response/unary/
function_invention.rs

1use crate::functions::inventions::response;
2use crate::{agent, error, functions};
3use serde::{Deserialize, Serialize};
4use schemars::JsonSchema;
5
6#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
7#[schemars(rename = "functions.inventions.response.unary.FunctionInvention")]
8pub struct FunctionInvention {
9    pub id: String,
10    pub completions: Vec<super::AgentCompletion>,
11    pub state: functions::inventions::State,
12    pub path: Option<crate::RemotePath>,
13    pub function: Option<functions::FullRemoteFunction>,
14    pub created: u64,
15    pub object: super::Object,
16    pub usage: agent::completions::response::Usage,
17    pub error: Option<error::ResponseError>,
18}
19
20impl FunctionInvention {
21    /// Normalize non-deterministic fields for test snapshot comparison.
22    pub fn normalize_for_tests(&mut self) {
23        self.id = String::new();
24        self.created = 0;
25        for completion in &mut self.completions {
26            completion.inner.normalize_for_tests();
27        }
28    }
29}
30
31impl From<response::streaming::FunctionInventionChunk> for FunctionInvention {
32    fn from(
33        response::streaming::FunctionInventionChunk {
34            id,
35            completions,
36            state,
37            path,
38            function,
39            created,
40            object,
41            usage,
42            error,
43        }: response::streaming::FunctionInventionChunk,
44    ) -> Self {
45        Self {
46            id,
47            completions: completions
48                .into_iter()
49                .map(super::AgentCompletion::from)
50                .collect(),
51            state: state.unwrap_or(
52                functions::inventions::State::AlphaScalarBranch(
53                    functions::inventions::AlphaScalarBranchState {
54                        params: functions::inventions::Params {
55                            depth: 0,
56                            min_branch_width: 0,
57                            max_branch_width: 0,
58                            min_leaf_width: 0,
59                            max_leaf_width: 0,
60                            name: String::new(),
61                            spec: String::new(),
62                        },
63                        essay: None,
64                        input_schema: None,
65                        essay_tasks: None,
66                        tasks: None,
67                        tasks_length: None,
68                        description: None,
69                        readme: None,
70                        checker_seed: None,
71                    },
72                ),
73            ),
74            path,
75            function,
76            created,
77            object: object.into(),
78            usage: usage.unwrap_or_default(),
79            error,
80        }
81    }
82}