assistant_settings.rs

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