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