mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-24 06:36:37 +00:00
started coding the fastAPI
This commit is contained in:
parent
59e4e48b91
commit
123b0fef72
15
endpoints/lollms_infos.py
Normal file
15
endpoints/lollms_infos.py
Normal file
@ -0,0 +1,15 @@
|
||||
from fastapi import APIRouter
|
||||
from lollms_webui import LoLLMSWebUI
|
||||
|
||||
router = APIRouter()
|
||||
lollmsWebUI = LoLLMSWebUI.get_instance()
|
||||
|
||||
@router.get("/users")
|
||||
def get_users():
|
||||
# Your code here
|
||||
pass
|
||||
|
||||
@router.post("/users")
|
||||
def create_user():
|
||||
# Your code here
|
||||
pass
|
70
lollms_webui.py
Normal file
70
lollms_webui.py
Normal file
@ -0,0 +1,70 @@
|
||||
"""
|
||||
File: lollms_web_ui.py
|
||||
Author: ParisNeo
|
||||
Description: Singleton class for the LoLLMS web UI.
|
||||
|
||||
This class provides a singleton instance of the LoLLMS web UI, allowing access to its functionality and data across multiple endpoints.
|
||||
"""
|
||||
|
||||
from lollms.app import LollmsApplication
|
||||
from lollms.main_config import LOLLMSConfig
|
||||
from lollms.paths import LollmsPaths
|
||||
|
||||
class LoLLMSWebUI(LollmsApplication):
|
||||
__instance = None
|
||||
|
||||
@staticmethod
|
||||
def build_instance(
|
||||
config: LOLLMSConfig,
|
||||
lollms_paths: LollmsPaths,
|
||||
load_binding=True,
|
||||
load_model=True,
|
||||
try_select_binding=False,
|
||||
try_select_model=False,
|
||||
callback=None,
|
||||
socketio = None
|
||||
):
|
||||
if LoLLMSWebUI.__instance is None:
|
||||
LoLLMSWebUI(
|
||||
config,
|
||||
lollms_paths,
|
||||
load_binding=load_binding,
|
||||
load_model=load_model,
|
||||
try_select_binding=try_select_binding,
|
||||
try_select_model=try_select_model,
|
||||
callback=callback,
|
||||
socketio=socketio
|
||||
)
|
||||
return LoLLMSWebUI.__instance
|
||||
@staticmethod
|
||||
def get_instance():
|
||||
return LoLLMSWebUI.__instance
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: LOLLMSConfig,
|
||||
lollms_paths: LollmsPaths,
|
||||
load_binding=True,
|
||||
load_model=True,
|
||||
try_select_binding=False,
|
||||
try_select_model=False,
|
||||
callback=None,
|
||||
socketio=None
|
||||
) -> None:
|
||||
super().__init__(
|
||||
"LoLLMSWebUI",
|
||||
config,
|
||||
lollms_paths,
|
||||
load_binding=load_binding,
|
||||
load_model=load_model,
|
||||
try_select_binding=try_select_binding,
|
||||
try_select_model=try_select_model,
|
||||
callback=callback,
|
||||
socketio=socketio
|
||||
)
|
||||
if LoLLMSWebUI.__instance is not None:
|
||||
raise Exception("This class is a singleton!")
|
||||
else:
|
||||
LoLLMSWebUI.__instance = self
|
||||
|
||||
# Other methods and properties of the LoLLMSWebUI singleton class
|
49
new_app.py
Normal file
49
new_app.py
Normal file
@ -0,0 +1,49 @@
|
||||
"""
|
||||
File: lollms_web_ui.py
|
||||
Author: ParisNeo
|
||||
Description: Singleton class for the LoLLMS web UI.
|
||||
|
||||
This file is the entry point to the webui.
|
||||
"""
|
||||
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from lollms.app import LollmsApplication
|
||||
from lollms.paths import LollmsPaths
|
||||
from lollms.main_config import LOLLMSConfig
|
||||
from lollms_webui import LoLLMSWebUI
|
||||
from pathlib import Path
|
||||
from ascii_colors import ASCIIColors
|
||||
import socketio
|
||||
import uvicorn
|
||||
import argparse
|
||||
|
||||
app = FastAPI()
|
||||
sio = socketio.AsyncServer(async_mode="asgi")
|
||||
|
||||
app.mount("/socket.io", socketio.ASGIApp(sio))
|
||||
#app.mount("/socket.io", StaticFiles(directory="path/to/socketio.js"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Parsong parameters
|
||||
parser = argparse.ArgumentParser(description="Start the chatbot FastAPI app.")
|
||||
|
||||
parser.add_argument(
|
||||
"--host", type=str, default=None, help="the hostname to listen on"
|
||||
)
|
||||
parser.add_argument("--port", type=int, default=None, help="the port to listen on")
|
||||
|
||||
args = parser.parse_args()
|
||||
root_path = Path(__file__).parent
|
||||
lollms_paths = LollmsPaths.find_paths(force_local=True, custom_default_cfg_path="configs/config.yaml")
|
||||
config = LOLLMSConfig.autoload(lollms_paths)
|
||||
if args.host:
|
||||
config.host=args.host
|
||||
if args.port:
|
||||
config.port=args.port
|
||||
|
||||
LoLLMSWebUI.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio)
|
||||
from endpoints.lollms_infos import *
|
||||
|
||||
uvicorn.run(app, host=config.host, port=config.port)
|
@ -18,4 +18,5 @@ beautifulsoup4
|
||||
packaging
|
||||
|
||||
fastapi
|
||||
uvicorn
|
||||
uvicorn
|
||||
python-socketio[asyncio_client]
|
||||
|
@ -151,10 +151,11 @@ goto end
|
||||
echo Install failed
|
||||
goto endend
|
||||
:end
|
||||
|
||||
cd
|
||||
cd scripts\python\lollms_installer
|
||||
call python main.py
|
||||
cd ..
|
||||
echo Installation complete.
|
||||
:endend
|
||||
|
||||
cd scripts\python\lollms_install
|
||||
call python main.py
|
||||
pause
|
||||
|
Loading…
Reference in New Issue
Block a user