Added more endpoints to the fastapi

This commit is contained in:
Saifeddine ALOUI 2024-01-07 15:26:40 +01:00
parent adf1e23559
commit 4ef9f5d72c
6 changed files with 40 additions and 12 deletions

View File

@ -214,12 +214,14 @@ class LoLLMsServer(LollmsApplication):
self.binding = None
for per in self.mounted_personalities:
per.model = None
if per is not None:
per.model = None
gc.collect()
self.binding = BindingBuilder().build_binding(self.config, self.lollms_paths, lollmsCom=self)
self.model = self.binding.build_model()
for per in self.mounted_personalities:
per.model = self.model
if per is not None:
per.model = self.model
except Exception as ex:
# Catch the exception and get the traceback as a list of strings
traceback_lines = traceback.format_exception(type(ex), ex, ex.__traceback__)

View File

@ -84,7 +84,8 @@ def reload_binding( params: ReloadBindingParams):
lollmsElfServer.binding = None
lollmsElfServer.model = None
for per in lollmsElfServer.mounted_personalities:
per.model = None
if per is not None:
per.model = None
gc.collect()
lollmsElfServer.binding = BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, InstallOption.INSTALL_IF_NECESSARY, lollmsCom=lollmsElfServer)
lollmsElfServer.model = None
@ -125,7 +126,8 @@ def install_binding(data:BindingInstallParams):
lollmsElfServer.binding = BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, lollmsCom=lollmsElfServer)
lollmsElfServer.model = lollmsElfServer.binding.build_model()
for per in lollmsElfServer.mounted_personalities:
per.model = lollmsElfServer.model
if per is not None:
per.model = lollmsElfServer.model
return {"status": True}
except Exception as ex:
lollmsElfServer.error(f"Couldn't build binding: [{ex}]")
@ -159,7 +161,8 @@ def reinstall_binding(data:BindingInstallParams):
lollmsElfServer.binding = BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, lollmsCom=lollmsElfServer)
lollmsElfServer.model = lollmsElfServer.binding.build_model()
for per in lollmsElfServer.mounted_personalities:
per.model = lollmsElfServer.model
if per is not None:
per.model = lollmsElfServer.model
return {"status": True}
except Exception as ex:
@ -196,7 +199,8 @@ def unInstall_binding(data:BindingInstallParams):
lollmsElfServer.binding = BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, lollmsCom=lollmsElfServer)
lollmsElfServer.model = lollmsElfServer.binding.build_model()
for per in lollmsElfServer.mounted_personalities:
per.model = lollmsElfServer.model
if per is not None:
per.model = lollmsElfServer.model
else:
lollmsElfServer.config.binding_name = None
if lollmsElfServer.config.auto_save:

View File

@ -80,7 +80,8 @@ def update_setting(data:SettingsInfos):
lollmsElfServer.binding = None
lollmsElfServer.model = None
for per in lollmsElfServer.mounted_personalities:
per.model = None
if per is not None:
per.model = None
gc.collect()
lollmsElfServer.binding = BindingBuilder().build_binding(lollmsElfServer.config, lollmsElfServer.lollms_paths, InstallOption.INSTALL_IF_NECESSARY, lollmsCom=lollmsElfServer)
lollmsElfServer.model = None
@ -109,7 +110,8 @@ def update_setting(data:SettingsInfos):
if lollmsElfServer.model is not None:
ASCIIColors.yellow("New model OK")
for per in lollmsElfServer.mounted_personalities:
per.model = lollmsElfServer.model
if per is not None:
per.model = lollmsElfServer.model
except Exception as ex:
trace_exception(ex)
lollmsElfServer.InfoMessage(f"It looks like you we couldn't load the model.\nHere is the error message:\n{ex}")

View File

@ -81,6 +81,14 @@ class V1InstructGenerateRequest(BaseModel):
router = APIRouter()
elf_server = LOLLMSElfServer.get_instance()
@router.get("/get_generation_status")
def get_generation_status():
return {"status":elf_server.busy}
@router.post("/generate")
def lollms_generate(request_data: GenerateRequest):
"""

View File

@ -168,6 +168,20 @@ def list_mounted_personalities(lollmsElfServer):
@router.get("/get_current_personality_path_infos")
def get_current_personality_path_infos():
if lollmsElfServer.personality is None:
return {
"personality_category":"",
"personality_name":""
}
else:
return {
"personality_category":lollmsElfServer.personality_category,
"personality_name":lollmsElfServer.personality_name
}
# ----------------------------------- Installation/Uninstallation/Reinstallation ----------------------------------------

View File

@ -42,11 +42,9 @@ def run_async(func):
"""
async def wrapper(*args, **kwargs):
return await func(*args, **kwargs)
return asyncio.run(func(*args, **kwargs))
loop = asyncio.get_event_loop()
loop.run_until_complete(wrapper())
return wrapper()
def terminate_thread(thread):
if thread: