conditionning is now separated from the configuration file

This commit is contained in:
Saifeddine ALOUI 2023-04-13 17:55:15 +02:00
parent a1b1a00e39
commit d52dbb16e1
4 changed files with 20 additions and 12 deletions

15
app.py
View File

@ -36,8 +36,9 @@ from config import load_config
class Gpt4AllWebUI:
def __init__(self, _app, config:dict) -> None:
def __init__(self, _app, config:dict, personality:dict) -> None:
self.config = config
self.personality = personality
self.current_discussion = None
self.app = _app
self.db_path = config["db_path"]
@ -135,7 +136,7 @@ class Gpt4AllWebUI:
# Create chatbot
self.chatbot_bindings = self.create_chatbot()
# Chatbot conditionning
self.condition_chatbot(self.config["personality_conditionning"])
self.condition_chatbot(self.personality["personality_conditionning"])
def create_chatbot(self):
@ -249,7 +250,7 @@ class Gpt4AllWebUI:
)
)
self.current_message = self.config["message_prefix"] + message + self.config["message_postfix"]
self.current_message = self.personality["message_prefix"] + message + self.personality["message_suffix"]
self.full_message += self.current_message
self.full_message_list.append(self.current_message)
@ -440,6 +441,10 @@ if __name__ == "__main__":
"-c", "--config", type=str, default="default", help="Sets the configuration file to be used."
)
parser.add_argument(
"-p", "--personality", type=str, default=None, help="Selects the personality to be using."
)
parser.add_argument(
"-s", "--seed", type=int, default=None, help="Force using a specific seed value."
)
@ -501,10 +506,12 @@ if __name__ == "__main__":
if arg_value is not None:
config[arg_name] = arg_value
personality = load_config(f"personalities/{config['personality']}.yaml")
executor = ThreadPoolExecutor(max_workers=2)
app.config['executor'] = executor
bot = Gpt4AllWebUI(app, config)
bot = Gpt4AllWebUI(app, config, personality)
if config["debug"]:
app.run(debug=True, host=config["host"], port=config["port"])

View File

@ -12,8 +12,4 @@ host: "localhost"
port: 9600
db_path: "database.db"
nb_messages_to_remember: 5
message_prefix: "\nuser:"
message_postfix: "\ngpt4all:"
personality_conditionning: |
Instruction: Act as gpt4all. A kind and helpful AI bot built to help users solve problems.
gpt4all:Welcome! I'm here to assist you with anything you need. What can I do for you today?
personality: "gpt4all_chatbot"

6
db.py
View File

@ -210,7 +210,7 @@ class Discussion:
self.discussion_id = discussion_id
self.discussions_db = discussions_db
def add_message(self, sender, content, message_type=0, rank=0):
def add_message(self, sender, content, message_type=0, rank=0, parent=0):
"""Adds a new message to the discussion
Args:
@ -221,8 +221,8 @@ class Discussion:
int: The added message id
"""
message_id = self.discussions_db.insert(
"INSERT INTO message (sender, content, type, rank, discussion_id) VALUES (?, ?, ?, ?, ?)",
(sender, content, message_type, rank, self.discussion_id)
"INSERT INTO message (sender, content, type, rank, parent, discussion_id) VALUES (?, ?, ?, ?, ?, ?)",
(sender, content, message_type, rank, parent, self.discussion_id)
)
return message_id

View File

@ -0,0 +1,5 @@
message_prefix: "\nuser:"
message_suffix: "\ngpt4all:"
personality_conditionning: |
Instruction: Act as gpt4all. A kind and helpful AI bot built to help users solve problems.
gpt4all:Welcome! I'm here to assist you with anything you need. What can I do for you today?