objectiveai_sdk/functions/executions/response/unary/
task.rs1use crate::functions::executions::response;
2use schemars::JsonSchema;
3use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
6#[serde(untagged)]
7#[schemars(rename = "functions.executions.response.unary.Task")]
8pub enum Task {
9 #[schemars(title = "FunctionExecution")]
10 FunctionExecution(super::FunctionExecutionTask),
11 #[schemars(title = "VectorCompletion")]
12 VectorCompletion(super::VectorCompletionTask),
13}
14
15impl Task {
16 pub fn task_path(&self) -> &Vec<u64> {
17 match self {
18 Task::FunctionExecution(f) => &f.task_path,
19 Task::VectorCompletion(v) => &v.task_path,
20 }
21 }
22
23 pub fn snapshot_sort_key(
28 &self,
29 ) -> (Vec<u64>, Option<u64>, Option<u64>, Option<u64>, u64) {
30 match self {
31 Task::FunctionExecution(f) => (
32 f.task_path.clone(),
33 f.swiss_round,
34 f.swiss_pool_index,
35 f.split_index,
36 f.task_index,
37 ),
38 Task::VectorCompletion(v) => {
39 (v.task_path.clone(), None, None, None, v.task_index)
40 }
41 }
42 }
43}
44
45impl From<response::streaming::TaskChunk> for Task {
46 fn from(chunk: response::streaming::TaskChunk) -> Self {
47 match chunk {
48 response::streaming::TaskChunk::FunctionExecution(chunk) => {
49 Task::FunctionExecution(chunk.into())
50 }
51 response::streaming::TaskChunk::VectorCompletion(chunk) => {
52 Task::VectorCompletion(chunk.into())
53 }
54 }
55 }
56}