Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assistant_v2/FEATURE_PROGRESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This document tracks which features from the original assistant have been implem
| Display log files | Pending |
| Get system info | Done |
| List and kill processes | Pending |
| Run internet speed tests | Pending |
| Run internet speed tests | Done |
| Set the clipboard contents | Done |
| Get the clipboard contents | Done |
| Timers with alarm sounds | Pending |
Expand Down
69 changes: 69 additions & 0 deletions assistant_v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
strict: None,
}
.into(),
FunctionObject {
name: "speedtest".into(),
description: Some(
"Runs an internet speedtest and returns the results.".into(),
),
parameters: Some(serde_json::json!({
"type": "object",
"properties": {},
"required": [],
})),
strict: None,
}
.into(),
FunctionObject {
name: "set_screen_brightness".into(),
description: Some(
Expand Down Expand Up @@ -538,6 +551,23 @@ fn get_clipboard_string() -> Result<String, String> {
.map_err(|e| format!("Failed to read clipboard contents: {}", e))
}

fn speedtest() -> Result<String, String> {
let output = match std::process::Command::new("speedtest-rs").output() {
Ok(output) => String::from_utf8_lossy(&output.stdout).to_string(),
Err(err) => {
if err.kind() == std::io::ErrorKind::NotFound {
return Err(
"speedtest-rs not found. Please install speedtest-rs and add it to your PATH. You can do this by running `cargo install speedtest-rs`".to_string(),
);
} else {
return Err(format!("Failed to run speedtest-rs: {:?}", err));
}
}
};

Ok(output)
}

async fn handle_requires_action(
client: Client<OpenAIConfig>,
run_object: RunObject,
Expand Down Expand Up @@ -673,6 +703,17 @@ async fn handle_requires_action(
});
}

if tool.function.name == "speedtest" {
let msg = match speedtest() {
Ok(out) => out,
Err(e) => e,
};
tool_outputs.push(ToolsOutputs {
tool_call_id: Some(tool.id.clone()),
output: Some(msg.into()),
});
}

if tool.function.name == "set_speech_speed" {
let speed = match serde_json::from_str::<serde_json::Value>(&tool.function.arguments) {
Ok(v) => v["speed"].as_f64().unwrap_or(1.0) as f32,
Expand Down Expand Up @@ -840,6 +881,34 @@ mod tests {
}));
}

#[test]
fn includes_speedtest_function() {
let req = CreateAssistantRequestArgs::default()
.instructions("test")
.model("gpt-4o")
.tools(vec![FunctionObject {
name: "speedtest".into(),
description: Some(
"Runs an internet speedtest and returns the results.".into(),
),
parameters: Some(serde_json::json!({
"type": "object",
"properties": {},
"required": [],
})),
strict: None,
}
.into()])
.build()
.unwrap();

let tools = req.tools.unwrap();
assert!(tools.iter().any(|t| match t {
async_openai::types::AssistantTools::Function(f) => f.function.name == "speedtest",
_ => false,
}));
}

#[test]
fn includes_set_screen_brightness_function() {
let req = CreateAssistantRequestArgs::default()
Expand Down