Skip to main content

ai_lib_rust/pipeline/
fallback.rs

1//! Fallback Operator
2//!
3//! This operator handles failover to alternative models/providers.
4
5pub struct FallbackOperator {
6    pub candidates: Vec<String>, // List of model IDs
7}
8
9impl FallbackOperator {
10    pub fn new(candidates: Vec<String>) -> Self {
11        Self { candidates }
12    }
13
14    pub fn next(&self, current_failed_model: &str) -> Option<&str> {
15        // Find current model index and return next
16        let idx = self
17            .candidates
18            .iter()
19            .position(|r| r == current_failed_model);
20        match idx {
21            Some(i) => {
22                if i + 1 < self.candidates.len() {
23                    Some(&self.candidates[i + 1])
24                } else {
25                    None // End of list
26                }
27            }
28            None => self.candidates.first().map(|s| s.as_str()),
29        }
30    }
31}