"lib/vscode:/vscode.git/clone" did not exist on "0b8b7ffb7337005f18a8a1611ee0d41213642a16"
opt.rs 2.13 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 dynamo_runtime::protocols::ENDPOINT_SCHEME;
5
use std::fmt;
6

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

11
    /// Listen for models on nats/etcd, add/remove dynamically
12
13
14
15
16
17
18
19
    Auto,

    /// Static remote: The dyn://namespace.component.endpoint name of a remote worker we expect to
    /// exists. THIS DISABLES AUTO-DISCOVERY. Only this endpoint will be connected.
    /// `--model-name and `--model-path` must also be set.
    ///
    /// A static remote setup avoids having to run etcd.
    Static(String),
20

21
22
    #[cfg(feature = "mistralrs")]
    MistralRs,
23

24
    Mocker,
25
26
27
28
29
30
31
}

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

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

35
            "mocker" => Ok(Output::Mocker),
36
            "echo" | "echo_full" => Ok(Output::Echo),
37

38
            "dyn" | "auto" => Ok(Output::Auto),
39

40
            endpoint_path if endpoint_path.starts_with(ENDPOINT_SCHEME) => {
41
42
                let path = endpoint_path.strip_prefix(ENDPOINT_SCHEME).unwrap();
                Ok(Output::Static(path.to_string()))
43
44
            }

45
46
47
48
49
50
51
52
            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 {
53
54
55
            #[cfg(feature = "mistralrs")]
            Output::MistralRs => "mistralrs",

56
            Output::Mocker => "mocker",
57
            Output::Echo => "echo",
58

59
60
            Output::Auto => "auto",
            Output::Static(endpoint) => &format!("{ENDPOINT_SCHEME}{endpoint}"),
61
62
63
64
        };
        write!(f, "{s}")
    }
}
65

66
67
68
impl Output {
    #[allow(unused_mut)]
    pub fn available_engines() -> Vec<String> {
69
        let mut out = vec!["echo".to_string(), Output::Mocker.to_string()];
70
71
72
73
74
75
76
        #[cfg(feature = "mistralrs")]
        {
            out.push(Output::MistralRs.to_string());
        }
        out
    }
}