assistant_settings.rs

 1use anyhow;
 2use schemars::JsonSchema;
 3use serde::{Deserialize, Serialize};
 4use settings::Setting;
 5
 6#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)]
 7pub enum OpenAIModel {
 8    #[serde(rename = "gpt-3.5-turbo-0613")]
 9    ThreePointFiveTurbo,
10    #[serde(rename = "gpt-4-0613")]
11    Four,
12}
13
14impl OpenAIModel {
15    pub fn full_name(&self) -> &'static str {
16        match self {
17            OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo-0613",
18            OpenAIModel::Four => "gpt-4-0613",
19        }
20    }
21
22    pub fn short_name(&self) -> &'static str {
23        match self {
24            OpenAIModel::ThreePointFiveTurbo => "gpt-3.5-turbo",
25            OpenAIModel::Four => "gpt-4",
26        }
27    }
28
29    pub fn cycle(&self) -> Self {
30        match self {
31            OpenAIModel::ThreePointFiveTurbo => OpenAIModel::Four,
32            OpenAIModel::Four => OpenAIModel::ThreePointFiveTurbo,
33        }
34    }
35}
36
37#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
38#[serde(rename_all = "snake_case")]
39pub enum AssistantDockPosition {
40    Left,
41    Right,
42    Bottom,
43}
44
45#[derive(Deserialize, Debug)]
46pub struct AssistantSettings {
47    pub button: bool,
48    pub dock: AssistantDockPosition,
49    pub default_width: f32,
50    pub default_height: f32,
51    pub default_open_ai_model: OpenAIModel,
52}
53
54#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
55pub struct AssistantSettingsContent {
56    pub button: Option<bool>,
57    pub dock: Option<AssistantDockPosition>,
58    pub default_width: Option<f32>,
59    pub default_height: Option<f32>,
60    pub default_open_ai_model: Option<OpenAIModel>,
61}
62
63impl Setting for AssistantSettings {
64    const KEY: Option<&'static str> = Some("assistant");
65
66    type FileContent = AssistantSettingsContent;
67
68    fn load(
69        default_value: &Self::FileContent,
70        user_values: &[&Self::FileContent],
71        _: &gpui::AppContext,
72    ) -> anyhow::Result<Self> {
73        Self::load_via_json_merge(default_value, user_values)
74    }
75}