objectiveai_sdk/functions/executions/response/streaming/
vector_completion_task_chunk.rs1use crate::{error, vector};
2use serde::{Deserialize, Serialize};
3use schemars::JsonSchema;
4
5#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default, JsonSchema, arbitrary::Arbitrary)]
6#[schemars(rename = "functions.executions.response.streaming.VectorCompletionTaskChunk")]
7pub struct VectorCompletionTaskChunk {
8 #[arbitrary(with = crate::arbitrary_util::arbitrary_u64)]
9 pub index: u64,
10 #[arbitrary(with = crate::arbitrary_util::arbitrary_u64)]
11 pub task_index: u64,
12 #[arbitrary(with = crate::arbitrary_util::arbitrary_vec_u64)]
13 pub task_path: Vec<u64>,
14 #[serde(flatten)]
15 pub inner: vector::completions::response::streaming::VectorCompletionChunk,
16 #[serde(skip_serializing_if = "Option::is_none")]
17 #[schemars(extend("omitempty" = true))]
18 pub error: Option<error::ResponseError>,
19}
20
21impl VectorCompletionTaskChunk {
22 pub fn push(&mut self, other: &VectorCompletionTaskChunk) {
23 self.inner.push(&other.inner);
24 if let Some(error) = &other.error {
25 self.error = Some(error.clone());
26 }
27 }
28
29 #[cfg(feature = "filesystem")]
35 pub fn produce_files(&self) -> (serde_json::Value, Vec<crate::filesystem::logs::LogFile>) {
36 let (mut reference, files) = match self.inner.produce_files() {
37 Some((reference, files)) => (reference, files),
38 None => return (serde_json::json!({ "type": "reference", "index": self.index, "task_index": self.task_index, "task_path": self.task_path }), Vec::new()),
39 };
40 if let Some(map) = reference.as_object_mut() {
41 map.insert("index".to_string(), serde_json::json!(self.index));
42 map.insert("task_index".to_string(), serde_json::json!(self.task_index));
43 map.insert("task_path".to_string(), serde_json::json!(self.task_path));
44 if let Some(error) = &self.error {
45 map.insert("error".to_string(), serde_json::to_value(error).unwrap());
46 }
47 }
48 (reference, files)
49 }
50}