Skip to main content

objectiveai_sdk/functions/profiles/computations/response/unary/
function_profile_computation.rs

1use crate::{
2    agent,
3    functions::{self, profiles::computations::response},
4};
5use schemars::JsonSchema;
6use serde::{Deserialize, Serialize};
7
8#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
9#[schemars(
10    rename = "functions.profiles.computations.response.unary.FunctionProfileComputation"
11)]
12pub struct FunctionProfileComputation {
13    pub id: String,
14    pub executions: Vec<super::FunctionExecution>,
15    pub executions_errors: bool,
16    pub profile: functions::InlineTasksProfile,
17    pub fitting_stats: response::FittingStats,
18    pub created: u64,
19    pub function: Option<crate::RemotePath>,
20    pub object: super::Object,
21    pub usage: agent::completions::response::Usage,
22}
23
24impl FunctionProfileComputation {
25    pub fn any_usage(&self) -> bool {
26        self.usage.any_usage()
27    }
28
29    pub fn normalize_for_tests(&mut self) {
30        self.usage.normalize_for_tests();
31    }
32}
33
34impl From<response::streaming::FunctionProfileComputationChunk>
35    for FunctionProfileComputation
36{
37    fn from(
38        response::streaming::FunctionProfileComputationChunk {
39            id,
40            executions,
41            executions_errors,
42            profile,
43            fitting_stats,
44            created,
45            function,
46            object,
47            usage,
48        }: response::streaming::FunctionProfileComputationChunk,
49    ) -> Self {
50        Self {
51            id,
52            executions: executions
53                .into_iter()
54                .map(super::FunctionExecution::from)
55                .collect(),
56            executions_errors: executions_errors.unwrap_or(false),
57            profile: profile.unwrap_or_else(|| functions::InlineTasksProfile {
58                tasks: Vec::new(),
59                weights: None,
60            }),
61            fitting_stats: fitting_stats
62                .unwrap_or(response::FittingStats::default()),
63            created,
64            function,
65            object: object.into(),
66            usage: usage.unwrap_or_default(),
67        }
68    }
69}