"segmentation/mmseg_custom/vscode:/vscode.git/clone" did not exist on "4bbef5094fb2065658e66b40f5d387850b4262ee"
opt.rs 3.11 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

18
19
use crate::ENDPOINT_SCHEME;

20
21
22
23
24
25
pub enum Input {
    /// Run an OpenAI compatible HTTP server
    Http,

    /// Read prompt from stdin
    Text,
26
27
28

    /// Pull requests from a namespace/component/endpoint path.
    Endpoint(String),
29
30
31
32
33
34
35
36
37
}

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

    fn try_from(s: &str) -> anyhow::Result<Self> {
        match s {
            "http" => Ok(Input::Http),
            "text" => Ok(Input::Text),
38
39
40
41
            endpoint_path if endpoint_path.starts_with(ENDPOINT_SCHEME) => {
                let path = endpoint_path.strip_prefix(ENDPOINT_SCHEME).unwrap();
                Ok(Input::Endpoint(path.to_string()))
            }
42
43
44
45
46
47
48
49
50
51
            e => Err(anyhow::anyhow!("Invalid in= option '{e}'")),
        }
    }
}

impl fmt::Display for Input {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let s = match self {
            Input::Http => "http",
            Input::Text => "text",
52
            Input::Endpoint(path) => path,
53
54
55
56
57
58
59
60
        };
        write!(f, "{s}")
    }
}

pub enum Output {
    /// Accept un-preprocessed requests, echo the prompt back as the response
    EchoFull,
61

62
63
64
    /// Accept preprocessed requests, echo the tokens back as the response
    EchoCore,

65
66
67
    /// Publish requests to a namespace/component/endpoint path.
    Endpoint(String),

68
69
70
    #[cfg(feature = "mistralrs")]
    /// Run inference on a model in a GGUF file using mistralrs w/ candle
    MistralRs,
71
72
73
74
75
76
77
}

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

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

81
            "echo_full" => Ok(Output::EchoFull),
82
            "echo_core" => Ok(Output::EchoCore),
83
84
85
86
87
88

            endpoint_path if endpoint_path.starts_with(ENDPOINT_SCHEME) => {
                let path = endpoint_path.strip_prefix(ENDPOINT_SCHEME).unwrap();
                Ok(Output::Endpoint(path.to_string()))
            }

89
90
91
92
93
94
95
96
            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 {
97
98
99
            #[cfg(feature = "mistralrs")]
            Output::MistralRs => "mistralrs",

100
            Output::EchoFull => "echo_full",
101
            Output::EchoCore => "echo_core",
102
103

            Output::Endpoint(path) => path,
104
105
106
107
        };
        write!(f, "{s}")
    }
}