refactor: modernize code, improve performance, and clean up various components.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Threading.Tasks;
|
||||
using Toak.Configuration;
|
||||
using Toak.Api;
|
||||
using Toak.Core.Interfaces;
|
||||
@@ -54,15 +50,9 @@ public static class DaemonService
|
||||
var notifications = new Notifications();
|
||||
|
||||
var speechClient = new OpenAiCompatibleClient(config.GroqApiKey);
|
||||
ILlmClient llmClient;
|
||||
if (config.LlmProvider == "together")
|
||||
{
|
||||
llmClient = new OpenAiCompatibleClient(config.TogetherApiKey, "https://api.together.xyz/v1/", config.ReasoningEffort);
|
||||
}
|
||||
else
|
||||
{
|
||||
llmClient = new OpenAiCompatibleClient(config.GroqApiKey, "https://api.groq.com/openai/v1/", config.ReasoningEffort);
|
||||
}
|
||||
ILlmClient llmClient = config.LlmProvider == "together"
|
||||
? new OpenAiCompatibleClient(config.TogetherApiKey, "https://api.together.xyz/v1/", config.ReasoningEffort)
|
||||
: new OpenAiCompatibleClient(config.GroqApiKey, "https://api.groq.com/openai/v1/", config.ReasoningEffort);
|
||||
|
||||
IAudioRecorder recorder = config.AudioBackend == "ffmpeg"
|
||||
? new FfmpegAudioRecorder(stateTracker, notifications)
|
||||
@@ -114,12 +104,12 @@ public static class DaemonService
|
||||
try
|
||||
{
|
||||
var buffer = new byte[3];
|
||||
int bytesRead = await client.ReceiveAsync(buffer, SocketFlags.None);
|
||||
var bytesRead = await client.ReceiveAsync(buffer, SocketFlags.None);
|
||||
if (bytesRead > 0)
|
||||
{
|
||||
byte cmd = buffer[0];
|
||||
bool pipeToStdout = bytesRead > 1 && buffer[1] == 1;
|
||||
bool copyToClipboard = bytesRead > 2 && buffer[2] == 1;
|
||||
var cmd = buffer[0];
|
||||
var pipeToStdout = bytesRead > 1 && buffer[1] == 1;
|
||||
var copyToClipboard = bytesRead > 2 && buffer[2] == 1;
|
||||
|
||||
if (cmd == 1) // START
|
||||
{
|
||||
@@ -142,9 +132,9 @@ public static class DaemonService
|
||||
}
|
||||
else if (cmd == 5) // STATUS
|
||||
{
|
||||
bool json = pipeToStdout; // buffer[1] == 1 is json
|
||||
bool isRecording = stateTracker.IsRecording();
|
||||
string stateStr = isRecording ? "Recording" : "Idle";
|
||||
var json = pipeToStdout; // buffer[1] == 1 is json
|
||||
var isRecording = stateTracker.IsRecording();
|
||||
var stateStr = isRecording ? "Recording" : "Idle";
|
||||
|
||||
if (json)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user