Skip to content

Commit

Permalink
Rustfmt!
Browse files Browse the repository at this point in the history
  • Loading branch information
awwaiid committed Oct 21, 2024
1 parent 714a087 commit 6786cef
Showing 1 changed file with 33 additions and 19 deletions.
52 changes: 33 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ fn keyboard_test(args: &Args) -> Result<()> {
}

fn text_assistant(args: &Args) -> Result<()> {

let mut keyboard = create_virtual_keyboard();

loop {
Expand Down Expand Up @@ -104,14 +103,18 @@ fn text_assistant(args: &Args) -> Result<()> {

let api_key = std::env::var("OPENAI_API_KEY")?;

let mut body = serde_json::from_str::<serde_json::Value>(include_str!("../prompts/text.json"))?;
let mut body =
serde_json::from_str::<serde_json::Value>(include_str!("../prompts/text.json"))?;
body["model"] = json!(args.model);
body["messages"][0]["content"].as_array_mut().unwrap().push(json!({
"type": "image_url",
"image_url": {
"url": format!("data:image/png;base64,{}", base64_image)
}
}));
body["messages"][0]["content"]
.as_array_mut()
.unwrap()
.push(json!({
"type": "image_url",
"image_url": {
"url": format!("data:image/png;base64,{}", base64_image)
}
}));

println!("Sending request to OpenAI API...");
string_to_keypresses(&mut keyboard, ".")?;
Expand Down Expand Up @@ -205,16 +208,20 @@ fn ghostwriter(args: &Args) -> Result<()> {

// Get the base prompt from prompts/base.json as a serde json object
// Then modify it to set our current model and add the image
let mut body = serde_json::from_str::<serde_json::Value>(include_str!("../prompts/base.json"))?;
let mut body =
serde_json::from_str::<serde_json::Value>(include_str!("../prompts/base.json"))?;
body["model"] = json!(args.model);
// body["model"] = json!("gpt-4o");
// body["model"] = json!("o1-preview");
body["messages"][0]["content"].as_array_mut().unwrap().push(json!({
"type": "image_url",
"image_url": {
"url": format!("data:image/png;base64,{}", base64_image)
}
}));
body["messages"][0]["content"]
.as_array_mut()
.unwrap()
.push(json!({
"type": "image_url",
"image_url": {
"url": format!("data:image/png;base64,{}", base64_image)
}
}));

println!("Sending request to OpenAI API...");
draw_line(
Expand Down Expand Up @@ -593,7 +600,7 @@ fn wait_for_trigger() -> Result<()> {
}
}

use evdev::{uinput::VirtualDeviceBuilder, uinput::VirtualDevice, AttributeSet, Key};
use evdev::{uinput::VirtualDevice, uinput::VirtualDeviceBuilder, AttributeSet, Key};
use std::thread::sleep;
use std::time::Duration;

Expand All @@ -616,7 +623,11 @@ fn string_to_keypresses(device: &mut VirtualDevice, input: &str) -> Result<(), e
if let Some(&(key, shift)) = key_map.get(&c) {
if shift {
// Press Shift
device.emit(&[InputEvent::new(EventType::KEY, Key::KEY_LEFTSHIFT.code(), 1)])?;
device.emit(&[InputEvent::new(
EventType::KEY,
Key::KEY_LEFTSHIFT.code(),
1,
)])?;
}

// Press key
Expand All @@ -627,7 +638,11 @@ fn string_to_keypresses(device: &mut VirtualDevice, input: &str) -> Result<(), e

if shift {
// Release Shift
device.emit(&[InputEvent::new(EventType::KEY, Key::KEY_LEFTSHIFT.code(), 0)])?;
device.emit(&[InputEvent::new(
EventType::KEY,
Key::KEY_LEFTSHIFT.code(),
0,
)])?;
}

// Sync event
Expand All @@ -639,7 +654,6 @@ fn string_to_keypresses(device: &mut VirtualDevice, input: &str) -> Result<(), e
Ok(())
}


fn create_virtual_keyboard() -> VirtualDevice {
let mut keys = AttributeSet::new();

Expand Down

0 comments on commit 6786cef

Please sign in to comment.