Skip to content

Commit e7484d6

Browse files
authored
Merge pull request #97 from sloganking/codex/continue-porting-v2-features
Port screen brightness feature to v2
2 parents 5d6210d + 84f6671 commit e7484d6

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

assistant_v2/FEATURE_PROGRESS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This document tracks which features from the original assistant have been implem
44

55
| Feature | Status |
66
| --- | --- |
7-
| Screen brightness control | Pending |
7+
| Screen brightness control | Done |
88
| System volume adjustment (Windows only) | Pending |
99
| Media playback commands | Pending |
1010
| Launch applications from voice | Pending |

assistant_v2/src/main.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
100100
strict: None,
101101
}
102102
.into(),
103+
FunctionObject {
104+
name: "set_screen_brightness".into(),
105+
description: Some(
106+
"Sets the screen brightness from 0 to 100 using the `luster` utility.".into(),
107+
),
108+
parameters: Some(serde_json::json!({
109+
"type": "object",
110+
"properties": {"brightness": {"type": "integer"}},
111+
"required": ["brightness"],
112+
})),
113+
strict: None,
114+
}
115+
.into(),
103116
FunctionObject {
104117
name: "set_clipboard".into(),
105118
description: Some("Sets the clipboard to the given text.".into()),
@@ -299,6 +312,25 @@ async fn handle_requires_action(
299312
});
300313
}
301314

315+
if tool.function.name == "set_screen_brightness" {
316+
let brightness = match serde_json::from_str::<serde_json::Value>(&tool.function.arguments) {
317+
Ok(v) => v["brightness"].as_i64().unwrap_or(0) as u32,
318+
Err(_) => 0,
319+
};
320+
321+
let result = std::process::Command::new("luster")
322+
.arg(brightness.to_string())
323+
.output();
324+
let msg = match result {
325+
Ok(_) => "Brightness set".to_string(),
326+
Err(e) => format!("Failed to set brightness: {}", e),
327+
};
328+
tool_outputs.push(ToolsOutputs {
329+
tool_call_id: Some(tool.id.clone()),
330+
output: Some(msg.into()),
331+
});
332+
}
333+
302334
if tool.function.name == "open_openai_billing" {
303335
let result = open::that("https://platform.openai.com/usage");
304336
let msg = match result {
@@ -401,4 +433,32 @@ mod tests {
401433
_ => false,
402434
}));
403435
}
436+
437+
#[test]
438+
fn includes_set_screen_brightness_function() {
439+
let req = CreateAssistantRequestArgs::default()
440+
.instructions("test")
441+
.model("gpt-4o")
442+
.tools(vec![
443+
FunctionObject {
444+
name: "set_screen_brightness".into(),
445+
description: Some("Sets the screen brightness from 0 to 100 using the `luster` utility.".into()),
446+
parameters: Some(serde_json::json!({
447+
"type": "object",
448+
"properties": {"brightness": {"type": "integer"}},
449+
"required": ["brightness"],
450+
})),
451+
strict: None,
452+
}
453+
.into(),
454+
])
455+
.build()
456+
.unwrap();
457+
458+
let tools = req.tools.unwrap();
459+
assert!(tools.iter().any(|t| match t {
460+
async_openai::types::AssistantTools::Function(f) => f.function.name == "set_screen_brightness",
461+
_ => false,
462+
}));
463+
}
404464
}

0 commit comments

Comments
 (0)