forked from ILikeAI/AlwaysReddy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.py
31 lines (26 loc) · 1.07 KB
/
prompt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import importlib
def build_initial_messages(prompt_name):
"""
Get the initial prompt for the given prompt file name.
@param prompt_name: The name of the prompt file to use.
@return: The initial prompt as a list of dictionaries.
"""
if prompt_name is None or prompt_name is False:
return []
else:
return [{"role": "system", "content": get_system_prompt_message(prompt_name)}]
def get_system_prompt_message(prompt_name):
"""
Get the system prompt message for the given prompt file name.
@param prompt_name: The name of the prompt file to use.
@return: The system prompt message as a string.
"""
if prompt_name is None or prompt_name is False:
return ""
else:
try:
system_prompt = importlib.import_module(f"system_prompts.{prompt_name}")
except ModuleNotFoundError:
print(f"Error: System prompt '{prompt_name}' not found. Using default prompt.")
system_prompt = importlib.import_module("system_prompts.default_prompt")
return system_prompt.get_prompt()