using Agent.Core.Logging;using LilithAgent = Lilith.Agent;namespace Lilith.RazorWebGui.Services;public sealed class LilithChatService{ private readonly object _lock = new(); private readonly List<ChatLine> _lines = []; private LilithAgent.Lilith? _lilith; public string Model { get; private set; } = "gemma4"; public int VersionNumber { get; } = 1; public bool IsReady { get; private set; } public IReadOnlyList<ChatLine> Lines { get { lock (_lock) { return _lines.ToList(); } } } public async Task InitializeAsync(CancellationToken cancellationToken = default) { if (IsReady) { return; } Model = Environment.GetEnvironmentVariable("LILITH_MODEL") ?? "gemma4"; var credentials = new LilithAgent.LilithCredentials(Model: Model); var lilith = new LilithAgent.Lilith(AppendLog, credentials); await lilith.BootAsync(startServerIfNotRunning: true).ConfigureAwait(false); _lilith = lilith; IsReady = true; } public async Task<bool> SendAsync(string input, CancellationToken cancellationToken = default) { if (_lilith is null) { throw new InvalidOperationException("Lilith is not initialized."); } if (input.StartsWith("/voice ", StringComparison.OrdinalIgnoreCase)) { AppendSystem($"Voice commands are not available in Version {VersionNumber} web UI."); return true; } return await _lilith.HandleInputAsync(input).ConfigureAwait(false); } public void Shutdown() { _lilith?.SaveConversation(); } private void AppendLog(LogEntry entry) { string text = entry.Description; if (string.IsNullOrEmpty(text)) { return; } ChatLog.Append(_lines, _lock, entry); } private void AppendSystem(string message) => AppendLog(new LogEntry("System", message, LogColors.Cyan, DateTime.Now, LogType.WriteLine));}
Documentation
Lilith.RazorWebGui (Version 1)
ASP.NET Core Razor Pages web UI for Lilith Version 1. Mirrors LilithConsole chat, commands, and logging.
- Model:
LILITH_MODEL(defaultgemma4) - Commands:
exit,/new,/history,/history <n>
dotnet run --project Lilith.RazorWebGui.csproj
Browse http://localhost:5000 (see Properties/launchSettings.json).