objectiveai_sdk/functions/executions/response/unary/
task.rs1use crate::functions::executions::response;
2use serde::{Deserialize, Serialize};
3use schemars::JsonSchema;
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(&self) -> (Vec<u64>, Option<u64>, Option<u64>, Option<u64>, u64) {
28 match self {
29 Task::FunctionExecution(f) => (
30 f.task_path.clone(),
31 f.swiss_round,
32 f.swiss_pool_index,
33 f.split_index,
34 f.task_index,
35 ),
36 Task::VectorCompletion(v) => (
37 v.task_path.clone(),
38 None,
39 None,
40 None,
41 v.task_index,
42 ),
43 }
44 }
45}
46
47impl From<response::streaming::TaskChunk> for Task {
48 fn from(chunk: response::streaming::TaskChunk) -> Self {
49 match chunk {
50 response::streaming::TaskChunk::FunctionExecution(chunk) => {
51 Task::FunctionExecution(chunk.into())
52 }
53 response::streaming::TaskChunk::VectorCompletion(chunk) => {
54 Task::VectorCompletion(chunk.into())
55 }
56 }
57 }
58}