initial commit
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
using Tomlyn;
|
||||
using Tomlyn.Model;
|
||||
|
||||
namespace Hush.Config;
|
||||
|
||||
public class ConfigManager
|
||||
{
|
||||
private readonly string _configDir;
|
||||
private readonly string _configPath;
|
||||
|
||||
public ConfigManager()
|
||||
{
|
||||
var homeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
|
||||
_configDir = Path.Combine(homeDir, ".config", "hush");
|
||||
_configPath = Path.Combine(_configDir, "config");
|
||||
}
|
||||
|
||||
public HushConfig Load()
|
||||
{
|
||||
if (!File.Exists(_configPath))
|
||||
{
|
||||
return new HushConfig();
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var toml = File.ReadAllText(_configPath);
|
||||
var model = Toml.ToModel<TomlTable>(toml);
|
||||
|
||||
var config = new HushConfig();
|
||||
|
||||
if (model.TryGetValue("groq_api_key", out var groqKey)) config.GroqApiKey = groqKey.ToString() ?? string.Empty;
|
||||
if (model.TryGetValue("together_api_key", out var togetherKey)) config.TogetherApiKey = togetherKey.ToString() ?? string.Empty;
|
||||
if (model.TryGetValue("cerebras_api_key", out var cerebrasKey)) config.CerebrasApiKey = cerebrasKey.ToString() ?? string.Empty;
|
||||
if (model.TryGetValue("fireworks_api_key", out var fireworksKey)) config.FireworksApiKey = fireworksKey.ToString() ?? string.Empty;
|
||||
|
||||
if (model.TryGetValue("llm_provider", out var llmProvider)) config.LlmProvider = llmProvider.ToString() ?? "groq";
|
||||
if (model.TryGetValue("whisper_provider", out var whisperProvider)) config.WhisperProvider = whisperProvider.ToString() ?? "groq";
|
||||
if (model.TryGetValue("typing_backend", out var typingBackend)) config.TypingBackend = typingBackend.ToString() ?? "wtype";
|
||||
if (model.TryGetValue("audio_backend", out var audioBackend)) config.AudioBackend = audioBackend.ToString() ?? "pw-record";
|
||||
|
||||
if (model.TryGetValue("llm_model", out var llmModel)) config.LlmModel = llmModel.ToString() ?? "openai/gpt-oss-20b";
|
||||
if (model.TryGetValue("whisper_model", out var whisperModel)) config.WhisperModel = whisperModel.ToString() ?? "whisper-large-v3-turbo";
|
||||
if (model.TryGetValue("reasoning_effort", out var reasoningEffort)) config.ReasoningEffort = reasoningEffort.ToString() ?? "none";
|
||||
|
||||
if (model.TryGetValue("min_recording_duration", out var minDuration)) config.MinRecordingDuration = Convert.ToInt32(minDuration);
|
||||
if (model.TryGetValue("whisper_language", out var language)) config.WhisperLanguage = language.ToString() ?? string.Empty;
|
||||
|
||||
return config;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new HushConfig();
|
||||
}
|
||||
}
|
||||
|
||||
public void Save(HushConfig config)
|
||||
{
|
||||
Directory.CreateDirectory(_configDir);
|
||||
|
||||
var model = new TomlTable
|
||||
{
|
||||
["groq_api_key"] = config.GroqApiKey,
|
||||
["together_api_key"] = config.TogetherApiKey,
|
||||
["cerebras_api_key"] = config.CerebrasApiKey,
|
||||
["fireworks_api_key"] = config.FireworksApiKey,
|
||||
|
||||
["llm_provider"] = config.LlmProvider,
|
||||
["whisper_provider"] = config.WhisperProvider,
|
||||
["typing_backend"] = config.TypingBackend,
|
||||
["audio_backend"] = config.AudioBackend,
|
||||
|
||||
["llm_model"] = config.LlmModel,
|
||||
["whisper_model"] = config.WhisperModel,
|
||||
["reasoning_effort"] = config.ReasoningEffort,
|
||||
|
||||
["min_recording_duration"] = config.MinRecordingDuration,
|
||||
["whisper_language"] = config.WhisperLanguage
|
||||
};
|
||||
|
||||
var toml = Toml.FromModel(model);
|
||||
File.WriteAllText(_configPath, toml);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Hush.Config;
|
||||
|
||||
public class HushConfig
|
||||
{
|
||||
public string GroqApiKey { get; set; } = string.Empty;
|
||||
public string TogetherApiKey { get; set; } = string.Empty;
|
||||
public string CerebrasApiKey { get; set; } = string.Empty;
|
||||
public string FireworksApiKey { get; set; } = string.Empty;
|
||||
|
||||
public string LlmProvider { get; set; } = "groq";
|
||||
public string WhisperProvider { get; set; } = "groq";
|
||||
public string TypingBackend { get; set; } = "wtype";
|
||||
public string AudioBackend { get; set; } = "pw-record";
|
||||
|
||||
public string LlmModel { get; set; } = "openai/gpt-oss-20b";
|
||||
public string WhisperModel { get; set; } = "whisper-large-v3-turbo";
|
||||
public string ReasoningEffort { get; set; } = "none";
|
||||
|
||||
public int MinRecordingDuration { get; set; } = 500;
|
||||
public string WhisperLanguage { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
[JsonSerializable(typeof(HushConfig))]
|
||||
public partial class HushConfigContext : JsonSerializerContext;
|
||||
Reference in New Issue
Block a user