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