Add prompt input
This commit is contained in:
parent
56efe5fb5c
commit
eb2a0d12c4
@ -1,9 +1,9 @@
|
||||
use eframe::egui;
|
||||
use model_response::ModelResponse;
|
||||
use state::AppState;
|
||||
|
||||
pub mod model_response;
|
||||
pub mod model_selection;
|
||||
pub mod prompt_input;
|
||||
pub mod state;
|
||||
|
||||
pub fn main() -> eframe::Result {
|
||||
@ -25,37 +25,18 @@ impl eframe::App for AppState {
|
||||
ui.heading("Groq Model Comparison");
|
||||
ui.label("Compare Groq models with ease!");
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
let counter_color = match self.counter {
|
||||
0 => egui::Color32::WHITE,
|
||||
_ if self.counter > 0 => egui::Color32::GREEN,
|
||||
_ => egui::Color32::RED,
|
||||
};
|
||||
|
||||
ui.label("Counter:");
|
||||
ui.label(egui::RichText::new(format!("{}", self.counter)).color(counter_color));
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
if ui.button("Increment").clicked() {
|
||||
self.counter += 1;
|
||||
}
|
||||
|
||||
if ui.button("Decrement").clicked() {
|
||||
self.counter -= 1;
|
||||
}
|
||||
});
|
||||
|
||||
ui.add(model_selection::ModelSelection::new(
|
||||
self,
|
||||
vec!["Model 1".to_string(), "Model 2".to_string()],
|
||||
));
|
||||
|
||||
ui.add(ModelResponse::new(
|
||||
"This is a test message".to_string(),
|
||||
200,
|
||||
100,
|
||||
));
|
||||
ui.add(prompt_input::PromptInput::new(self));
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
for model in &self.selected_models {
|
||||
ui.vertical(|ui| ui.add(model));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
use eframe::egui::{self, Response, Ui, Widget};
|
||||
|
||||
pub struct ModelResponse {
|
||||
pub name: String,
|
||||
pub message: String,
|
||||
pub status: i32,
|
||||
pub time: i32,
|
||||
}
|
||||
|
||||
impl ModelResponse {
|
||||
pub fn new(message: String, status: i32, time: i32) -> Self {
|
||||
pub fn new(name: String, message: String, status: i32, time: i32) -> Self {
|
||||
Self {
|
||||
name,
|
||||
message,
|
||||
status,
|
||||
time,
|
||||
@ -16,7 +18,7 @@ impl ModelResponse {
|
||||
}
|
||||
}
|
||||
|
||||
impl Widget for ModelResponse {
|
||||
impl Widget for &ModelResponse {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
egui::Frame::none()
|
||||
.inner_margin(8.0)
|
||||
@ -24,13 +26,17 @@ impl Widget for ModelResponse {
|
||||
.fill(egui::Color32::DARK_GRAY)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Status:");
|
||||
ui.label(self.status.to_string());
|
||||
});
|
||||
ui.label(&self.name);
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Time:");
|
||||
ui.label(self.time.to_string());
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Status:");
|
||||
ui.label(self.status.to_string());
|
||||
});
|
||||
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Time:");
|
||||
ui.label(self.time.to_string());
|
||||
});
|
||||
});
|
||||
|
||||
egui::Frame::none()
|
||||
@ -38,7 +44,7 @@ impl Widget for ModelResponse {
|
||||
.rounding(4.0)
|
||||
.fill(egui::Color32::WHITE)
|
||||
.show(ui, |ui| {
|
||||
ui.label(egui::RichText::new(self.message).color(egui::Color32::BLACK));
|
||||
ui.label(egui::RichText::new(&self.message).color(egui::Color32::BLACK));
|
||||
});
|
||||
})
|
||||
.response
|
||||
|
@ -1,6 +1,6 @@
|
||||
use eframe::egui::{self, Response, Ui, Widget};
|
||||
|
||||
use super::state::AppState;
|
||||
use super::{model_response::ModelResponse, state::AppState};
|
||||
|
||||
pub struct ModelSelection<'a> {
|
||||
app_state: &'a mut AppState,
|
||||
@ -23,35 +23,46 @@ impl<'a> Widget for ModelSelection<'a> {
|
||||
.selected_text("Models")
|
||||
.show_ui(ui, |ui| {
|
||||
for model in self.models_available {
|
||||
let contained = self.app_state.model_selection.contains(&model);
|
||||
let selected_models = self
|
||||
.app_state
|
||||
.selected_models
|
||||
.iter()
|
||||
.map(|m| m.name.clone())
|
||||
.collect::<Vec<String>>();
|
||||
let contained = selected_models.contains(&model);
|
||||
|
||||
let label = ui.selectable_label(contained, &model);
|
||||
|
||||
if label.clicked() && !contained {
|
||||
self.app_state.model_selection.push(model.clone());
|
||||
self.app_state.selected_models.push(ModelResponse {
|
||||
name: model.clone(),
|
||||
message: "No message".to_string(),
|
||||
status: 0,
|
||||
time: 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let mut model_to_remove: Option<String> = None;
|
||||
|
||||
for model in &self.app_state.model_selection {
|
||||
for model in &self.app_state.selected_models {
|
||||
egui::Frame::none()
|
||||
.inner_margin(8.0)
|
||||
.rounding(4.0)
|
||||
.fill(egui::Color32::WHITE)
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal(|ui| {
|
||||
ui.label(model);
|
||||
ui.label(model.name.clone());
|
||||
if ui.button("X").clicked() {
|
||||
model_to_remove.replace(model.clone());
|
||||
model_to_remove.replace(model.name.clone());
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
if let Some(model) = model_to_remove {
|
||||
self.app_state.model_selection.retain(|m| m != &model);
|
||||
self.app_state.selected_models.retain(|m| m.name != model);
|
||||
}
|
||||
})
|
||||
.response
|
||||
|
29
rust-learning/src/gui/prompt_input.rs
Normal file
29
rust-learning/src/gui/prompt_input.rs
Normal file
@ -0,0 +1,29 @@
|
||||
use eframe::egui::{Response, Ui, Widget};
|
||||
|
||||
use super::state::AppState;
|
||||
|
||||
pub struct PromptInput<'a> {
|
||||
app_state: &'a mut AppState,
|
||||
}
|
||||
|
||||
impl<'a> PromptInput<'a> {
|
||||
pub fn new(app_state: &'a mut AppState) -> Self {
|
||||
Self { app_state }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Widget for PromptInput<'a> {
|
||||
fn ui(self, ui: &mut Ui) -> Response {
|
||||
ui.horizontal(|ui| {
|
||||
let label = ui.label("Prompt:");
|
||||
ui.text_edit_singleline(&mut self.app_state.prompt_input)
|
||||
.labelled_by(label.id);
|
||||
|
||||
if ui.button("Submit").clicked() {
|
||||
self.app_state.prompt_input.clear();
|
||||
}
|
||||
});
|
||||
|
||||
ui.label(&self.app_state.prompt_input)
|
||||
}
|
||||
}
|
@ -1,15 +1,17 @@
|
||||
use eframe::CreationContext;
|
||||
|
||||
use super::model_response::ModelResponse;
|
||||
|
||||
pub struct AppState {
|
||||
pub counter: i32,
|
||||
pub model_selection: Vec<String>,
|
||||
pub selected_models: Vec<ModelResponse>,
|
||||
pub prompt_input: String,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(_cc: &CreationContext<'_>) -> Self {
|
||||
Self {
|
||||
counter: 0,
|
||||
model_selection: vec![],
|
||||
selected_models: vec![],
|
||||
prompt_input: String::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user