opt.rs 1.46 KB
Newer Older
1
2
3
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

4
use std::fmt;
5

6
pub enum Output {
7
8
    /// Echos the prompt back as the response
    Echo,
9

10
    /// Listen for models on nats/etcd, add/remove dynamically
11
12
    Auto,

13
14
    #[cfg(feature = "mistralrs")]
    MistralRs,
15

16
    Mocker,
17
18
19
20
21
22
23
}

impl TryFrom<&str> for Output {
    type Error = anyhow::Error;

    fn try_from(s: &str) -> anyhow::Result<Self> {
        match s {
24
25
26
            #[cfg(feature = "mistralrs")]
            "mistralrs" => Ok(Output::MistralRs),

27
            "mocker" => Ok(Output::Mocker),
28
            "echo" | "echo_full" => Ok(Output::Echo),
29

30
            "dyn" | "auto" => Ok(Output::Auto),
31

32
33
34
35
36
37
38
39
            e => Err(anyhow::anyhow!("Invalid out= option '{e}'")),
        }
    }
}

impl fmt::Display for Output {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let s = match self {
40
41
42
            #[cfg(feature = "mistralrs")]
            Output::MistralRs => "mistralrs",

43
            Output::Mocker => "mocker",
44
            Output::Echo => "echo",
45

46
            Output::Auto => "auto",
47
48
49
50
        };
        write!(f, "{s}")
    }
}
51

52
53
54
impl Output {
    #[allow(unused_mut)]
    pub fn available_engines() -> Vec<String> {
55
        let mut out = vec!["echo".to_string(), Output::Mocker.to_string()];
56
57
58
59
60
61
62
        #[cfg(feature = "mistralrs")]
        {
            out.push(Output::MistralRs.to_string());
        }
        out
    }
}