From f7743ade897ac819c6ff4b6ff1ab7f59fbc95de0 Mon Sep 17 00:00:00 2001 From: Cyberes Date: Wed, 23 Aug 2023 23:27:33 -0600 Subject: [PATCH] add dynamic analitics tracking to home page --- config/config.yml | 15 +++++++++++++++ llm_server/config.py | 1 + server.py | 9 ++++++++- templates/home.html | 22 ++++------------------ 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/config/config.yml b/config/config.yml index 8c9833c..f6213e0 100644 --- a/config/config.yml +++ b/config/config.yml @@ -11,6 +11,21 @@ token_limit: 7777 backend_url: https://10.0.0.86:8083 llm_middleware_name: proxy.chub-archive.evulid.cc +analytics_tracking_code: | + var _paq = window._paq = window._paq || []; + _paq.push(['trackPageView']); + _paq.push(['enableLinkTracking']); + (function () { + var u = "https://mato.evulid.cc/"; + _paq.push(['setTrackerUrl', u + 'matomo.php']); + _paq.push(['setSiteId', '10']); + var d = document, + g = d.createElement('script'), + s = d.getElementsByTagName('script')[0]; + g.async = true; + g.src = u + 'matomo.js'; + s.parentNode.insertBefore(g, s); + })(); ## STATS ## diff --git a/llm_server/config.py b/llm_server/config.py index 3f17533..7d2bd4e 100644 --- a/llm_server/config.py +++ b/llm_server/config.py @@ -9,6 +9,7 @@ config_default_vars = { 'load_num_prompts': False, 'show_num_prompts': True, 'show_uptime': True, + 'analytics_tracking_code': '', } config_required_vars = ['token_limit', 'concurrent_gens', 'mode', 'llm_middleware_name'] diff --git a/server.py b/server.py index 2af6b84..2c630da 100644 --- a/server.py +++ b/server.py @@ -1,3 +1,4 @@ +import collections import json import os import sys @@ -93,7 +94,7 @@ app.register_blueprint(bp, url_prefix='/api/v1/') def home(): if not opts.full_client_api: opts.full_client_api = f'https://{request.headers.get("Host")}/{opts.frontend_api_client.strip("/")}' - stats = generate_stats() + stats = collections.OrderedDict(sorted(generate_stats().items())) if not bool(redis.get('backend_online')) or not stats['online']: running_model = estimated_wait_sec = 'offline' @@ -101,8 +102,14 @@ def home(): running_model = opts.running_model estimated_wait_sec = f"{stats['estimated_wait_sec']} seconds" + if len(config['analytics_tracking_code']): + analytics_tracking_code = f"" + else: + analytics_tracking_code = '' + return render_template('home.html', llm_middleware_name=config['llm_middleware_name'], + analytics_tracking_code=analytics_tracking_code, current_model=running_model, client_api=opts.full_client_api, estimated_wait=estimated_wait_sec, diff --git a/templates/home.html b/templates/home.html index 66e787d..d56c04c 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,24 +1,10 @@ - + + {{ llm_middleware_name }} - + {{ analytics_tracking_code|safe }}