working elf server

This commit is contained in:
Saifeddine ALOUI 2024-01-03 04:18:15 +01:00
parent 3581e608e5
commit c97a61a9e2
7 changed files with 161 additions and 13 deletions

1
lollms/server/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
elf_global_paths_cfg.yaml

1
lollms/server/configs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
local_config.yaml

View File

@ -0,0 +1,96 @@
# =================== Lord Of Large Language Models Configuration file ===========================
version: 39
binding_name: null
model_name: null
# Host information
host: localhost
port: 9601
# Genreration parameters
discussion_prompt_separator: "!@>"
seed: -1
n_predict: 1024
ctx_size: 4084
min_n_predict: 512
temperature: 0.9
top_k: 50
top_p: 0.95
repeat_last_n: 40
repeat_penalty: 1.2
n_threads: 8
#Personality parameters
personalities: ["generic/lollms"]
active_personality_id: 0
override_personality_model_parameters: false #if true the personality parameters are overriden by those of the configuration (may affect personality behaviour)
extensions: []
user_name: user
user_description: ""
use_user_name_in_discussions: false
user_avatar: default_user.svg
use_user_informations_in_discussion: false
# UI parameters
db_path: database.db
# Automatic updates
debug: False
auto_update: true
auto_save: true
auto_title: false
# Enables gpu usage
enable_gpu: true
# Automatically open the browser
auto_show_browser: true
# Voice service
enable_voice_service: false
xtts_base_url: http://127.0.0.1:8020
auto_read: false
current_voice: null
current_language: en
# Image generation service
enable_sd_service: false
sd_base_url: http://127.0.0.1:7860
# Audio
media_on: false
audio_in_language: 'en-US'
auto_speak: false
audio_out_voice: null
audio_pitch: 1
audio_auto_send_input: true
audio_silenceTimer: 5000
# Data vectorization
use_discussions_history: false # Activate vectorizing previous conversations
summerize_discussion: false # activate discussion summary (better but adds computation time)
max_summary_size: 512 # in tokens
data_vectorization_visualize_on_vectorization: false
use_files: true # Activate using files
data_vectorization_activate: true # To activate/deactivate data vectorization
data_vectorization_method: "tfidf_vectorizer" #"model_embedding" or "tfidf_vectorizer"
data_visualization_method: "PCA" #"PCA" or "TSNE"
data_vectorization_save_db: False # For each new session, new files
data_vectorization_chunk_size: 512 # chunk size
data_vectorization_overlap_size: 128 # overlap between chunks size
data_vectorization_nb_chunks: 2 # number of chunks to use
data_vectorization_build_keys_words: false # If true, when querrying the database, we use keywords generated from the user prompt instead of the prompt itself.
data_vectorization_force_first_chunk: false # If true, the first chunk of the document will systematically be used
data_vectorization_make_persistance: false # If true, the data will be persistant webween runs
# Helpers
pdf_latex_path: null
# boosting information
positive_boost: null
negative_boost: null
force_output_language_to_be: null

View File

@ -19,6 +19,8 @@ class LOLLMSElfServer(LollmsApplication):
lollms_paths: LollmsPaths,
load_binding=True,
load_model=True,
load_voice_service=True,
load_sd_service=True,
try_select_binding=False,
try_select_model=False,
callback=None,
@ -30,6 +32,8 @@ class LOLLMSElfServer(LollmsApplication):
lollms_paths,
load_binding=load_binding,
load_model=load_model,
load_sd_service=load_sd_service,
load_voice_service=load_voice_service,
try_select_binding=try_select_binding,
try_select_model=try_select_model,
callback=callback,
@ -46,6 +50,8 @@ class LOLLMSElfServer(LollmsApplication):
lollms_paths: LollmsPaths,
load_binding=True,
load_model=True,
load_voice_service=True,
load_sd_service=True,
try_select_binding=False,
try_select_model=False,
callback=None,
@ -57,6 +63,8 @@ class LOLLMSElfServer(LollmsApplication):
lollms_paths,
load_binding=load_binding,
load_model=load_model,
load_sd_service=load_sd_service,
load_voice_service=load_voice_service,
try_select_binding=try_select_binding,
try_select_model=try_select_model,
callback=callback,

View File

@ -0,0 +1,34 @@
from fastapi import APIRouter
from lollms.server.elf_server import LOLLMSElfServer
from pydantic import BaseModel
from starlette.responses import StreamingResponse
class GenerateRequest(BaseModel):
text: str
n_predict: int = 1024
stream: bool = False
router = APIRouter()
elf_server = LOLLMSElfServer.get_instance()
@router.post("/generate")
def generate(request_data: GenerateRequest):
text = request_data.text
n_predict = request_data.n_predict
stream = request_data.stream
if elf_server.binding is not None:
if stream:
def generate_chunks():
def callback(chunk):
# Yield each chunk of data
yield chunk
elf_server.binding.generate(text, n_predict, callback=callback)
return StreamingResponse(generate_chunks())
else:
output = elf_server.binding.generate(text, n_predict)
return output
else:
return None

View File

@ -1,15 +1,19 @@
from fastapi import APIRouter
from lollms_webui import LoLLMSWebUI
import pkg_resources
from lollms.server.elf_server import LOLLMSElfServer
from ascii_colors import ASCIIColors
router = APIRouter()
lollmsWebUI = LoLLMSWebUI.get_instance()
lollmsWebUI = LOLLMSElfServer.get_instance()
@router.get("/users")
def get_users():
# Your code here
pass
@router.get("/version")
def get_version():
"""
Get the version of the lollms package.
@router.post("/users")
def create_user():
# Your code here
pass
Returns:
dict: A dictionary containing the version of the lollms package.
"""
version = pkg_resources.get_distribution('lollms').version
ASCIIColors.yellow("Lollms version: " + version)
return {"version": version}

View File

@ -11,7 +11,7 @@ from fastapi.staticfiles import StaticFiles
from lollms.app import LollmsApplication
from lollms.paths import LollmsPaths
from lollms.main_config import LOLLMSConfig
from lollms.server.elf import LOLLMSElfServer
from lollms.server.elf_server import LOLLMSElfServer
from pathlib import Path
from ascii_colors import ASCIIColors
import socketio
@ -36,7 +36,7 @@ if __name__ == "__main__":
args = parser.parse_args()
root_path = Path(__file__).parent
lollms_paths = LollmsPaths.find_paths(force_local=True, custom_default_cfg_path="configs/config.yaml")
lollms_paths = LollmsPaths.find_paths(tool_prefix="elf_",force_local=True, custom_default_cfg_path="configs/config.yaml")
config = LOLLMSConfig.autoload(lollms_paths)
if args.host:
config.host=args.host
@ -44,6 +44,10 @@ if __name__ == "__main__":
config.port=args.port
LOLLMSElfServer.build_instance(config=config, lollms_paths=lollms_paths, socketio=sio)
from lollms.server.endpoints.lollms_infos import *
from lollms.server.endpoints.lollms_infos import router as lollms_infos_router
from lollms.server.endpoints.lollms_generator import router as lollms_generator_router
app.include_router(lollms_infos_router)
app.include_router(lollms_generator_router)
uvicorn.run(app, host=config.host, port=config.port)