Files
noentropy/src/gemini_helpers.rs
glitchySid 1a72116b9d refactor: Simplify codebase by extracting modules and helpers
Extract code into focused modules for better maintainability:

New modules:
- gemini_types.rs (32 lines) - Response type definitions
- gemini_helpers.rs (51 lines) - Prompt builder and conversion helpers
- prompt.rs (130 lines) - User input and validation logic

Refactored files:
- gemini.rs: 278 -> 259 lines (-19 lines)
  * Extract response parsing into helper methods
  * Extract request building into separate methods
  * Extract retry logic into dedicated functions
  * Use PromptBuilder for cleaner prompt construction

- config.rs: 275 -> 127 lines (-148 lines)
  * Extract all prompting logic to prompt.rs module
  * Simplify with Default trait for Config
  * Cleaner API methods

Benefits:
- Better separation of concerns
- Easier to test and maintain
- Clearer module boundaries
- Reduced nesting and complexity
- All 31 tests still passing
2025-12-29 00:35:14 +05:30

52 lines
1.7 KiB
Rust

use crate::files::{FileCategory, OrganizationPlan};
use crate::gemini_types::OrganizationPlanResponse;
impl OrganizationPlanResponse {
pub fn to_organization_plan(self) -> OrganizationPlan {
OrganizationPlan {
files: self
.files
.into_iter()
.map(|f| FileCategory {
filename: f.filename,
category: f.category,
sub_category: String::new(),
})
.collect(),
}
}
}
#[derive(Debug)]
pub struct PromptBuilder {
file_list: String,
}
impl PromptBuilder {
pub fn new(file_list: Vec<String>) -> Self {
Self {
file_list: file_list.join(", "),
}
}
pub fn build_categorization_prompt(&self) -> String {
format!(
"I have these files in my Downloads folder: [{}]. \
Categorize them into these folders: 'Images', 'Documents', 'Installers', 'Music', 'Archives', 'Code', 'Misc'. \
Return ONLY a JSON object with this structure: {{ 'files': [ {{ 'filename': 'name', 'category': 'folder' }} ] }}",
self.file_list
)
}
pub fn build_subcategory_prompt(
filename: &str,
parent_category: &str,
content: &str,
) -> String {
format!(
"I have a file named '{}' inside the '{}' folder. Here is the first 1000 characters of content:\n---\n{}\n---\nBased on this, suggest a single short sub-folder name (e.g., 'Invoices', 'Notes', 'Config'). Return ONLY the name of the sub-folder. Do not use markdown or explanations.",
filename, parent_category, content
)
}
}