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