From fb402a5d3d043efbecd7199ea45927d6ad37af6c Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Sun, 7 Jan 2024 22:34:09 +0100 Subject: [PATCH] The core is updated --- .../endpoints/lollms_configuration_infos.py | 183 +++++++++--------- .../endpoints/lollms_personalities_infos.py | 23 ++- lollms/utilities.py | 12 +- 3 files changed, 114 insertions(+), 104 deletions(-) diff --git a/lollms/server/endpoints/lollms_configuration_infos.py b/lollms/server/endpoints/lollms_configuration_infos.py index ec2060c..2cb9a34 100644 --- a/lollms/server/endpoints/lollms_configuration_infos.py +++ b/lollms/server/endpoints/lollms_configuration_infos.py @@ -7,8 +7,9 @@ description: application. These routes are specific to configurations """ -from fastapi import APIRouter, Request +from fastapi import APIRouter, Request, HTTPException from pydantic import BaseModel +from json import JSONDecodeError import pkg_resources from lollms.server.elf_server import LOLLMSElfServer from lollms.binding import BindingBuilder, InstallOption @@ -17,6 +18,7 @@ from lollms.utilities import load_config, trace_exception, gc from pathlib import Path from typing import List import json +from typing import List, Any class SettingsInfos(BaseModel): setting_name:str @@ -28,108 +30,113 @@ lollmsElfServer = LOLLMSElfServer.get_instance() # ----------------------------------- Settings ----------------------------------------- @router.post("/update_setting") -def update_setting(data:SettingsInfos): - setting_name = data.setting_name +async def update_setting(request: Request): + """ + Endpoint to apply configuration settings. - ASCIIColors.info(f"Requested updating of setting {data.setting_name} to {data.setting_value}") - if setting_name== "temperature": - lollmsElfServer.config["temperature"]=float(data.setting_value) - elif setting_name== "n_predict": - lollmsElfServer.config["n_predict"]=int(data.setting_value) - elif setting_name== "top_k": - lollmsElfServer.config["top_k"]=int(data.setting_value) - elif setting_name== "top_p": - lollmsElfServer.config["top_p"]=float(data.setting_value) - - elif setting_name== "repeat_penalty": - lollmsElfServer.config["repeat_penalty"]=float(data.setting_value) - elif setting_name== "repeat_last_n": - lollmsElfServer.config["repeat_last_n"]=int(data.setting_value) + :param request: The HTTP request object. + :return: A JSON response with the status of the operation. + """ - elif setting_name== "n_threads": - lollmsElfServer.config["n_threads"]=int(data.setting_value) - elif setting_name== "ctx_size": - lollmsElfServer.config["ctx_size"]=int(data.setting_value) + try: + config_data = (await request.json()) + if "config" in config_data.keys(): + config_data = config_data["config"] + setting_name = config_data["setting_name"] + setting_value = config_data["setting_value"] - elif setting_name== "personality_folder": - lollmsElfServer.personality_name=data.setting_value - if len(lollmsElfServer.config["personalities"])>0: - if lollmsElfServer.config["active_personality_id"] None @@ -40,12 +42,10 @@ def run_async(func): Returns: None: Nothing is returned since the function is meant to perform side effects. """ - - async def wrapper(*args, **kwargs): - return asyncio.run(func(*args, **kwargs)) - - return wrapper() - + try: + return asyncio.run(func) + except: + return func def terminate_thread(thread): if thread: if not thread.is_alive():