Skip to content

Commit 0bddb60

Browse files
authored
Merge pull request #59 from dezoito/feature/experiment
Feature/experiment
2 parents aa54b35 + 3bf7e59 commit 0bddb60

15 files changed

+252
-303
lines changed

bun.lockb

414 Bytes
Binary file not shown.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"react-hook-form": "^7.49.3",
4444
"react-hotkeys-hook": "^4.5.0",
4545
"tailwind-merge": "^2.2.0",
46+
"tailwind-scrollbar": "^3.1.0",
4647
"tailwindcss": "^3.4.1",
4748
"tailwindcss-animate": "^1.0.7",
4849
"uuid": "^9.0.1",

src-tauri/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ edition = "2021"
1313
tauri-build = { version = "1.5", features = [] }
1414

1515
[dependencies]
16-
tauri = { version = "1.6", features = [ "fs-all", "dialog-all", "shell-open"] }
16+
tauri = { version = "1.6", features = [ "path-all", "fs-all", "dialog-all", "shell-open"] }
1717
serde = { version = "1.0", features = ["derive"] }
1818
serde_json = "1.0"
1919
anyhow = "1.0.79"
@@ -27,6 +27,7 @@ ollama-rs = { version = "0.2.0", default-features = false, features = ["rustls"]
2727
chrono = "0.4.38"
2828
reqwest = {version = "0.12.4", features = ["blocking", "json", "rustls-tls"], default-features = false }
2929
sqlx = { version = "0.8.1", features = ["runtime-tokio", "sqlite", "chrono"] }
30+
eff-wordlist = "1.0.3"
3031

3132
[features]
3233
# this feature is used for production builds or when `devPath` points to the filesystem
Lines changed: 33 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,42 @@
11
use grid_search_desktop::{Error, ExperimentFile};
2-
use std::fs;
32

4-
#[tauri::command]
5-
pub fn get_experiments(app_handle: tauri::AppHandle) -> Result<Vec<ExperimentFile>, Error> {
6-
let binding = app_handle.path_resolver().app_data_dir().unwrap();
7-
let app_data_dir = binding.to_str().unwrap();
8-
let mut files: Vec<ExperimentFile> = fs::read_dir(app_data_dir)?
9-
.filter_map(Result::ok)
10-
.filter_map(|entry| {
11-
let path = entry.path();
12-
if path.extension().unwrap_or_default() != "json" {
13-
return None;
14-
}
15-
let metadata = fs::metadata(&path).ok()?;
16-
let created = metadata.created().ok()?;
17-
let contents = fs::read_to_string(&path).ok()?;
18-
Some(ExperimentFile {
19-
name: path.file_name()?.to_string_lossy().into_owned(),
20-
created,
21-
contents,
22-
})
23-
})
24-
.collect();
3+
use crate::db::DatabaseState;
254

26-
files.sort_by_key(|file| file.created);
27-
files.reverse();
28-
Ok(files)
5+
#[tauri::command]
6+
pub async fn get_experiments(
7+
state: tauri::State<'_, DatabaseState>,
8+
) -> Result<Vec<ExperimentFile>, Error> {
9+
let stmt = r#"
10+
SELECT
11+
name,
12+
created,
13+
contents
14+
FROM experiments
15+
ORDER BY id DESC
16+
"#;
17+
18+
let query = sqlx::query_as::<_, ExperimentFile>(stmt);
19+
let pool = &state.0;
20+
let experiments = query.fetch_all(pool).await?;
21+
22+
println!("\nRetrieved {} experiments:", experiments.len());
23+
Ok(experiments)
2924
}
3025

31-
// ---
32-
// Example below connects to the database
33-
// ---
34-
35-
// #[tauri::command]
36-
// pub async fn get_experiments(
37-
// state: tauri::State<'_, DatabaseState>,
38-
// ) -> Result<Vec<ExperimentFile>, Error> {
39-
// // Access the database pool
40-
// let pool = &state.0;
41-
42-
// // Example query
43-
// let experiments =
44-
// sqlx::query!("SELECT name, created, contents FROM experiments ORDER BY created DESC")
45-
// .fetch_all(pool)
46-
// .await
47-
// .map_err(|e| Error::StringError(e.to_string()))?;
48-
49-
// // Convert to your ExperimentFile struct
50-
// let files: Vec<ExperimentFile> = experiments
51-
// .into_iter()
52-
// .map(|row| ExperimentFile {
53-
// name: row.name,
54-
// created: SystemTime::from(chrono::DateTime::parse_from_rfc3339(&row.created).unwrap()),
55-
// contents: row.contents,
56-
// })
57-
// .collect();
26+
#[tauri::command]
27+
pub async fn delete_experiments(
28+
state: tauri::State<'_, DatabaseState>,
29+
uuid: String,
30+
) -> Result<(), Error> {
31+
let pool = &state.0;
5832

59-
// Ok(files)
60-
// }
33+
let stmt: &str = match uuid.as_str() {
34+
"*" => "DELETE FROM experiments",
35+
_ => "DELETE FROM experiments WHERE experiment_uuid = $1",
36+
};
6137

62-
#[tauri::command]
63-
pub fn delete_experiment_files(
64-
app_handle: tauri::AppHandle,
65-
file_name: String,
66-
) -> Result<(), String> {
67-
let app_data_dir = app_handle
68-
.path_resolver()
69-
.app_data_dir()
70-
.ok_or_else(|| "Failed to get application data directory".to_string())?;
38+
let _ = sqlx::query(stmt).bind(&uuid).execute(pool).await?;
39+
print!("Deleted experiment with UUID: {}", uuid);
7140

72-
if file_name == "*" {
73-
// Delete all JSON files in the directory
74-
for entry in fs::read_dir(&app_data_dir).map_err(|e| e.to_string())? {
75-
let entry = entry.map_err(|e| e.to_string())?;
76-
let path = entry.path();
77-
if path.is_file() && path.extension().map(|e| e == "json").unwrap_or(false) {
78-
fs::remove_file(path).map_err(|e| e.to_string())?;
79-
}
80-
}
81-
Ok(())
82-
} else {
83-
// Delete a specific file
84-
let file_path = app_data_dir.join(file_name);
85-
if file_path.exists() && file_path.is_file() {
86-
fs::remove_file(file_path).map_err(|e| e.to_string())?;
87-
Ok(())
88-
} else {
89-
// File doesn't exist, do nothing
90-
Ok(())
91-
}
92-
}
41+
Ok(())
9342
}

src-tauri/src/commands/llm.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::db::DatabaseState;
12
use reqwest::Client;
23
use serde_json::json;
34
use tokio::time::{self, Duration};
@@ -62,9 +63,9 @@ pub async fn get_ollama_version(config: IDefaultConfigs) -> Result<String, Error
6263

6364
#[tauri::command]
6465
pub async fn get_inference(
66+
state: tauri::State<'_, DatabaseState>,
6567
config: IDefaultConfigs,
6668
params: TParamIteration,
67-
app_handle: tauri::AppHandle,
6869
) -> Result<GenerationResponse, Error> {
6970
// println!("----------------------------------------------------------");
7071
// println!("Config and Params");
@@ -180,18 +181,11 @@ pub async fn get_inference(
180181
dbg!(&res);
181182
println!("---------------------------------------------");
182183

183-
// sets the base path for storing logs
184-
// see https://github.com/tauri-apps/tauri/discussions/5557
185-
let app_data_dir = app_handle
186-
.path_resolver()
187-
.app_data_dir()
188-
.unwrap_or_else(|| panic!("Failed to get application data directory"));
189-
let app_data_dir_str = app_data_dir.to_string_lossy();
190-
191184
// Log the experiment if it's successful
185+
let pool = &state.0;
192186
match res {
193187
Ok(generation_response) => {
194-
log_experiment(&config, &params, &generation_response, &app_data_dir_str).await?;
188+
log_experiment(pool, &config, &params, &generation_response).await?;
195189
Ok(generation_response)
196190
}
197191
Err(err) => Err(Error::StringError(err.to_string())),

0 commit comments

Comments
 (0)