refactor: modernize code, improve performance, and clean up various components.
This commit is contained in:
@@ -1,7 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.Json;
|
||||
using Toak.Serialization;
|
||||
|
||||
@@ -9,7 +5,7 @@ namespace Toak.Core.Skills;
|
||||
|
||||
public static class SkillRegistry
|
||||
{
|
||||
public static List<ISkill> AllSkills = new List<ISkill>();
|
||||
public static List<ISkill> AllSkills = [];
|
||||
|
||||
public static string SkillsDirectory => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
|
||||
@@ -28,7 +24,7 @@ public static class SkillRegistry
|
||||
{
|
||||
try
|
||||
{
|
||||
string json = File.ReadAllText(file);
|
||||
var json = File.ReadAllText(file);
|
||||
var def = JsonSerializer.Deserialize(json, AppJsonSerializerContext.Default.SkillDefinition);
|
||||
if (def != null)
|
||||
{
|
||||
@@ -47,7 +43,7 @@ public static class SkillRegistry
|
||||
if (AllSkills.Count == 0) Initialize();
|
||||
|
||||
var activeSkills = AllSkills.Where(s => activeSkillNames.Contains(s.Name, StringComparer.OrdinalIgnoreCase)).ToList();
|
||||
string normalizedTranscript = transcript.Trim();
|
||||
var normalizedTranscript = transcript.Trim();
|
||||
|
||||
foreach (var skill in activeSkills)
|
||||
{
|
||||
@@ -72,9 +68,11 @@ public static class SkillRegistry
|
||||
Description = "Translates the spoken command into a bash command and types it.",
|
||||
Hotwords = ["System terminal", "System run", "System execute"],
|
||||
Action = "type",
|
||||
SystemPrompt = @"You are a Linux terminal expert.
|
||||
Translate the user's request into a single, valid bash command.
|
||||
Output ONLY the raw command, no formatting, no markdown."
|
||||
SystemPrompt = """
|
||||
You are a Linux terminal expert.
|
||||
Translate the user's request into a single, valid bash command.
|
||||
Output ONLY the raw command, no formatting, no markdown.
|
||||
"""
|
||||
},
|
||||
new SkillDefinition
|
||||
{
|
||||
@@ -82,10 +80,12 @@ Output ONLY the raw command, no formatting, no markdown."
|
||||
Description = "Translates the spoken text into another language on the fly.",
|
||||
Hotwords = ["System translate to", "System translate into"],
|
||||
Action = "type",
|
||||
SystemPrompt = @"You are an expert translator. The user wants to translate the following text.
|
||||
The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:').
|
||||
Translate the REST of the transcript into that target language.
|
||||
Output ONLY the final translated text. Do not include markdown, explanations, or quotes."
|
||||
SystemPrompt = """
|
||||
You are an expert translator. The user wants to translate the following text.
|
||||
The first few words identify the target language (e.g. 'Translate to Spanish:', 'Translate into Hungarian:').
|
||||
Translate the REST of the transcript into that target language.
|
||||
Output ONLY the final translated text. Do not include markdown, explanations, or quotes.
|
||||
"""
|
||||
},
|
||||
new SkillDefinition
|
||||
{
|
||||
@@ -93,13 +93,15 @@ Output ONLY the final translated text. Do not include markdown, explanations, or
|
||||
Description = "Rewrites text into a formal, articulate tone.",
|
||||
Hotwords = ["System professional", "System formalize", "System formal"],
|
||||
Action = "type",
|
||||
SystemPrompt = @"Rewrite the following text to be articulate and formal.
|
||||
The text will start with 'System professional', 'System formalize', or 'System formal',
|
||||
or something along the lines of that. You can ignore those words.
|
||||
Do not add any conversational filler.
|
||||
Make sure to preserve the meaning of the original text.
|
||||
Output ONLY the final professional text.
|
||||
Text: {transcript}"
|
||||
SystemPrompt = """
|
||||
Rewrite the following text to be articulate and formal.
|
||||
The text will start with 'System professional', 'System formalize', or 'System formal',
|
||||
or something along the lines of that. You can ignore those words.
|
||||
Do not add any conversational filler.
|
||||
Make sure to preserve the meaning of the original text.
|
||||
Output ONLY the final professional text.
|
||||
Text: {transcript}
|
||||
"""
|
||||
},
|
||||
new SkillDefinition
|
||||
{
|
||||
@@ -107,19 +109,21 @@ Text: {transcript}"
|
||||
Description = "Provides a direct, crisp summary of the dictation.",
|
||||
Hotwords = ["System summary", "System concise", "System summarize"],
|
||||
Action = "type",
|
||||
SystemPrompt = @"Summarize the following text to be as concise
|
||||
and direct as possible.
|
||||
The text will start with 'System summary', 'System concise', or 'System summarize',
|
||||
and you shoul ignore that part of the text.
|
||||
Output ONLY the final summary text.
|
||||
Text: {transcript}"
|
||||
SystemPrompt = """
|
||||
Summarize the following text to be as concise
|
||||
and direct as possible.
|
||||
The text will start with 'System summary', 'System concise', or 'System summarize',
|
||||
and you shoul ignore that part of the text.
|
||||
Output ONLY the final summary text.
|
||||
Text: {transcript}
|
||||
"""
|
||||
}
|
||||
};
|
||||
|
||||
foreach (var def in defaults)
|
||||
{
|
||||
string filename = Path.Combine(SkillsDirectory, $"{def.Name.ToLowerInvariant()}.json");
|
||||
string json = JsonSerializer.Serialize(def, AppJsonSerializerContext.Default.SkillDefinition);
|
||||
var filename = Path.Combine(SkillsDirectory, $"{def.Name.ToLowerInvariant()}.json");
|
||||
var json = JsonSerializer.Serialize(def, AppJsonSerializerContext.Default.SkillDefinition);
|
||||
File.WriteAllText(filename, json);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user