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 retry_token: Option<String>,
19    pub created: u64,
20    pub function: Option<crate::RemotePath>,
21    pub object: super::Object,
22    pub usage: agent::completions::response::Usage,
23}
24
25impl FunctionProfileComputation {
26    pub fn any_usage(&self) -> bool {
27        self.usage.any_usage()
28    }
29
30    pub fn normalize_for_tests(&mut self) {}
31}
32
33impl From<response::streaming::FunctionProfileComputationChunk>
34    for FunctionProfileComputation
35{
36    fn from(
37        response::streaming::FunctionProfileComputationChunk {
38            id,
39            executions,
40            executions_errors,
41            profile,
42            fitting_stats,
43            retry_token,
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            retry_token,
64            created,
65            function,
66            object: object.into(),
67            usage: usage.unwrap_or_default(),
68        }
69    }
70}