mirror of
https://github.com/Paillat-dev/Botator.git
synced 2026-01-02 17:24:55 +00:00
🐛 fix(ChatProcess.py): fix logic error in the return criteria for determining if the bot should respond to a message 🐛 fix(ChatProcess.py): fix typo in the 'functions' variable name 🐛 fix(ChatProcess.py): fix typo in the 'functions' parameter name in the request function call 🐛 fix(ChatProcess.py): fix typo in the 'functions' parameter name in the processFunctioncallResponse function call 🐛 fix(ChatProcess.py): remove unnecessary print statement in the processMessage function 🐛 fix(prompts.py): remove unnecessary print statement in the createPrompt function 🐛 fix(channelSetup.py): fix logic error in the is_owner function call 🐛 fix(moderation.py): remove unnecessary code for disabling moderation 🐛 fix(config.py): remove unnecessary code for creating tables in the database 🐛 fix(functionscalls.py): fix type hint for the return value of the call_function function 🐛 fix(guild.py): fix handling of serialized data in the load function 🐛 fix(SqlConnector.py): create setup_data table if it does not exist
78 lines
2.3 KiB
Python
78 lines
2.3 KiB
Python
import datetime
|
|
|
|
from src.utils.variousclasses import models, characters, apis
|
|
|
|
promts = {}
|
|
for character in characters.reverseMatchingDict.keys():
|
|
with open(
|
|
f"src/chatUtils/prompts/{character}/chat.txt", "r", encoding="utf-8"
|
|
) as f:
|
|
promts[character] = {}
|
|
promts[character]["chat"] = f.read()
|
|
|
|
with open(
|
|
f"src/chatUtils/prompts/{character}/text.txt", "r", encoding="utf-8"
|
|
) as f:
|
|
promts[character]["text"] = f.read()
|
|
|
|
|
|
def createPrompt(
|
|
messages: list[dict],
|
|
model: str,
|
|
character: str,
|
|
modeltype: str,
|
|
guildName: str,
|
|
channelName: str,
|
|
) -> str | list[dict]:
|
|
"""
|
|
Creates a prompt from the messages list
|
|
"""
|
|
if modeltype == "chat":
|
|
prompt = createChatPrompt(messages, model, character)
|
|
sysprompt = prompt[0]["content"]
|
|
sysprompt = (
|
|
sysprompt.replace("[server-name]", guildName)
|
|
.replace("[channel-name]", channelName)
|
|
.replace(
|
|
"[datetime]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")
|
|
)
|
|
)
|
|
prompt[0]["content"] = sysprompt
|
|
elif modeltype == "text":
|
|
prompt = (
|
|
createTextPrompt(messages, model, character)
|
|
.replace("[server-name]", guildName)
|
|
.replace("[channel-name]", channelName)
|
|
.replace(
|
|
"[datetime]", datetime.datetime.utcnow().strftime("%d/%m/%Y %H:%M:%S")
|
|
)
|
|
)
|
|
else:
|
|
raise ValueError("Invalid type")
|
|
return prompt
|
|
|
|
|
|
def createTextPrompt(messages: list[dict], model: str, character: str) -> str:
|
|
"""
|
|
Creates a text prompt from the messages list
|
|
"""
|
|
global promts
|
|
prompt = promts[character]["text"]
|
|
for message in messages:
|
|
if message["name"] == "assistant":
|
|
message["name"] = character
|
|
prompt += f"{message['name']}: {message['content']} <|endofmessage|>\n"
|
|
prompt += f"{character}:"
|
|
return prompt
|
|
|
|
|
|
def createChatPrompt(messages: list[dict], model: str, character: str) -> str:
|
|
"""
|
|
Creates a chat prompt from the messages list
|
|
"""
|
|
global promts
|
|
prompt = promts[character]["chat"]
|
|
final_prompt = [{"role": "system", "content": prompt}]
|
|
final_prompt.extend(messages)
|
|
return final_prompt
|