@@ -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