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 @@ -8,7 +8,7 @@ This document tracks which features from the original assistant have been implem
| System volume adjustment (Windows only) | Pending |
| Media playback commands | Done |
| Launch applications from voice | Pending |
| Display log files | Done |
| Display log files | Done (includes live stream) |
| Get system info | Done |
| List and kill processes | Pending |
| Run internet speed tests | Done (async) |
Expand Down
86 changes: 85 additions & 1 deletion assistant_v2/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ use open;
use enigo::{Enigo, KeyboardControllable};
use speakstream::ss::SpeakStream;
use std::error::Error;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::fs;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Mutex};
use std::sync::LazyLock;
Expand Down Expand Up @@ -246,6 +248,19 @@ async fn main() -> Result<(), Box<dyn Error>> {
strict: None,
}
.into(),
FunctionObject {
name: "show_live_log_stream".into(),
description: Some(
"Shows live updates of the log file via opening powershell and running 'Get-Content -Wait'.".into(),
),
parameters: Some(serde_json::json!({
"type": "object",
"properties": {},
"required": [],
})),
strict: None,
}
.into(),
FunctionObject {
name: "get_system_info".into(),
description: Some("Returns system information like CPU and memory usage.".into()),
Expand Down Expand Up @@ -597,6 +612,32 @@ fn speedtest() -> Result<String, String> {
Ok(output)
}

fn get_currently_active_log_file() -> Option<PathBuf> {
let mut entries: Vec<_> = fs::read_dir(&*LOGS_DIR).ok()?.filter_map(Result::ok).collect();
entries.sort_by_key(|entry| entry.file_name());
entries.last().map(|last| last.path())
}

fn run_get_content_wait_on_file(file_path: &Path) -> Result<String, String> {
let file_path_str = file_path
.to_str()
.ok_or_else(|| "Failed to convert file path to string".to_string())?;
Command::new("cmd")
.args([
"/C",
"start",
"powershell",
"-NoExit",
"-Command",
"Get-Content",
&format!("\"{}\"", file_path_str),
"-Wait",
])
.spawn()
.map(|_| "Successfully opened file in powershell".to_string())
.map_err(|err| format!("Failed to open file in powershell: {:?}", err))
}

async fn handle_requires_action(
client: Client<OpenAIConfig>,
run_object: RunObject,
Expand Down Expand Up @@ -745,6 +786,20 @@ async fn handle_requires_action(
});
}

if tool.function.name == "show_live_log_stream" {
let msg = match get_currently_active_log_file() {
Some(log_file) => match run_get_content_wait_on_file(&log_file) {
Ok(m) => m,
Err(e) => e,
},
None => "No log files found".to_string(),
};
tool_outputs.push(ToolsOutputs {
tool_call_id: Some(tool.id.clone()),
output: Some(msg.into()),
});
}

if tool.function.name == "speedtest" {
tool_outputs.push(ToolsOutputs {
tool_call_id: Some(tool.id.clone()),
Expand Down Expand Up @@ -1019,6 +1074,35 @@ mod tests {
}));
}

#[test]
fn includes_show_live_log_stream_function() {
let req = CreateAssistantRequestArgs::default()
.instructions("test")
.model("gpt-4o")
.tools(vec![FunctionObject {
name: "show_live_log_stream".into(),
description: Some(
"Shows live updates of the log file via opening powershell and running 'Get-Content -Wait'.".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 == "show_live_log_stream",
_ => false,
}));
}

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