2 Commits

2 changed files with 26 additions and 8 deletions
+11 -6
View File
@@ -177,7 +177,7 @@ def chat() -> dict[str, any]:
url = url_server url = url_server
headers = get_auth_headers(url) 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: try:
url = url + "/api/generate" url = url + "/api/generate"
logger.debug(f"url: {url} headers: {headers}") logger.debug(f"url: {url} headers: {headers}")
@@ -239,11 +239,16 @@ def select_endpoint_llm() -> Response:
if len(endpoints) != 1: if len(endpoints) != 1:
raise ValueError(f"Expected exactly one endpoint with title '{title}', found {len(endpoints)}") raise ValueError(f"Expected exactly one endpoint with title '{title}', found {len(endpoints)}")
global_state.set_host_url(endpoints[0]['url']) # Reset the session
global_state.set_llm(llm) if (title != global_state.get_host_title()) or (llm != global_state.get_llm()): # A change in setting
logger.debug(f"Updated to host url {endpoints[0]['url']} and LLM {llm}") session.clear()
logger.debug('Session cleared due to changed endpoint or changed LLM')
return jsonify({'message': 'Endpoint and LLM selected successfully'}) 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"]) @app.route('/smartassist', methods=["POST"])
+15 -2
View File
@@ -123,13 +123,26 @@ class GlobalState:
def get_host_url(self) -> str: def get_host_url(self) -> str:
""" """
Get the current URL of the host used for LLMs. Get the URL of the host currently used for LLMs.
Returns: Returns:
str: The current URL of the host. str: The URL of the current host.
""" """
return self.host_url return self.host_url
def get_host_title(self) -> str:
"""
Get the title of the host currently used for LLMs.
There must be a 1-to-1 mapping from host_url to host_title.
Returns:
str: The title of the current host.
"""
endpoints = self.get_endpoints_with_key_value('url', self.get_host_url())
if len(endpoints) != 1:
raise ValueError(f"Expected exactly one endpoint with url '{self.get_host_url()}', found {len(endpoints)}")
return endpoints[0]["title"]
def set_llm(self, model_name: str = "phi3:mini") -> None: def set_llm(self, model_name: str = "phi3:mini") -> None:
""" """
Set the LLM to use for queries. Set the LLM to use for queries.