Skip to content

Commit

Permalink
Add log entry; disable lots of debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Dec 25, 2024
1 parent 7737538 commit 6da25ac
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 16 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ Draw some stuff on your screen, and then trigger the assistant by *touching/tapp
* Oh -- I think it's rather important to run each set a few times assuming there is some temperature involved
* To scale this even further we of course would want to bring in a JUDGE-BOT!
* Then I could say things like "my new segmentation algorithm improved output quality by 17% per the JUDGE-BOT" etc
* **2024-12-25** -- CLI simplify and expand
* Now you can pass just `-m gpt-4o-mini` and it will guess the engine is `openai`
* You can also pass `--engine-api-key` and `--engine-url-base`
* So now to use [Groq](https://groq.com/): `./ghostwriter -m llama-3.2-90b-vision-preview --engine-api-key $GROQ_API_KEY --engine openai --engine-base-url https://api.groq.com/openai`
* ... but so far Llama 3.2 90b vision is still quite bad with this interface
* I turned off a bunch of debugging. Now I'll need to go back and introduce log-level or something

## Ideas
* [DONE] Matt showed me his iOS super calc that just came out, take inspiration from that!
Expand Down
4 changes: 2 additions & 2 deletions src/llm_engine/anthropic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl LLMEngine for Anthropic {
});

// print body for debugging
println!("Request: {}", body);
// println!("Request: {}", body);

let raw_response = ureq::post(&format!("{}/v1/messages", self.base_url))
.set("x-api-key", self.api_key.as_str())
Expand All @@ -118,7 +118,7 @@ impl LLMEngine for Anthropic {
};

let json: json = response.into_json().unwrap();
println!("Response: {}", json);
// println!("Response: {}", json);
let tool_calls = &json["content"];
if let Some(tool_call) = tool_calls.get(0) {
let function_name = tool_call["name"].as_str().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/llm_engine/openai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl LLMEngine for OpenAI {
});

// print body for debugging
println!("Request: {}", body);
// println!("Request: {}", body);
let raw_response = ureq::post(format!("{}/v1/chat/completions", self.base_url).as_str())
.set("Authorization", &format!("Bearer {}", self.api_key))
.set("Content-Type", "application/json")
Expand All @@ -115,7 +115,7 @@ impl LLMEngine for OpenAI {
};

let json: json = response.into_json().unwrap();
println!("Response: {}", json);
// println!("Response: {}", json);

let tool_calls = &json["choices"][0]["message"]["tool_calls"];

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn draw_svg(
}

fn load_config(filename: &str) -> String {
println!("Loading config from {}", filename);
// println!("Loading config from {}", filename);

if std::path::Path::new(filename).exists() {
std::fs::read_to_string(filename).unwrap()
Expand Down Expand Up @@ -271,7 +271,7 @@ fn ghostwriter(args: &Args) -> Result<()> {
} else {
String::new()
};
println!("Segmentation description: {}", segmentation_description);
// println!("Segmentation description: {}", segmentation_description);

let prompt_general_raw = load_config(&args.prompt);
let prompt_general_json =
Expand Down
20 changes: 10 additions & 10 deletions src/segmenter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ impl ImageAnalyzer {
&self,
image_path: &str,
) -> Result<SegmentationResult, Box<dyn std::error::Error>> {
println!("Reading image from: {}", image_path);
// println!("Reading image from: {}", image_path);

// Read image and convert to grayscale
let img = image::open(image_path)?.to_rgb8();
let (width, height) = img.dimensions();
println!("Image loaded: {}x{}", width, height);
// println!("Image loaded: {}x{}", width, height);

// Convert to grayscale
let gray: GrayImage = image::imageops::grayscale(&img);
Expand All @@ -55,7 +55,7 @@ impl ImageAnalyzer {

// Find contours
let contours = find_contours(&binary);
println!("Found {} contours", contours.len());
// println!("Found {} contours", contours.len());

// Process regions
let mut regions = Vec::new();
Expand Down Expand Up @@ -91,7 +91,7 @@ impl ImageAnalyzer {
regions.sort_by(|a, b| b.area.partial_cmp(&a.area).unwrap());
regions.truncate(self.max_regions);

println!("Processed {} significant regions", regions.len());
// println!("Processed {} significant regions", regions.len());

Ok(SegmentationResult {
regions,
Expand Down Expand Up @@ -156,12 +156,12 @@ impl ImageAnalyzer {
}

pub fn analyze_image(image_path: &str) -> Result<String, Box<dyn std::error::Error>> {
println!("Reading image from: {}", image_path);
// println!("Reading image from: {}", image_path);

// Read image and convert to grayscale
let img = image::open(image_path)?.to_rgb8();
let (width, height) = img.dimensions();
println!("Image loaded: {}x{}", width, height);
// println!("Image loaded: {}x{}", width, height);

// Convert to grayscale
let gray: GrayImage = image::imageops::grayscale(&img);
Expand All @@ -178,16 +178,16 @@ pub fn analyze_image(image_path: &str) -> Result<String, Box<dyn std::error::Err

// Find contours
let contours = find_contours(&binary);
println!("Found {} contours", contours.len());
// println!("Found {} contours", contours.len());

// Process regions
let mut regions = Vec::new();
let min_area = 50.0; // (width * height) as f32 * 0.001; // Assuming min_region_size is 0.01
println!("Min region area: {}", min_area);
// println!("Min region area: {}", min_area);

for contour in contours {
let area = contour_area(&contour.points) as f32;
println!("Contour area: {}", area);
// println!("Contour area: {}", area);

if area >= min_area {
let bounds = min_area_rect(&contour.points);
Expand Down Expand Up @@ -216,7 +216,7 @@ pub fn analyze_image(image_path: &str) -> Result<String, Box<dyn std::error::Err
regions.sort_by(|a, b| b.area.partial_cmp(&a.area).unwrap());
regions.truncate(10); // Assuming max_regions is 10

println!("Processed {} significant regions", regions.len());
// println!("Processed {} significant regions", regions.len());

let mut result = String::new();
for region in regions {
Expand Down

0 comments on commit 6da25ac

Please sign in to comment.