mirror of
https://github.com/ParisNeo/lollms-webui.git
synced 2025-01-20 03:36:26 +00:00
Merge branch 'main' into small-fixes
This commit is contained in:
commit
c873a6d69b
29
app.py
29
app.py
@ -222,6 +222,15 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
"/reset", "reset", self.reset, methods=["GET"]
|
||||
)
|
||||
|
||||
self.add_endpoint(
|
||||
"/export_multiple_discussions", "export_multiple_discussions", self.export_multiple_discussions, methods=["POST"]
|
||||
)
|
||||
|
||||
def export_multiple_discussions(self):
|
||||
data = request.get_json()
|
||||
discussion_ids = data["discussion_ids"]
|
||||
return jsonify(self.db.export_discussions_to_json(discussion_ids))
|
||||
|
||||
|
||||
def reset(self):
|
||||
os.kill(os.getpid(), signal.SIGINT) # Send the interrupt signal to the current process
|
||||
@ -445,7 +454,10 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
|
||||
|
||||
def apply_settings(self):
|
||||
return jsonify(self.process.set_config(self.config))
|
||||
result = self.process.set_config(self.config)
|
||||
print("Set config results:")
|
||||
print(result)
|
||||
return jsonify(result)
|
||||
|
||||
def list_backends(self):
|
||||
backends_dir = Path('./backends') # replace with the actual path to the models folder
|
||||
@ -677,8 +689,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
self.backend = backend_
|
||||
self.config['model'] = models[0]
|
||||
# Build chatbot
|
||||
self.process.set_config(self.config)
|
||||
return jsonify({"status": "ok"})
|
||||
return jsonify(self.process.set_config(self.config))
|
||||
else:
|
||||
return jsonify({"status": "no_models_found"})
|
||||
|
||||
@ -690,11 +701,10 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
if self.config['model']!= model:
|
||||
print("set_model: New model selected")
|
||||
self.config['model'] = model
|
||||
# Build chatbot
|
||||
self.process.set_config(self.config)
|
||||
return jsonify({"status": "ok"})
|
||||
# Build chatbot
|
||||
return jsonify(self.process.set_config(self.config))
|
||||
|
||||
return jsonify({"status": "error"})
|
||||
return jsonify({"status": "succeeded"})
|
||||
|
||||
def update_model_params(self):
|
||||
data = request.get_json()
|
||||
@ -709,7 +719,6 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
|
||||
self.config['backend'] = backend
|
||||
self.config['model'] = model
|
||||
self.process.set_config(self.config)
|
||||
|
||||
self.config['personality_language'] = personality_language
|
||||
self.config['personality_category'] = personality_category
|
||||
@ -732,7 +741,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
|
||||
save_config(self.config, self.config_file_path)
|
||||
|
||||
self.process.set_config(self.config)
|
||||
|
||||
# Fixed missing argument
|
||||
self.backend = self.process.rebuild_backend(self.config)
|
||||
|
||||
@ -754,7 +763,7 @@ class Gpt4AllWebUI(GPT4AllAPI):
|
||||
print(f"\trepeat_last_n:{self.config['repeat_last_n']}")
|
||||
print("==============================================")
|
||||
|
||||
return jsonify({"status":"ok"})
|
||||
return jsonify(self.process.set_config(self.config))
|
||||
|
||||
|
||||
def get_available_models(self):
|
||||
|
@ -179,12 +179,11 @@ class ModelProcess:
|
||||
print("Couldn't build backend.")
|
||||
print(ex)
|
||||
backend = None
|
||||
self._set_config_result['backend_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't build backend:{ex}")
|
||||
return backend
|
||||
|
||||
def _rebuild_model(self):
|
||||
try:
|
||||
self.reset_config_result()
|
||||
print(" ******************* Building Backend from generation Process *************************")
|
||||
self.backend = self.load_backend(self.config["backend"], install=True)
|
||||
print("Backend loaded successfully")
|
||||
@ -199,14 +198,18 @@ class ModelProcess:
|
||||
print("Couldn't build model")
|
||||
print(ex)
|
||||
self.model = None
|
||||
self._set_config_result['model_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't build model:{ex}")
|
||||
self._set_config_result['status'] ='failed'
|
||||
self._set_config_result['backend_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't build backend:{ex}")
|
||||
except Exception as ex:
|
||||
traceback.print_exc()
|
||||
print("Couldn't build backend")
|
||||
print(ex)
|
||||
self.backend = None
|
||||
self.model = None
|
||||
self._set_config_result['status'] ='failed'
|
||||
self._set_config_result['backend_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't build backend:{ex}")
|
||||
|
||||
def rebuild_personality(self):
|
||||
try:
|
||||
@ -224,6 +227,7 @@ class ModelProcess:
|
||||
|
||||
def _rebuild_personality(self):
|
||||
try:
|
||||
self.reset_config_result()
|
||||
print(f" ******************* Building Personality {self.config['personality']} from generation Process *************************")
|
||||
personality_path = f"personalities/{self.config['personality_language']}/{self.config['personality_category']}/{self.config['personality']}"
|
||||
self.personality = AIPersonality(personality_path)
|
||||
@ -235,8 +239,9 @@ class ModelProcess:
|
||||
if self.config["debug"]:
|
||||
print(ex)
|
||||
self.personality = AIPersonality()
|
||||
self._set_config_result['personality_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't load personality:{ex}")
|
||||
self._set_config_result['status'] ='failed'
|
||||
self._set_config_result['backend_status'] ='failed'
|
||||
self._set_config_result['errors'].append(f"couldn't build backend:{ex}")
|
||||
|
||||
def step_callback(self, text, message_type):
|
||||
self.generation_queue.put((text,self.id, message_type))
|
||||
|
@ -250,6 +250,30 @@ class DiscussionsDB:
|
||||
return discussions
|
||||
|
||||
|
||||
def export_discussions_to_json(self, discussions_ids:list):
|
||||
# Convert the list of discussion IDs to a tuple
|
||||
discussions_ids_tuple = tuple(discussions_ids)
|
||||
db_discussions = self.select("SELECT * FROM discussion WHERE discussion_id IN ({})".format(
|
||||
','.join(['?'] * len(discussions_ids_tuple))
|
||||
))
|
||||
discussions = []
|
||||
for row in db_discussions:
|
||||
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,))
|
||||
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]
|
||||
discussion["messages"].append(
|
||||
{"sender": sender, "content": content, "type": content_type, "rank": rank, "parent": parent}
|
||||
)
|
||||
discussions.append(discussion)
|
||||
return discussions
|
||||
|
||||
class Discussion:
|
||||
def __init__(self, discussion_id, discussions_db:DiscussionsDB):
|
||||
self.discussion_id = discussion_id
|
||||
|
Loading…
Reference in New Issue
Block a user