mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2024-12-19 12:27:52 +00:00
Merge branch 'lollms' into lollms-patchy2
This commit is contained in:
commit
56d5b9cdfd
@ -24,6 +24,7 @@ import requests
|
||||
from tqdm import tqdm
|
||||
import traceback
|
||||
import sys
|
||||
from lollms.console import MainMenu
|
||||
|
||||
__author__ = "parisneo"
|
||||
__github__ = "https://github.com/ParisNeo/lollms-webui"
|
||||
@ -325,7 +326,8 @@ class ModelProcess:
|
||||
print("No model loaded. Waiting for new configuration instructions")
|
||||
|
||||
self.ready = True
|
||||
ASCIIColors.print(ASCIIColors.color_bright_blue,f"Listening on :http://{self.config['host']}:{self.config['port']}")
|
||||
ASCIIColors.blue(f"Your personal data is stored here :{self.lollms_paths.personal_path}")
|
||||
ASCIIColors.blue(f"Listening on :http://{self.config['host']}:{self.config['port']}")
|
||||
while True:
|
||||
try:
|
||||
if not self.generate_queue.empty():
|
||||
@ -470,11 +472,16 @@ class ModelProcess:
|
||||
class LoLLMsAPPI():
|
||||
def __init__(self, config:LOLLMSConfig, socketio, config_file_path:str, lollms_paths: LollmsPaths) -> None:
|
||||
self.lollms_paths = lollms_paths
|
||||
self.config = config
|
||||
self.menu = MainMenu(self)
|
||||
|
||||
# Check model
|
||||
if config.model_name is None:
|
||||
self.menu.select_model()
|
||||
|
||||
self.socketio = socketio
|
||||
#Create and launch the process
|
||||
self.process = ModelProcess(self.lollms_paths, config)
|
||||
self.config = config
|
||||
self.binding = self.process.rebuild_binding(self.config)
|
||||
self.mounted_personalities = self.process.rebuild_personalities()
|
||||
if self.config["active_personality_id"]<len(self.mounted_personalities):
|
||||
@ -630,6 +637,37 @@ class LoLLMsAPPI():
|
||||
self._message_id = id
|
||||
|
||||
|
||||
def load_model(self):
|
||||
try:
|
||||
print("update_settings : New model selected")
|
||||
if hasattr(self,"process"):
|
||||
result = self.process.set_config(self.config)
|
||||
print("Set config results:")
|
||||
print(result)
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load model.Process returned exception : {ex}")
|
||||
ASCIIColors.error(f"Binding returned this exception : {ex}")
|
||||
ASCIIColors.error(f"{self.config.get_model_path_infos()}")
|
||||
print("Please select a valid model or install a new one from a url")
|
||||
self.menu.select_model()
|
||||
|
||||
|
||||
def load_personality(self):
|
||||
try:
|
||||
print("update_settings : New personality selected")
|
||||
if hasattr(self,"process"):
|
||||
result = self.process.set_config(self.config)
|
||||
print("Set config results:")
|
||||
print(result)
|
||||
except Exception as ex:
|
||||
ASCIIColors.error(f"Couldn't load personality. Please verify your configuration file at {self.configuration_path} or use the next menu to select a valid personality")
|
||||
ASCIIColors.error(f"Binding returned this exception : {ex}")
|
||||
ASCIIColors.error(f"{self.config.get_personality_path_infos()}")
|
||||
print("Please select a valid model or install a new one from a url")
|
||||
self.menu.select_model()
|
||||
self.cond_tk = self.personality.model.tokenize(self.personality.personality_conditioning)
|
||||
self.n_cond_tk = len(self.cond_tk)
|
||||
|
||||
def download_file(self, url, installation_path, callback=None):
|
||||
"""
|
||||
Downloads a file from a URL, reports the download progress using a callback function, and displays a progress bar.
|
||||
@ -676,7 +714,9 @@ class LoLLMsAPPI():
|
||||
self.personality.name, self.personality.welcome_message,
|
||||
DiscussionsDB.MSG_TYPE_NORMAL,
|
||||
0,
|
||||
-1,model = self.config["model_name"],
|
||||
-1,
|
||||
binding= self.config["binding_name"],
|
||||
model = self.config["model_name"],
|
||||
personality=self.config["personalities"][self.config["active_personality_id"]]
|
||||
)
|
||||
|
||||
|
52
api/db.py
52
api/db.py
@ -1,6 +1,7 @@
|
||||
|
||||
import sqlite3
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
__author__ = "parisneo"
|
||||
__github__ = "https://github.com/ParisNeo/lollms-webui"
|
||||
__copyright__ = "Copyright 2023, "
|
||||
@ -20,7 +21,7 @@ class DiscussionsDB:
|
||||
"""
|
||||
create database schema
|
||||
"""
|
||||
db_version = 4
|
||||
db_version = 5
|
||||
# Verify encoding and change it if it is not complient
|
||||
with sqlite3.connect(self.db_path) as conn:
|
||||
# Execute a PRAGMA statement to get the current encoding of the database
|
||||
@ -65,6 +66,7 @@ class DiscussionsDB:
|
||||
cursor.execute("""
|
||||
CREATE TABLE message (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
binding TEXT,
|
||||
model TEXT,
|
||||
personality TEXT,
|
||||
sender TEXT NOT NULL,
|
||||
@ -118,6 +120,10 @@ class DiscussionsDB:
|
||||
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN model TEXT DEFAULT ''") # Added in V4
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN personality INT DEFAULT ''") # Added in V4
|
||||
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN binding TEXT DEFAULT ''") # Added in V5
|
||||
|
||||
|
||||
except :
|
||||
pass
|
||||
# Upgrade the schema to version 1
|
||||
@ -131,6 +137,7 @@ class DiscussionsDB:
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN model TEXT DEFAULT ''") # Added in V4
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN personality INT DEFAULT ''") # Added in V4
|
||||
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN binding TEXT DEFAULT ''") # Added in V5
|
||||
except :
|
||||
pass
|
||||
# Upgrade the schema to version 1
|
||||
@ -142,6 +149,15 @@ class DiscussionsDB:
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN model TEXT DEFAULT ''") # Added in V4
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN personality INT DEFAULT ''") # Added in V4
|
||||
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN binding TEXT DEFAULT ''") # Added in V5
|
||||
except :
|
||||
pass
|
||||
elif version < 5:
|
||||
print(f"Upgrading schema to version {db_version}...")
|
||||
# Add the 'created_at' column to the 'message' table
|
||||
if message_table_exist:
|
||||
try:
|
||||
cursor.execute("ALTER TABLE message ADD COLUMN binding TEXT DEFAULT ''") # Added in V5
|
||||
except :
|
||||
pass
|
||||
# Update the schema version
|
||||
@ -259,15 +275,20 @@ class DiscussionsDB:
|
||||
discussion_id = row[0]
|
||||
discussion_title = row[1]
|
||||
discussion = {"id": discussion_id, "title":discussion_title, "messages": []}
|
||||
rows = self.select(f"SELECT * FROM message WHERE discussion_id=?",(discussion_id,))
|
||||
rows = self.select(f"SELECT sender, content, message_type, rank, parent, binding, model, personality, created_at FROM message WHERE discussion_id=?",(discussion_id,))
|
||||
for message_row in rows:
|
||||
sender = message_row[1]
|
||||
content = message_row[2]
|
||||
content_type = message_row[3]
|
||||
rank = message_row[4]
|
||||
parent = message_row[5]
|
||||
binding = message_row[6]
|
||||
model = message_row[7]
|
||||
personality = message_row[8]
|
||||
created_at = message_row[9]
|
||||
|
||||
discussion["messages"].append(
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent}
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent, "binding": binding, "model":model, "personality":personality, "created_at":created_at}
|
||||
)
|
||||
discussions.append(discussion)
|
||||
return discussions
|
||||
@ -285,15 +306,20 @@ class DiscussionsDB:
|
||||
discussion_id = row[0]
|
||||
discussion_title = row[1]
|
||||
discussion = {"id": discussion_id, "title":discussion_title, "messages": []}
|
||||
rows = self.select(f"SELECT * FROM message WHERE discussion_id=?",(discussion_id,))
|
||||
rows = self.select(f"SELECT sender, content, message_type, rank, parent, binding, model, personality, created_at FROM message WHERE discussion_id=?",(discussion_id,))
|
||||
for message_row in rows:
|
||||
sender = message_row[1]
|
||||
content = message_row[2]
|
||||
content_type = message_row[3]
|
||||
rank = message_row[4]
|
||||
parent = message_row[5]
|
||||
binding = message_row[6]
|
||||
model = message_row[7]
|
||||
personality = message_row[8]
|
||||
created_at = message_row[9]
|
||||
|
||||
discussion["messages"].append(
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent}
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent, "binding": binding, "model":model, "personality":personality, "created_at":created_at}
|
||||
)
|
||||
discussions.append(discussion)
|
||||
return discussions
|
||||
@ -316,8 +342,12 @@ class DiscussionsDB:
|
||||
content_type = message_data.get("type")
|
||||
rank = message_data.get("rank")
|
||||
parent = message_data.get("parent")
|
||||
binding = message_data.get("binding","")
|
||||
model = message_data.get("model","")
|
||||
personality = message_data.get("personality","")
|
||||
created_at = message_data.get("created_at",datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
||||
discussion["messages"].append(
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent}
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "model": model, "binding": binding, "personality": personality, "created_at": created_at}
|
||||
)
|
||||
|
||||
# Insert message into the database
|
||||
@ -333,7 +363,7 @@ class Discussion:
|
||||
self.discussion_id = discussion_id
|
||||
self.discussions_db = discussions_db
|
||||
|
||||
def add_message(self, sender, content, message_type=0, rank=0, parent=0, model ="", personality=""):
|
||||
def add_message(self, sender, content, message_type=0, rank=0, parent=0, binding="", model ="", personality="", created_at=datetime.now().strftime('%Y-%m-%d %H:%M:%S')):
|
||||
"""Adds a new message to the discussion
|
||||
|
||||
Args:
|
||||
@ -344,8 +374,8 @@ class Discussion:
|
||||
int: The added message id
|
||||
"""
|
||||
message_id = self.discussions_db.insert(
|
||||
"INSERT INTO message (sender, content, type, rank, parent, model, personality, discussion_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(sender, content, message_type, rank, parent, model, personality, self.discussion_id)
|
||||
"INSERT INTO message (sender, content, type, rank, parent, binding, model, personality, created_at, discussion_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||
(sender, content, message_type, rank, parent, binding, model, personality, created_at, self.discussion_id)
|
||||
)
|
||||
return message_id
|
||||
|
||||
@ -376,10 +406,10 @@ class Discussion:
|
||||
list: List of entries in the format {"id":message id, "sender":sender name, "content":message content, "type":message type, "rank": message rank}
|
||||
"""
|
||||
rows = self.discussions_db.select(
|
||||
"SELECT id, sender, content, type, rank, parent, model, personality FROM message WHERE discussion_id=?", (self.discussion_id,)
|
||||
"SELECT id, sender, content, type, rank, parent, binding, model, personality, created_at FROM message WHERE discussion_id=?", (self.discussion_id,)
|
||||
)
|
||||
|
||||
return [{"id": row[0], "sender": row[1], "content": row[2], "type": row[3], "rank": row[4], "parent": row[5], "model": row[6], "personality": row[7]} for row in rows]
|
||||
return [{"id": row[0], "sender": row[1], "content": row[2], "type": row[3], "rank": row[4], "parent": row[5], "binding":row[6], "model": row[7], "personality": row[8], "created_at": row[9]} for row in rows]
|
||||
|
||||
def update_message(self, message_id, new_content):
|
||||
"""Updates the content of a message
|
||||
|
12
app.py
12
app.py
@ -72,7 +72,6 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
|
||||
self.app = _app
|
||||
self.cancel_gen = False
|
||||
|
||||
|
||||
app.template_folder = "web/dist"
|
||||
|
||||
@ -440,7 +439,11 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
else:
|
||||
self.config["active_personality_id"] = 0
|
||||
self.config["personalities"][self.config["active_personality_id"]] = f"{self.personality_language}/{self.personality_category}/{self.personality_name}"
|
||||
personality_fn = self.lollms_paths.personalities_zoo_path/self.config["personalities"][self.config["active_personality_id"]]
|
||||
|
||||
if self.personality_category!="Custom":
|
||||
personality_fn = self.lollms_paths.personalities_zoo_path/self.config["personalities"][self.config["active_personality_id"]]
|
||||
else:
|
||||
personality_fn = self.lollms_paths.personal_personalities_path/self.config["personalities"][self.config["active_personality_id"]].split("/")[-1]
|
||||
self.personality.load_personality(personality_fn)
|
||||
else:
|
||||
self.config["personalities"].append(f"{self.personality_language}/{self.personality_category}/{self.personality_name}")
|
||||
@ -482,12 +485,15 @@ class LoLLMsWebUI(LoLLMsAPPI):
|
||||
return jsonify({'setting_name': data['setting_name'], "status":True})
|
||||
|
||||
|
||||
|
||||
def apply_settings(self):
|
||||
result = self.process.set_config(self.config)
|
||||
print("Set config results:")
|
||||
print(result)
|
||||
return jsonify(result)
|
||||
|
||||
|
||||
|
||||
def ram_usage(self):
|
||||
"""
|
||||
Returns the RAM usage in bytes.
|
||||
@ -1198,7 +1204,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Configuration loading part
|
||||
config = LOLLMSConfig.autoload(lollms_paths)
|
||||
|
||||
|
||||
# Override values in config with command-line arguments
|
||||
for arg_name, arg_value in vars(args).items():
|
||||
if arg_value is not None:
|
||||
|
@ -1,6 +1,6 @@
|
||||
# =================== Lord Of Large Language Models Configuration file ===========================
|
||||
version: 7
|
||||
binding_name: gpt4all
|
||||
binding_name: c_transformers
|
||||
model_name: ggml-gpt4all-j-v1.3-groovy.bin
|
||||
|
||||
# Host information
|
||||
|
File diff suppressed because one or more lines are too long
1
web/dist/assets/index-d5a22ec2.css
vendored
1
web/dist/assets/index-d5a22ec2.css
vendored
File diff suppressed because one or more lines are too long
1
web/dist/assets/index-f4e7668c.css
vendored
Normal file
1
web/dist/assets/index-f4e7668c.css
vendored
Normal file
File diff suppressed because one or more lines are too long
4
web/dist/index.html
vendored
4
web/dist/index.html
vendored
@ -6,8 +6,8 @@
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>GPT4All - WEBUI</title>
|
||||
<script type="module" crossorigin src="/assets/index-5903b487.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-d5a22ec2.css">
|
||||
<script type="module" crossorigin src="/assets/index-76dfba09.js"></script>
|
||||
<link rel="stylesheet" href="/assets/index-f4e7668c.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
Loading…
Reference in New Issue
Block a user