This commit is contained in:
@@ -4,3 +4,4 @@
|
|||||||
Cargo.lock
|
Cargo.lock
|
||||||
*.pkg.tar.zst
|
*.pkg.tar.zst
|
||||||
/pkg
|
/pkg
|
||||||
|
/.config
|
||||||
|
|||||||
@@ -124,37 +124,6 @@ impl MainEditor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_ui(&mut self, project: &mut ProjectSettings, ui: &mut egui::Ui) {
|
pub fn render_ui(&mut self, project: &mut ProjectSettings, ui: &mut egui::Ui) {
|
||||||
if let Some(dialog) = &mut self.dialog {
|
|
||||||
dialog.ui(ui, project);
|
|
||||||
|
|
||||||
match dialog {
|
|
||||||
ContentAI::Summarise { ready, result, .. } => {
|
|
||||||
if *ready.lock().unwrap() == ReadyState::Ready {
|
|
||||||
self.content.content.push_str(&result.lock().unwrap());
|
|
||||||
self.content.saved = false;
|
|
||||||
*ready.lock().unwrap() = ReadyState::Idle;
|
|
||||||
} else if *ready.lock().unwrap() == ReadyState::Halted {
|
|
||||||
*ready.lock().unwrap() = ReadyState::Idle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ContentAI::Continue {
|
|
||||||
ready,
|
|
||||||
result,
|
|
||||||
content,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
*content = self.content.content.clone();
|
|
||||||
if *ready.lock().unwrap() == ReadyState::Ready {
|
|
||||||
self.content.content.push_str(&result.lock().unwrap());
|
|
||||||
self.content.saved = false;
|
|
||||||
*ready.lock().unwrap() = ReadyState::Idle;
|
|
||||||
} else if *ready.lock().unwrap() == ReadyState::Halted {
|
|
||||||
*ready.lock().unwrap() = ReadyState::Idle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.vertical(|ui| {
|
ui.vertical(|ui| {
|
||||||
// check for Ctrl+S to save
|
// check for Ctrl+S to save
|
||||||
if ui.input(|i| i.key_pressed(egui::Key::S) && i.modifiers.ctrl) {
|
if ui.input(|i| i.key_pressed(egui::Key::S) && i.modifiers.ctrl) {
|
||||||
@@ -253,6 +222,21 @@ impl MainEditor {
|
|||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
|
if let Some(dialog) = &mut self.dialog {
|
||||||
|
dialog.ui(ui, project);
|
||||||
|
|
||||||
|
dialog.content = self.content.content.clone();
|
||||||
|
if *dialog.ready.lock().unwrap() == ReadyState::Ready {
|
||||||
|
self.content
|
||||||
|
.content
|
||||||
|
.push_str(&dialog.result.lock().unwrap());
|
||||||
|
self.content.saved = false;
|
||||||
|
*dialog.ready.lock().unwrap() = ReadyState::Idle;
|
||||||
|
} else if *dialog.ready.lock().unwrap() == ReadyState::Halted {
|
||||||
|
*dialog.ready.lock().unwrap() = ReadyState::Idle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if self.show_preview {
|
if self.show_preview {
|
||||||
self.preview_ui(ui);
|
self.preview_ui(ui);
|
||||||
}
|
}
|
||||||
@@ -356,17 +340,8 @@ impl MainEditor {
|
|||||||
|
|
||||||
ui.menu_button("AI Actions", |ui| {
|
ui.menu_button("AI Actions", |ui| {
|
||||||
ui.add_enabled_ui(project.ai_enabled(), |ui| {
|
ui.add_enabled_ui(project.ai_enabled(), |ui| {
|
||||||
if ui.button("Summarise").clicked() {
|
if ui.button("AI Assistant").clicked() {
|
||||||
self.dialog = Some(ContentAI::Summarise {
|
self.dialog = Some(ContentAI {
|
||||||
result: Arc::new(Mutex::new(String::new())),
|
|
||||||
content: self.content.content.clone(),
|
|
||||||
open: true,
|
|
||||||
ready: Arc::new(Mutex::new(ReadyState::Idle)),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if ui.button("Continue").clicked() {
|
|
||||||
self.dialog = Some(ContentAI::Continue {
|
|
||||||
content: self.content.content.clone(),
|
content: self.content.content.clone(),
|
||||||
instruction: String::new(),
|
instruction: String::new(),
|
||||||
max_tokens: 1024,
|
max_tokens: 1024,
|
||||||
|
|||||||
@@ -8,100 +8,32 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::editors::settings_editor::ProjectSettings;
|
use crate::editors::settings_editor::ProjectSettings;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum ContentAI {
|
pub struct ContentAI {
|
||||||
Summarise {
|
pub open: bool,
|
||||||
open: bool,
|
pub content: String,
|
||||||
content: String,
|
pub instruction: String,
|
||||||
result: Arc<Mutex<String>>,
|
pub max_tokens: usize,
|
||||||
ready: Arc<Mutex<ReadyState>>,
|
pub context_override: String,
|
||||||
},
|
pub result: Arc<Mutex<String>>,
|
||||||
Continue {
|
pub ready: Arc<Mutex<ReadyState>>,
|
||||||
open: bool,
|
pub temperature: f32,
|
||||||
content: String,
|
pub reasoning_effort: ReasoningEffort,
|
||||||
instruction: String,
|
pub model_override: String,
|
||||||
max_tokens: usize,
|
|
||||||
context_override: String,
|
|
||||||
result: Arc<Mutex<String>>,
|
|
||||||
ready: Arc<Mutex<ReadyState>>,
|
|
||||||
temperature: f32,
|
|
||||||
reasoning_effort: ReasoningEffort,
|
|
||||||
model_override: String,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ContentAI {
|
impl ContentAI {
|
||||||
pub fn ui(&mut self, ui: &mut egui::Ui, project: &mut ProjectSettings) {
|
pub fn ui(&mut self, ui: &mut egui::Ui, project: &mut ProjectSettings) {
|
||||||
let mut is_open = *match self {
|
let is_open = self.open;
|
||||||
ContentAI::Summarise { open, .. } => open,
|
|
||||||
ContentAI::Continue { open, .. } => open,
|
|
||||||
};
|
|
||||||
|
|
||||||
if is_open {
|
if is_open {
|
||||||
egui::Window::new("AI Assistant")
|
egui::SidePanel::right("ai_assistant").show_inside(ui, |ui| {
|
||||||
.open(&mut is_open)
|
Self::ui_continue(self, ui, project);
|
||||||
.show(ui.ctx(), |ui| match self {
|
});
|
||||||
ContentAI::Summarise { .. } => {
|
|
||||||
Self::ui_summarise(self, ui, project);
|
|
||||||
}
|
|
||||||
ContentAI::Continue { .. } => {
|
|
||||||
Self::ui_continue(self, ui, project);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
match self {
|
|
||||||
ContentAI::Summarise { open, .. } => *open = is_open,
|
|
||||||
ContentAI::Continue { open, .. } => *open = is_open,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn ui_summarise(&mut self, ui: &mut egui::Ui, _project: &mut ProjectSettings) {
|
|
||||||
if let ContentAI::Summarise {
|
|
||||||
content,
|
|
||||||
result,
|
|
||||||
ready,
|
|
||||||
..
|
|
||||||
} = self
|
|
||||||
{
|
|
||||||
egui::ScrollArea::vertical()
|
|
||||||
.id_salt("summarise")
|
|
||||||
.auto_shrink([false, false])
|
|
||||||
.max_width(ui.available_width())
|
|
||||||
.show(ui, |ui| {
|
|
||||||
ui.add(
|
|
||||||
egui::TextEdit::multiline(content)
|
|
||||||
.frame(false)
|
|
||||||
.interactive(false),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
ui.add(
|
|
||||||
egui::TextEdit::multiline(&mut *result.lock().unwrap())
|
|
||||||
.font(egui::TextStyle::Monospace)
|
|
||||||
.interactive(false)
|
|
||||||
.frame(false)
|
|
||||||
.lock_focus(true)
|
|
||||||
.hint_text("Summary will appear here..."),
|
|
||||||
);
|
|
||||||
if ui.button("Summarise").clicked() {
|
|
||||||
// Self::summarise(content, result.clone());
|
|
||||||
*ready.lock().unwrap() = ReadyState::Generating;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
self.open = is_open;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ui_continue(&mut self, ui: &mut egui::Ui, project: &mut ProjectSettings) {
|
fn ui_continue(&mut self, ui: &mut egui::Ui, project: &mut ProjectSettings) {
|
||||||
if let ContentAI::Continue {
|
|
||||||
content,
|
|
||||||
instruction,
|
|
||||||
max_tokens,
|
|
||||||
context_override,
|
|
||||||
result,
|
|
||||||
ready,
|
|
||||||
temperature,
|
|
||||||
model_override,
|
|
||||||
reasoning_effort,
|
|
||||||
..
|
|
||||||
} = self
|
|
||||||
{
|
{
|
||||||
ui.weak("(The model will see current file content)");
|
ui.weak("(The model will see current file content)");
|
||||||
ui.separator();
|
ui.separator();
|
||||||
@@ -114,7 +46,7 @@ impl ContentAI {
|
|||||||
.max_width(ui.available_width())
|
.max_width(ui.available_width())
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::TextEdit::multiline(instruction)
|
egui::TextEdit::multiline(&mut self.instruction)
|
||||||
.frame(false)
|
.frame(false)
|
||||||
.desired_width(ui.available_width())
|
.desired_width(ui.available_width())
|
||||||
.hint_text("Writing Instructions"),
|
.hint_text("Writing Instructions"),
|
||||||
@@ -130,7 +62,7 @@ impl ContentAI {
|
|||||||
.max_width(ui.available_width())
|
.max_width(ui.available_width())
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::TextEdit::multiline(context_override)
|
egui::TextEdit::multiline(&mut self.context_override)
|
||||||
.frame(false)
|
.frame(false)
|
||||||
.desired_width(ui.available_width())
|
.desired_width(ui.available_width())
|
||||||
.hint_text("Any additional context?"),
|
.hint_text("Any additional context?"),
|
||||||
@@ -144,7 +76,7 @@ impl ContentAI {
|
|||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.label("Max Tokens");
|
ui.label("Max Tokens");
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::DragValue::new(max_tokens)
|
egui::DragValue::new(&mut self.max_tokens)
|
||||||
.range(128..=u32::MAX)
|
.range(128..=u32::MAX)
|
||||||
.speed(128),
|
.speed(128),
|
||||||
);
|
);
|
||||||
@@ -152,7 +84,7 @@ impl ContentAI {
|
|||||||
|
|
||||||
ui.label("Temperature");
|
ui.label("Temperature");
|
||||||
ui.add(
|
ui.add(
|
||||||
egui::DragValue::new(temperature)
|
egui::DragValue::new(&mut self.temperature)
|
||||||
.range(0.0..=2.0)
|
.range(0.0..=2.0)
|
||||||
.speed(0.1),
|
.speed(0.1),
|
||||||
);
|
);
|
||||||
@@ -160,51 +92,58 @@ impl ContentAI {
|
|||||||
ui.label("Reasoning effort");
|
ui.label("Reasoning effort");
|
||||||
|
|
||||||
egui::ComboBox::from_id_salt("reasoning_effort")
|
egui::ComboBox::from_id_salt("reasoning_effort")
|
||||||
.selected_text(reasoning_effort.to_string())
|
.selected_text(self.reasoning_effort.to_string())
|
||||||
.show_ui(ui, |ui| {
|
.show_ui(ui, |ui| {
|
||||||
ui.selectable_value(
|
ui.selectable_value(
|
||||||
reasoning_effort,
|
&mut self.reasoning_effort,
|
||||||
ReasoningEffort::Minimal,
|
ReasoningEffort::Minimal,
|
||||||
"Minimal",
|
"Minimal",
|
||||||
);
|
);
|
||||||
ui.selectable_value(reasoning_effort, ReasoningEffort::Low, "Low");
|
|
||||||
ui.selectable_value(
|
ui.selectable_value(
|
||||||
reasoning_effort,
|
&mut self.reasoning_effort,
|
||||||
|
ReasoningEffort::Low,
|
||||||
|
"Low",
|
||||||
|
);
|
||||||
|
ui.selectable_value(
|
||||||
|
&mut self.reasoning_effort,
|
||||||
ReasoningEffort::Medium,
|
ReasoningEffort::Medium,
|
||||||
"Medium",
|
"Medium",
|
||||||
);
|
);
|
||||||
ui.selectable_value(reasoning_effort, ReasoningEffort::High, "High");
|
ui.selectable_value(
|
||||||
|
&mut self.reasoning_effort,
|
||||||
|
ReasoningEffort::High,
|
||||||
|
"High",
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
|
|
||||||
ui.label("Model override");
|
ui.label("Model override");
|
||||||
ui.add(egui::TextEdit::singleline(model_override));
|
ui.add(egui::TextEdit::singleline(&mut self.model_override));
|
||||||
ui.end_row();
|
ui.end_row();
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
ui.separator();
|
||||||
|
|
||||||
let mut ready_lock = ready.lock().unwrap();
|
let mut ready_lock = self.ready.lock().unwrap();
|
||||||
|
|
||||||
match *ready_lock {
|
match *ready_lock {
|
||||||
ReadyState::Idle => {
|
ReadyState::Idle => {
|
||||||
let continue_content = || {
|
let continue_content = || {
|
||||||
let context_override = context_override.clone();
|
let context_override = self.context_override.clone();
|
||||||
let content = content.clone();
|
let content = self.content.clone();
|
||||||
let instruction = instruction.clone();
|
let instruction = self.instruction.clone();
|
||||||
let project = project.clone();
|
let project = project.clone();
|
||||||
let ai_context = project.ai_context.clone();
|
let ai_context = project.ai_context.clone();
|
||||||
let result = result.clone();
|
let result = self.result.clone();
|
||||||
let ready = ready.clone();
|
let ready = self.ready.clone();
|
||||||
let reasoning_effort = reasoning_effort;
|
|
||||||
|
|
||||||
let options = AIOptions {
|
let options = AIOptions {
|
||||||
max_completion_tokens: *max_tokens,
|
max_completion_tokens: self.max_tokens,
|
||||||
reasoning_effort: *reasoning_effort,
|
reasoning_effort: self.reasoning_effort,
|
||||||
temperature: *temperature,
|
temperature: self.temperature,
|
||||||
model_override: if !model_override.is_empty() {
|
model_override: if !self.model_override.is_empty() {
|
||||||
Some(model_override.clone())
|
Some(self.model_override.clone())
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
},
|
},
|
||||||
@@ -254,34 +193,38 @@ impl ContentAI {
|
|||||||
ReadyState::Ready => {}
|
ReadyState::Ready => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
egui::ScrollArea::both()
|
egui::TopBottomPanel::bottom("llm_output")
|
||||||
.auto_shrink([true, true])
|
.resizable(true)
|
||||||
.id_salt("llm_output")
|
.show_inside(ui, |ui| {
|
||||||
.max_width(ui.available_width())
|
egui::ScrollArea::both()
|
||||||
.max_height(ui.available_height() / 4.0)
|
.auto_shrink([false, false])
|
||||||
.show(ui, |ui| {
|
.id_salt("llm_output")
|
||||||
ui.add(
|
.max_width(ui.available_width())
|
||||||
egui::TextEdit::multiline(&mut *result.lock().unwrap())
|
// .max_height(ui.available_height() / 3.0)
|
||||||
.font(egui::TextStyle::Monospace)
|
.show(ui, |ui| {
|
||||||
.interactive(false)
|
ui.add(
|
||||||
.desired_rows(0)
|
egui::TextEdit::multiline(&mut *self.result.lock().unwrap())
|
||||||
.frame(false)
|
.font(egui::TextStyle::Monospace)
|
||||||
.desired_width(ui.available_width())
|
.interactive(false)
|
||||||
.lock_focus(true)
|
.desired_rows(0)
|
||||||
.hint_text("Content will appear here..."),
|
.frame(false)
|
||||||
);
|
.desired_width(ui.available_width())
|
||||||
|
.lock_focus(true)
|
||||||
|
.hint_text("Content will appear here..."),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Insert").clicked() {
|
||||||
|
*ready_lock = ReadyState::Ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ui.button("Clear").clicked() {
|
||||||
|
self.result.lock().unwrap().clear();
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.separator();
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if ui.button("Insert").clicked() {
|
|
||||||
*ready_lock = ReadyState::Ready;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ui.button("Clear").clicked() {
|
|
||||||
result.lock().unwrap().clear();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user