ai_chain_glm/chatgpt/
model.rs

1use ai_chain::options::{ModelRef, Opt};
2use serde::{Deserialize, Serialize};
3use strum_macros::{EnumIter,EnumString};
4
5/// The `Model` enum represents the available ChatGPT models that you can use through the OpenAI
6/// API.
7///
8/// These models have different capabilities and performance characteristics, allowing you to choose
9/// the one that best suits your needs. See <https://platform.openai.com/docs/models> for more
10/// information.
11///
12/// # Example
13///
14/// ```
15/// use ai_chain_glm::chatgpt::Model;
16///
17/// let turbo_model = Model::default();
18/// let custom_model = Model::Other("your_custom_model_name".to_string());
19/// ```
20
21#[derive(EnumIter,Debug,Default, Clone, Serialize, Deserialize, EnumString, PartialEq, Eq)]
22#[non_exhaustive]
23pub enum Model {
24    /// A high-performance and versatile model from the "moonshot" series.
25    #[strum(serialize = "glm-4")]
26    #[default]
27    GLM4,
28    #[strum(serialize = "glm-4v")]
29    GLM4V,
30    #[strum(serialize = "glm-3-turbo")]
31    GLM3Turbo,
32
33
34    // ... 你可以继续添加更多的 "moonshot" 模型 ...
35
36    /// A variant that allows you to specify a custom model name as a string,
37    /// in case new models are introduced or you have access to specialized models.
38    #[strum(default)]
39    Other(String),
40}
41impl Model {
42
43}
44
45impl ToString for Model {
46    fn to_string(&self) -> String {
47        match &self {
48            Model::GLM4 => "glm-4".to_string(),
49            Model::GLM4V => "glm-4v".to_string(),
50            Model::GLM3Turbo => "glm-3-turbo".to_string(),
51
52            Model::Other(model) => model.to_string(),
53        }
54    }
55}
56
57
58
59/// Conversion from Model to ModelRef
60impl From<Model> for ModelRef {
61    fn from(value: Model) -> Self {
62        ModelRef::from_model_name(value.to_string())
63    }
64}
65
66/// Conversion from Model to Option
67impl From<Model> for Opt {
68    fn from(value: Model) -> Self {
69        Opt::Model(value.into())
70    }
71}
72
73#[cfg(test)]
74mod tests {
75    use std::str::FromStr;
76    use strum::IntoEnumIterator;
77
78    use super::*;
79
80    // Tests for FromStr
81    #[test]
82    fn test_from_str() -> Result<(), Box<dyn std::error::Error>> {
83        // Model::iter()
84        let model_names =  Model::iter().map(|model| model.to_string()).collect::<Vec<String>>();
85        println!("{:?}", model_names);
86        Ok(())
87    }
88
89    // Test ToString
90    #[test]
91    fn test_to_string() {
92
93    }
94
95    #[test]
96    #[allow(deprecated)]
97    fn test_to_string_deprecated() {
98
99    }
100}