Skip to main content

objectiveai_sdk/functions/executions/response/streaming/
vector_completion_task_chunk.rs

1use crate::agent::completions::response::streaming::AgentCompletionIds;
2use crate::{error, vector};
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6#[derive(
7    Debug,
8    Clone,
9    PartialEq,
10    Serialize,
11    Deserialize,
12    Default,
13    JsonSchema,
14    arbitrary::Arbitrary,
15)]
16#[schemars(
17    rename = "functions.executions.response.streaming.VectorCompletionTaskChunk"
18)]
19pub struct VectorCompletionTaskChunk {
20    #[arbitrary(with = crate::arbitrary_util::arbitrary_u64)]
21    pub index: u64,
22    #[arbitrary(with = crate::arbitrary_util::arbitrary_u64)]
23    pub task_index: u64,
24    #[arbitrary(with = crate::arbitrary_util::arbitrary_vec_u64)]
25    pub task_path: Vec<u64>,
26    /// The messages dispatched for this vector-completion task.
27    /// Populated ONLY on the FIRST chunk of the task; [`push`](Self::push)
28    /// keeps the first value.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    #[schemars(extend("omitempty" = true))]
31    #[arbitrary(default)]
32    pub request_messages:
33        Option<Vec<crate::agent::completions::message::Message>>,
34    /// The response options (choices) voted on for this
35    /// vector-completion task. Populated ONLY on the FIRST chunk of the
36    /// task; [`push`](Self::push) keeps the first value.
37    #[serde(skip_serializing_if = "Option::is_none")]
38    #[schemars(extend("omitempty" = true))]
39    #[arbitrary(default)]
40    pub request_choices:
41        Option<Vec<crate::agent::completions::message::RichContent>>,
42    #[serde(flatten)]
43    pub inner: vector::completions::response::streaming::VectorCompletionChunk,
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[schemars(extend("omitempty" = true))]
46    pub error: Option<error::ResponseError>,
47}
48
49impl AgentCompletionIds for VectorCompletionTaskChunk {
50    fn agent_completion_ids(&self) -> impl Iterator<Item = &str> + Send {
51        self.inner.agent_completion_ids()
52    }
53}
54
55impl VectorCompletionTaskChunk {
56    pub fn push(&mut self, other: &VectorCompletionTaskChunk) {
57        self.inner.push(&other.inner);
58        if let Some(error) = &other.error {
59            self.error = Some(error.clone());
60        }
61        // First chunk wins: `request_messages` and `request_choices`
62        // ride only the task's first chunk.
63        if self.request_messages.is_none() {
64            if let Some(request_messages) = &other.request_messages {
65                self.request_messages = Some(request_messages.clone());
66            }
67        }
68        if self.request_choices.is_none() {
69            if let Some(request_choices) = &other.request_choices {
70                self.request_choices = Some(request_choices.clone());
71            }
72        }
73    }
74}