You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.0 KiB
Python

import time
from libs.config import Config
def get_prompt(name: str, type: str, params: dict = {}):
sys_params = {
"bot_name": Config.get("chatcomplete.bot_name", "ChatGPT"),
}
prompts = Config.get("chatcomplete.prompts")
if name in prompts and type in prompts[name]:
prompt: str = prompts[name][type]
for key in sys_params:
prompt = prompt.replace("{" + key + "}", sys_params[key])
for key in params:
prompt = prompt.replace("{" + key + "}", params[key])
return prompt
else:
return None
def format_prompt(prompt: str, params: dict = {}):
sys_params = {
"bot_name": Config.get("chatcomplete.bot_name", "ChatGPT"),
"current_date": time.strftime("%Y-%m-%d", time.localtime()),
"current_time": time.strftime("%H:%M:%S", time.localtime()),
}
for key in sys_params:
prompt = prompt.replace("{" + key + "}", sys_params[key])
for key in params:
prompt = prompt.replace("{" + key + "}", params[key])
return prompt