1pub mod assistant;
2mod assistant_settings;
3
4pub use assistant::AssistantPanel;
5use gpui::{actions, AppContext};
6use serde::{Deserialize, Serialize};
7
8actions!(ai, [Assist]);
9
10// Data types for chat completion requests
11#[derive(Serialize)]
12struct OpenAIRequest {
13 model: String,
14 messages: Vec<RequestMessage>,
15 stream: bool,
16}
17
18#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
19struct RequestMessage {
20 role: Role,
21 content: String,
22}
23
24#[derive(Serialize, Deserialize, Debug, Eq, PartialEq)]
25struct ResponseMessage {
26 role: Option<Role>,
27 content: Option<String>,
28}
29
30#[derive(Clone, Copy, Serialize, Deserialize, Debug, Eq, PartialEq)]
31#[serde(rename_all = "lowercase")]
32enum Role {
33 User,
34 Assistant,
35 System,
36}
37
38#[derive(Deserialize, Debug)]
39struct OpenAIResponseStreamEvent {
40 pub id: Option<String>,
41 pub object: String,
42 pub created: u32,
43 pub model: String,
44 pub choices: Vec<ChatChoiceDelta>,
45 pub usage: Option<Usage>,
46}
47
48#[derive(Deserialize, Debug)]
49struct Usage {
50 pub prompt_tokens: u32,
51 pub completion_tokens: u32,
52 pub total_tokens: u32,
53}
54
55#[derive(Deserialize, Debug)]
56struct ChatChoiceDelta {
57 pub index: u32,
58 pub delta: ResponseMessage,
59 pub finish_reason: Option<String>,
60}
61
62#[derive(Deserialize, Debug)]
63struct OpenAIUsage {
64 prompt_tokens: u64,
65 completion_tokens: u64,
66 total_tokens: u64,
67}
68
69#[derive(Deserialize, Debug)]
70struct OpenAIChoice {
71 text: String,
72 index: u32,
73 logprobs: Option<serde_json::Value>,
74 finish_reason: Option<String>,
75}
76
77pub fn init(cx: &mut AppContext) {
78 assistant::init(cx);
79}