2025-01-31 17:43:29 -08:00
|
|
|
|
namespace app.ViewModels;
|
|
|
|
|
|
|
|
|
|
using System;
|
2025-01-31 18:49:44 -08:00
|
|
|
|
using System.Threading.Tasks;
|
2025-01-31 17:43:29 -08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text.Json;
|
|
|
|
|
using System.Collections.Generic;
|
2025-01-31 18:49:44 -08:00
|
|
|
|
using System.Net.WebSockets;
|
2025-01-31 17:43:29 -08:00
|
|
|
|
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; }
|
2025-01-31 18:49:44 -08:00
|
|
|
|
private ClientWebSocket ws { get; set; }
|
2025-01-31 17:43:29 -08:00
|
|
|
|
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()
|
|
|
|
|
{
|
2025-01-31 18:49:44 -08:00
|
|
|
|
ws = new();
|
2025-01-31 17:43:29 -08:00
|
|
|
|
config = GetConfig();
|
|
|
|
|
ApiKey = config.ApiKey;
|
|
|
|
|
SpeakModel = config.SpeakModel;
|
|
|
|
|
ListenModel = config.ListenModel;
|
|
|
|
|
ThinkModel = config.ThinkModel;
|
|
|
|
|
if (string.IsNullOrEmpty(config.ApiKey))
|
|
|
|
|
{
|
|
|
|
|
CurrentView = new ConfigWindow();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-01-31 18:49:44 -08:00
|
|
|
|
CurrentView = new HomeWindow();
|
2025-01-31 17:43:29 -08:00
|
|
|
|
}
|
|
|
|
|
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);
|
2025-01-31 18:49:44 -08:00
|
|
|
|
CurrentView = new HomeWindow();
|
2025-01-31 17:43:29 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OpenConfig()
|
|
|
|
|
{
|
|
|
|
|
CurrentView = new ConfigWindow();
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 18:49:44 -08:00
|
|
|
|
public async Task StartAgent() {
|
|
|
|
|
// ws.Options.SetRequestHeader("Authorization", "token " + config.ApiKey);
|
|
|
|
|
// await ws.ConnectAsync(new Uri("wss://agent.deepgram.com/agent"), System.Threading.CancellationToken.None);
|
|
|
|
|
CurrentView = new AgentWindow();
|
2025-01-31 17:43:29 -08:00
|
|
|
|
}
|
|
|
|
|
|
2025-01-31 18:49:44 -08:00
|
|
|
|
public async Task EndConversation() {
|
|
|
|
|
CurrentView = new HomeWindow();
|
|
|
|
|
// await ws.CloseAsync(WebSocketCloseStatus.NormalClosure, "Conversation ended", System.Threading.CancellationToken.None);
|
2025-01-31 17:43:29 -08:00
|
|
|
|
}
|
|
|
|
|
}
|