Skip to content

Commit

Permalink
show answer count
Browse files Browse the repository at this point in the history
- real update every 10mins
- in between doing an estimation based on 15 answers / minute
  • Loading branch information
nor0x committed Sep 11, 2024
1 parent 6bf6302 commit 9ba2232
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
(Get-Content -Path WahlGPT.Common/Settings.cs) -replace 'QDRANT_HOST', '${{ secrets.QDRANT_HOST }}' | Set-Content -Path WahlGPT.Common/Settings.cs
(Get-Content -Path WahlGPT.Common/Settings.cs) -replace 'QDRANT_API_KEY', '${{ secrets.QDRANT_API_KEY }}' | Set-Content -Path WahlGPT.Common/Settings.cs
(Get-Content -Path WahlGPT.Common/Settings.cs) -replace 'BLOB_CONNECTION_STRING', '${{ secrets.BLOB_CONNECTION_STRING }}' | Set-Content -Path WahlGPT.Common/Settings.cs
(Get-Content -Path WahlGPT.Common/Settings.cs) -replace 'COUNT_ENDPOINT', '${{ secrets.COUNT_ENDPOINT }}' | Set-Content -Path WahlGPT.Common/Settings.cs
(Get-Content -Path WahlGPT.Common/Settings.cs) -replace 'VERSION_HASH', '${{ github.sha }}' | Set-Content -Path WahlGPT.Common/Settings.cs
- name: auto minify the files
Expand Down
1 change: 1 addition & 0 deletions WahlGPT.Common/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static class Settings
public const string QdrantHost = "QDRANT_HOST";
public const string QdrantApiKey = "QDRANT_API_KEY";
public const string BlobConnectionString = "BLOB_CONNECTION_STRING";
public const string CountUrl = "COUNT_ENDPOINT";
public const string Version = "VERSION_HASH";

static IKernelMemory? _kernelMemory;
Expand Down
31 changes: 30 additions & 1 deletion WahlGPT.Web/ChatManager.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,49 @@
using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
using Microsoft.KernelMemory;
using WahlGPT.Common;
using static System.Net.WebRequestMethods;

namespace WahlGPT;

public class ChatManager
{
public Dictionary<string, string> _questionCache = new();
public ChatManager(HttpClient client)
public ChatManager(HttpClient client, IJSRuntime jsRuntime)
{
_client = client;
_jsRuntime = jsRuntime;
}


readonly HttpClient _client;
readonly IJSRuntime _jsRuntime;

public async Task<int> GetCount()
{
var lastDate = await _jsRuntime.InvokeAsync<string>("localStorage.getItem", "countDate");
if (!string.IsNullOrWhiteSpace(lastDate))
{
var lastDateTime = DateTime.Parse(lastDate);
if (DateTime.Now.Subtract(lastDateTime).TotalMinutes < 10)
{
var lastCount = await _jsRuntime.InvokeAsync<string>("localStorage.getItem", "count");
if (!string.IsNullOrWhiteSpace(lastCount))
{
var minutes = DateTime.Now.Subtract(lastDateTime).TotalMinutes;
var estimatedCount = (int)(minutes * 10) + int.Parse(lastCount);
return estimatedCount;
}
}
}

var countString = await _client.GetStringAsync(Settings.CountUrl);
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "count", countString);
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", "countDate", DateTime.Now.ToString());
return int.Parse(countString);
}

public async Task<MyMemoryAnswer?> AskQuestion(string question, List<string> documentIds)
{
Expand Down
11 changes: 9 additions & 2 deletions WahlGPT.Web/Pages/Home.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
Willkommen zu <strong>WahlGPT</strong>
<div class="beta-badge">βeta</div>
</h1>
<p class="header-info-text">...ein LLM das die Wahlprogramme zur Nationalratswahl 2024 <a href="https://www.bmi.gv.at/412/Nationalratswahlen/Nationalratswahl_2024/start.aspx#pk_02" target="_blank">aller Parteien</a> gelesen hat und dir Fragen dazu beantwortet.
</p>
<p>
...ein LLM das die Wahlprogramme zur Nationalratswahl 2024 <a href="https://www.bmi.gv.at/412/Nationalratswahlen/Nationalratswahl_2024/start.aspx#pk_02" target="_blank">aller Parteien</a> gelesen hat
<br /> und dir Fragen dazu beantwortet.
bisher <span data-countup> @_answerCount</span> Antworten generiert
</p>

<ul class="actions special">
Expand Down Expand Up @@ -208,6 +209,7 @@
private string? _questionButtonText = "Frage stellen";
private bool _waitingForAnswer;
private bool _buttonDisabled = true;
int _answerCount = 12345;
Timer? _timer;
int _countDown;

Expand All @@ -232,6 +234,11 @@
if(firstRender)
{
await _js.InvokeVoidAsync("doSuggestions");
await Task.Run(async () =>
{
_answerCount = await _chat.GetCount();
await _js.InvokeVoidAsync("doCountUp", _answerCount);
});
}
}

Expand Down
8 changes: 8 additions & 0 deletions WahlGPT.Web/wwwroot/assets/js/anime.min.js

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions WahlGPT.Web/wwwroot/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ span:nth-child(3) {
margin-bottom: 2rem;
}

.header-info-text {
width: 44%;
margin: 0 auto !important;
margin-top: 1.1rem !important;
}

/* BLAZOR */


Expand Down Expand Up @@ -336,4 +342,8 @@ code {
.support-text {
max-width: 100%;
}

.header-info-text {
width: 80% !important;
}
}
1 change: 1 addition & 0 deletions WahlGPT.Web/wwwroot/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<script src="assets/js/breakpoints.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script src="assets/js/anime.min.js"></script>
<script src="js/app.js"></script>
</body>

Expand Down
45 changes: 44 additions & 1 deletion WahlGPT.Web/wwwroot/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,47 @@ let typeWriter = function (element, text, i) {
typeWriter(element, text, i + 1)
}, Math.floor(Math.random() * 90) + 10);
}
}
}

window.doCountUp = function (count) {

const els = document.querySelectorAll('[data-countup]');

els.forEach(el => {
el.textContent = count;
});
els.forEach(makeCountup);
}



function countup(el, target) {
let data = { count: 0 };
anime({
targets: data,
count: [0, target],
duration: 5000,
round: 1,
delay: 200,
easing: 'easeOutCubic',
update() {
el.innerText = data.count.toLocaleString();
}
});
}

function makeCountup(el) {
const text = el.textContent;
const target = parseInt(text, 10);

const io = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.intersectionRatio > 0) {
countup(el, target);
io.unobserve(entry.target);
}
});
});

io.observe(el);
}

0 comments on commit 9ba2232

Please sign in to comment.