From 97ee179b29fefce307023e0cc0c61f4fc30c04b3 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Tue, 6 Aug 2024 23:37:27 +0200 Subject: [PATCH] Snyggade till en loggutskrivt --- smartassist/src/backend.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index 377a805..9b13db4 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -177,7 +177,7 @@ def chat() -> dict[str, any]: url = url_server headers = get_auth_headers(url) - logger.debug(f"Sending request to:\n\turl:\t{url}\nmodel:\n\t{model}") + logger.debug(f"Sending request to:\n\turl:\t{url}\n\tmodel:\t{model}") try: url = url + "/api/generate" logger.debug(f"url: {url} headers: {headers}") @@ -239,11 +239,16 @@ def select_endpoint_llm() -> Response: if len(endpoints) != 1: raise ValueError(f"Expected exactly one endpoint with title '{title}', found {len(endpoints)}") - global_state.set_host_url(endpoints[0]['url']) - global_state.set_llm(llm) - logger.debug(f"Updated to host url {endpoints[0]['url']} and LLM {llm}") - - return jsonify({'message': 'Endpoint and LLM selected successfully'}) + # Reset the session + if (title != global_state.get_host_title()) or (llm != global_state.get_llm()): # A change in setting + session.clear() + logger.debug('Session cleared due to changed endpoint or changed LLM') + global_state.set_host_url(endpoints[0]['url']) + global_state.set_llm(llm) + logger.debug(f"Updated to host url {endpoints[0]['url']} and LLM {llm}") + return jsonify({'message': 'New endpoint and/or LLM detected, settings were changed successfully'}) + else: + return jsonify({'message': 'Endpoint and LLM are untouched'}) @app.route('/smartassist', methods=["POST"])