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    pub openai_api_url: String,
 59}
 60
 61/// Assistant panel settings
 62#[derive(Clone, Default, Serialize, Deserialize, JsonSchema, Debug)]
 63pub struct AssistantSettingsContent {
 64    /// Whether to show the assistant panel button in the status bar.
 65    ///
 66    /// Default: true
 67    pub button: Option<bool>,
 68    /// Where to dock the assistant.
 69    ///
 70    /// Default: right
 71    pub dock: Option<AssistantDockPosition>,
 72    /// Default width in pixels when the assistant is docked to the left or right.
 73    ///
 74    /// Default: 640
 75    pub default_width: Option<f32>,
 76    /// Default height in pixels when the assistant is docked to the bottom.
 77    ///
 78    /// Default: 320
 79    pub default_height: Option<f32>,
 80    /// The default OpenAI model to use when starting new conversations.
 81    ///
 82    /// Default: gpt-4-1106-preview
 83    pub default_open_ai_model: Option<OpenAiModel>,
 84    /// OpenAI API base URL to use when starting new conversations.
 85    ///
 86    /// Default: https://api.openai.com/v1
 87    pub openai_api_url: Option<String>,
 88}
 89
 90impl Settings for AssistantSettings {
 91    const KEY: Option<&'static str> = Some("assistant");
 92
 93    type FileContent = AssistantSettingsContent;
 94
 95    fn load(
 96        default_value: &Self::FileContent,
 97        user_values: &[&Self::FileContent],
 98        _: &mut gpui::AppContext,
 99    ) -> anyhow::Result<Self> {
100        Self::load_via_json_merge(default_value, user_values)
101    }
102}