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}
31
32impl From<response::streaming::FunctionProfileComputationChunk>
33    for FunctionProfileComputation
34{
35    fn from(
36        response::streaming::FunctionProfileComputationChunk {
37            id,
38            executions,
39            executions_errors,
40            profile,
41            fitting_stats,
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            created,
62            function,
63            object: object.into(),
64            usage: usage.unwrap_or_default(),
65        }
66    }
67}