cache the home page in the background

This commit is contained in:
Cyberes 2023-09-30 23:03:42 -06:00
parent 3ecb7bcf88
commit b10d22ca0d
6 changed files with 18 additions and 12 deletions

View File

@ -34,7 +34,8 @@ config_default_vars = {
'openai_moderation_enabled': True, 'openai_moderation_enabled': True,
'netdata_root': None, 'netdata_root': None,
'show_backends': True, 'show_backends': True,
'cluster_workers': 30 'cluster_workers': 30,
'background_homepage_cacher': True
} }
config_required_vars = ['cluster', 'mode', 'llm_middleware_name'] config_required_vars = ['cluster', 'mode', 'llm_middleware_name']

View File

@ -53,6 +53,7 @@ def load_config(config_path):
opts.openai_moderation_enabled = config['openai_moderation_enabled'] opts.openai_moderation_enabled = config['openai_moderation_enabled']
opts.show_backends = config['show_backends'] opts.show_backends = config['show_backends']
opts.cluster_workers = config['cluster_workers'] opts.cluster_workers = config['cluster_workers']
opts.background_homepage_cacher = config['background_homepage_cacher']
if opts.openai_expose_our_model and not opts.openai_api_key: if opts.openai_expose_our_model and not opts.openai_api_key:
print('If you set openai_epose_our_model to false, you must set your OpenAI key in openai_api_key.') print('If you set openai_epose_our_model to false, you must set your OpenAI key in openai_api_key.')

View File

@ -38,3 +38,4 @@ openai_moderation_enabled = True
cluster = {} cluster = {}
show_backends = True show_backends = True
cluster_workers = 30 cluster_workers = 30
background_homepage_cacher = True

View File

@ -14,5 +14,5 @@ def fallback(path):
response_msg = format_sillytavern_err(error_msg, error_type='API') response_msg = format_sillytavern_err(error_msg, error_type='API')
return jsonify({ return jsonify({
'results': [{'text': response_msg}], 'results': [{'text': response_msg}],
'result': f'Wrong API path, visit {base_client_api} for more info' 'result': f'Wrong API path, visit {base_client_api} for more info.'
}), 200 # return 200 so we don't trigger an error message in the client's ST }), 200 # return 200 so we don't trigger an error message in the client's ST

View File

@ -1,11 +1,13 @@
import time import time
import requests
from llm_server import opts from llm_server import opts
from llm_server.cluster.backend import get_a_cluster_backend, get_backends from llm_server.cluster.backend import get_backends
from llm_server.cluster.cluster_config import cluster_config from llm_server.cluster.cluster_config import cluster_config
from llm_server.custom_redis import redis from llm_server.custom_redis import redis
from llm_server.database.database import weighted_average_column_for_model from llm_server.database.database import weighted_average_column_for_model
from llm_server.llm.info import get_info, get_running_model from llm_server.llm.info import get_info
def main_background_thread(): def main_background_thread():
@ -26,6 +28,14 @@ def main_background_thread():
cluster_config.set_backend_value(backend_url, 'average_output_tokens', average_output_tokens) cluster_config.set_backend_value(backend_url, 'average_output_tokens', average_output_tokens)
if average_generation_elapsed_sec and average_output_tokens: if average_generation_elapsed_sec and average_output_tokens:
cluster_config.set_backend_value(backend_url, 'estimated_avg_tps', estimated_avg_tps) cluster_config.set_backend_value(backend_url, 'estimated_avg_tps', estimated_avg_tps)
if opts.background_homepage_cacher:
try:
base_client_api = redis.get('base_client_api', dtype=str)
r = requests.get('https://' + base_client_api, timeout=5)
except Exception as e:
print(f'Failed fetch the homepage - {e.__class__.__name__}: {e}')
time.sleep(30) time.sleep(30)

View File

@ -111,7 +111,7 @@
<h3>Instructions</h3> <h3>Instructions</h3>
<div id="instructions"> <div id="instructions">
<ol> <ol>
<li>In Settings > Power User Options, enable <kbd>Relaxed API URLS</kbd></li> <li>In Settings > Power User Options, enable <kbd>Relaxed API URLS</kbd>.</li>
<li>Set your API type to <kbd>{{ mode_name }}</kbd></li> <li>Set your API type to <kbd>{{ mode_name }}</kbd></li>
<li>Enter <kbd>{{ client_api }}</kbd> in the <kbd>{{ api_input_textbox }}</kbd> textbox.</li> <li>Enter <kbd>{{ client_api }}</kbd> in the <kbd>{{ api_input_textbox }}</kbd> textbox.</li>
{% if enable_streaming %} {% if enable_streaming %}
@ -167,17 +167,10 @@
</div> </div>
<br> <br>
{% endfor %} {% endfor %}
<!--
<div class="info-box">
<pre><code class="language-json" style="background-color: white">{{ stats_json|safe }}</code></pre>
</div>
-->
</div> </div>
<div class="footer"> <div class="footer">
<a href="https://git.evulid.cc/cyberes/local-llm-server" target="_blank">git.evulid.cc/cyberes/local-llm-server</a> <a href="https://git.evulid.cc/cyberes/local-llm-server" target="_blank">git.evulid.cc/cyberes/local-llm-server</a>
</div> </div>
<script>hljs.highlightAll();</script>
</body> </body>
</html> </html>