142 lines
5.0 KiB
C#
142 lines
5.0 KiB
C#
|
namespace app.ViewModels;
|
|||
|
|
|||
|
using System;
|
|||
|
using System.IO;
|
|||
|
using System.Text.Json;
|
|||
|
using System.Collections.Generic;
|
|||
|
using Avalonia.Controls;
|
|||
|
using app.Models;
|
|||
|
using app.Views;
|
|||
|
|
|||
|
public partial class MainWindowViewModel : ViewModelBase
|
|||
|
{
|
|||
|
private UserControl _currentView;
|
|||
|
public UserControl CurrentView
|
|||
|
{
|
|||
|
get => _currentView;
|
|||
|
set => SetProperty(ref _currentView, value);
|
|||
|
}
|
|||
|
private ConfigModel config { get; set; }
|
|||
|
public string ActionButtonText { get; set; } = "Start Conversation";
|
|||
|
public string ApiKey { get; set; }
|
|||
|
public string SpeakModel { get; set; }
|
|||
|
public string ListenModel { get; set; }
|
|||
|
public string ThinkModel { get; set; }
|
|||
|
public List<string> SpeakModels { get; } = new()
|
|||
|
{
|
|||
|
"aura-asteria-en", "aura-luna-en", "aura-athena-en", "aura-stella-en",
|
|||
|
"aura-hera-en", "aura-orion-en", "aura-arcas-en", "aura-perseus-en",
|
|||
|
"aura-angus-en", "aura-orpheus-en", "aura-helios-en", "aura-zeus-en"
|
|||
|
};
|
|||
|
|
|||
|
public List<string> ListenModels { get; } = new()
|
|||
|
{
|
|||
|
"nova-2", "nova-2-meeting", "nova-2-phonecall", "nova-2-finance",
|
|||
|
"nova-2-conversationalai", "nova-2-finance", "nova-2-voicemail",
|
|||
|
"nova-2-video", "nova-2-medical", "nova-2-drivethru", "nova-2-automotive",
|
|||
|
"nova-2-atc", "nova", "nova-phonecall", "nova-medical", "enhanced",
|
|||
|
"enhanced-phonecall", "enhanced-meeting", "enhanced-finance", "base",
|
|||
|
"base-phonecall", "base-meeting", "base-finance", "base-conversationalai",
|
|||
|
"base-voicemail", "base-video", "whisper-tiny", "whisper-small",
|
|||
|
"whisper-medium", "whisper-large", "whisper-base"
|
|||
|
};
|
|||
|
|
|||
|
public List<string> ThinkModels { get; } = new()
|
|||
|
{
|
|||
|
"gpt-4o-mini", "claude-3-haiku-20240307"
|
|||
|
};
|
|||
|
|
|||
|
public MainWindowViewModel()
|
|||
|
{
|
|||
|
config = GetConfig();
|
|||
|
ApiKey = config.ApiKey;
|
|||
|
SpeakModel = config.SpeakModel;
|
|||
|
ListenModel = config.ListenModel;
|
|||
|
ThinkModel = config.ThinkModel;
|
|||
|
if (string.IsNullOrEmpty(config.ApiKey))
|
|||
|
{
|
|||
|
CurrentView = new ConfigWindow();
|
|||
|
return;
|
|||
|
}
|
|||
|
CurrentView = new AgentWindow();
|
|||
|
}
|
|||
|
private static string ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/.config/deepgram-voice-assistant";
|
|||
|
private static string ConfigFilePath = ConfigPath + "/config.json";
|
|||
|
private static ConfigModel GetConfig()
|
|||
|
{
|
|||
|
// if config directory does not exist, create it
|
|||
|
if (!Directory.Exists(ConfigPath))
|
|||
|
{
|
|||
|
Console.WriteLine("Creating config directory");
|
|||
|
Directory.CreateDirectory(ConfigPath);
|
|||
|
}
|
|||
|
// check if file exists
|
|||
|
if (!File.Exists(ConfigFilePath))
|
|||
|
{
|
|||
|
// create file too
|
|||
|
Console.WriteLine("Creating config file");
|
|||
|
using FileStream fs = File.Create(ConfigFilePath);
|
|||
|
fs.Close();
|
|||
|
// write default config
|
|||
|
Console.WriteLine("Writing default config");
|
|||
|
using StreamWriter writer = new(ConfigFilePath);
|
|||
|
writer.WriteLine("{\n\t\"apiKey\": \"\",\n\t\"speakModel\": \"aura-athena-en\",\n\t\"listenModel\": \"nova-2\",\n\t\"thinkModel\": \"claude-3-haiku-20240307\"\n}");
|
|||
|
writer.Close();
|
|||
|
}
|
|||
|
// Read the config file
|
|||
|
using StreamReader reader = new(ConfigFilePath);
|
|||
|
string json = reader.ReadToEnd();
|
|||
|
reader.Close();
|
|||
|
return JsonSerializer.Deserialize<ConfigModel>(json);
|
|||
|
}
|
|||
|
private static void UpdateConfig(ConfigModel config)
|
|||
|
{
|
|||
|
// Write the config file
|
|||
|
using StreamWriter writer = new(ConfigFilePath);
|
|||
|
writer.WriteLine(JsonSerializer.Serialize(config));
|
|||
|
writer.Close();
|
|||
|
}
|
|||
|
|
|||
|
public void SaveConfig()
|
|||
|
{
|
|||
|
string speakModel = SpeakModel;
|
|||
|
string listenModel = ListenModel;
|
|||
|
string thinkModel = ThinkModel;
|
|||
|
Console.WriteLine("Saving config");
|
|||
|
Console.WriteLine("ApiKey: " + ApiKey);
|
|||
|
Console.WriteLine("SpeakModel: " + speakModel);
|
|||
|
Console.WriteLine("ListenModel: " + listenModel);
|
|||
|
Console.WriteLine("ThinkModel: " + thinkModel);
|
|||
|
config = new()
|
|||
|
{
|
|||
|
ApiKey = ApiKey,
|
|||
|
SpeakModel = speakModel,
|
|||
|
ListenModel = listenModel,
|
|||
|
ThinkModel = thinkModel
|
|||
|
};
|
|||
|
UpdateConfig(config);
|
|||
|
CurrentView = new AgentWindow();
|
|||
|
}
|
|||
|
|
|||
|
public void OpenConfig()
|
|||
|
{
|
|||
|
CurrentView = new ConfigWindow();
|
|||
|
}
|
|||
|
|
|||
|
public void ToggleConversation() {
|
|||
|
if (ActionButtonText == "Start Conversation") {
|
|||
|
StartConversation();
|
|||
|
} else {
|
|||
|
EndConversation();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public void StartConversation() {
|
|||
|
ActionButtonText = "End Conversation";
|
|||
|
}
|
|||
|
|
|||
|
public void EndConversation() {
|
|||
|
ActionButtonText = "Start Conversation";
|
|||
|
}
|
|||
|
}
|