2024-01-06 01:05:07 +00:00
|
|
|
"""
|
|
|
|
project: lollms_webui
|
|
|
|
file: lollms_webui_infos.py
|
|
|
|
author: ParisNeo
|
|
|
|
description:
|
|
|
|
This module contains a set of FastAPI routes that provide information about the Lord of Large Language and Multimodal Systems (LoLLMs) Web UI
|
|
|
|
application. These routes allow users to retrieve details such as the current version number, a list of available databases, and options for
|
|
|
|
updating or restarting the software.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
from fastapi import APIRouter, Request
|
|
|
|
import pkg_resources
|
|
|
|
from lollms_webui import LOLLMSWebUI
|
|
|
|
from ascii_colors import ASCIIColors
|
2024-01-18 00:07:41 +00:00
|
|
|
from lollms.utilities import load_config, run_async
|
2024-01-06 01:05:07 +00:00
|
|
|
from pathlib import Path
|
|
|
|
from typing import List
|
|
|
|
import sys
|
2024-01-13 23:42:18 +00:00
|
|
|
import socketio
|
2024-01-18 00:07:41 +00:00
|
|
|
import time
|
2024-01-09 22:26:41 +00:00
|
|
|
# ----------------------- Defining router and main class ------------------------------
|
|
|
|
|
2024-01-06 01:05:07 +00:00
|
|
|
# Create an instance of the LoLLMSWebUI class
|
2024-01-13 09:31:43 +00:00
|
|
|
lollmsElfServer:LOLLMSWebUI = LOLLMSWebUI.get_instance()
|
2024-01-06 01:05:07 +00:00
|
|
|
router = APIRouter()
|
|
|
|
|
2024-03-18 21:30:18 +00:00
|
|
|
|
|
|
|
@router.get("/get_versionID")
|
|
|
|
async def get_lollms_webui_version():
|
|
|
|
"""Get the version of the LoLLMs Web UI application."""
|
|
|
|
# Return the version string
|
2024-03-18 23:23:37 +00:00
|
|
|
return {"id":3}
|
2024-03-18 21:30:18 +00:00
|
|
|
|
2024-01-06 01:05:07 +00:00
|
|
|
@router.get("/get_lollms_webui_version")
|
|
|
|
async def get_lollms_webui_version():
|
|
|
|
"""Get the version of the LoLLMs Web UI application."""
|
|
|
|
# Return the version string
|
|
|
|
return lollmsElfServer.version
|
|
|
|
|
|
|
|
|
|
|
|
@router.get("/restart_program")
|
|
|
|
async def restart_program():
|
2024-01-24 11:08:07 +00:00
|
|
|
"""Restart the program."""
|
2024-02-17 23:14:52 +00:00
|
|
|
if lollmsElfServer.config.headless_server_mode:
|
|
|
|
return {"status":False,"error":"Restarting app is blocked when in headless mode for obvious security reasons!"}
|
|
|
|
|
2024-02-19 22:03:59 +00:00
|
|
|
if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1":
|
2024-02-17 23:14:52 +00:00
|
|
|
return {"status":False,"error":"Restarting app is blocked when the server is exposed outside for very obvious reasons!"}
|
|
|
|
|
2024-01-24 11:08:07 +00:00
|
|
|
lollmsElfServer.ShowBlockingMessage("Restarting program.\nPlease stand by...")
|
|
|
|
# Stop the socketIO server
|
|
|
|
run_async(lollmsElfServer.sio.shutdown)
|
|
|
|
# Sleep for 1 second before rebooting
|
|
|
|
time.sleep(1)
|
|
|
|
lollmsElfServer.HideBlockingMessage()
|
|
|
|
# Reboot the program
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info(" ╔══════════════════════════════════════════════════╗")
|
|
|
|
ASCIIColors.info(" ║ Restarting backend ║")
|
|
|
|
ASCIIColors.info(" ╚══════════════════════════════════════════════════╝")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
lollmsElfServer.run_restart_script(lollmsElfServer.args)
|
|
|
|
|
2024-01-06 01:05:07 +00:00
|
|
|
@router.get("/update_software")
|
|
|
|
async def update_software():
|
2024-01-24 11:08:07 +00:00
|
|
|
"""Update the software."""
|
2024-02-17 23:14:52 +00:00
|
|
|
if lollmsElfServer.config.headless_server_mode:
|
2024-02-18 23:23:15 +00:00
|
|
|
return {"status":False,"error":"Updating app is blocked when in headless mode for obvious security reasons!"}
|
2024-02-17 23:14:52 +00:00
|
|
|
|
2024-02-19 22:03:59 +00:00
|
|
|
if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1":
|
2024-02-18 23:23:15 +00:00
|
|
|
return {"status":False,"error":"Updating app is blocked when the server is exposed outside for very obvious reasons!"}
|
2024-02-17 23:14:52 +00:00
|
|
|
|
2024-01-24 11:08:07 +00:00
|
|
|
# Display an informative message
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("╔══════════════════════════════════════════════════╗")
|
|
|
|
ASCIIColors.info("║ Updating backend ║")
|
|
|
|
ASCIIColors.info("╚══════════════════════════════════════════════════╝")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
ASCIIColors.info("")
|
|
|
|
# Stop the socketIO server
|
|
|
|
await lollmsElfServer.sio.shutdown()
|
|
|
|
# Sleep for 1 second before rebooting
|
|
|
|
time.sleep(1)
|
2024-01-13 23:42:18 +00:00
|
|
|
|
2024-01-24 11:08:07 +00:00
|
|
|
# Run the update script using the provided arguments
|
|
|
|
lollmsElfServer.run_update_script(lollmsElfServer.args)
|
|
|
|
# Exit the program after successful update
|
|
|
|
sys.exit()
|
2024-01-06 01:05:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
@router.get("/check_update")
|
|
|
|
def check_update():
|
|
|
|
"""Checks if an update is available"""
|
2024-02-17 23:14:52 +00:00
|
|
|
if lollmsElfServer.config.headless_server_mode:
|
2024-02-18 23:23:15 +00:00
|
|
|
return {"status":False,"error":"Checking updates is blocked when in headless mode for obvious security reasons!"}
|
2024-02-17 23:14:52 +00:00
|
|
|
|
2024-02-19 22:03:59 +00:00
|
|
|
if lollmsElfServer.config.host!="localhost" and lollmsElfServer.config.host!="127.0.0.1":
|
2024-02-18 23:23:15 +00:00
|
|
|
return {"status":False,"error":"Checking updates is blocked when the server is exposed outside for very obvious reasons!"}
|
2024-02-17 23:14:52 +00:00
|
|
|
|
2024-01-06 01:05:07 +00:00
|
|
|
if lollmsElfServer.config.auto_update:
|
|
|
|
res = lollmsElfServer.check_update_()
|
|
|
|
return {'update_availability':res}
|
|
|
|
else:
|
|
|
|
return {'update_availability':False}
|