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