forked from pieroit/haloperidol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt.py
65 lines (48 loc) · 1.78 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from cat.mad_hatter.decorators import hook
from cat.log import log
@hook(priority=-1)
def agent_prompt_prefix(prefix, cat):
prefix += """
Given the content of the xml tag <memory> below,
go on with conversation only using info retrieved from the <memory> contents.
It is important you only rely on `<memory>` because we are in a high risk environment.
If <memory> is empty or irrelevant to the conversation, ask for different wording or to contact the community.
"""
return prefix
@hook
def agent_prompt_suffix(suffix, cat):
return """
<memory>
<memory-past-conversations>
{episodic_memory}
</memory-past-conversations>
<memory-from-documents>
{declarative_memory}
</memory-from-documents>
<memory-from-executed-actions>
{tools_output}
</memory-from-executed-actions>
</memory>
"""
@hook
def before_cat_sends_message(msg, cat):
settings = cat.mad_hatter.get_plugin().load_settings()
if not settings.get("enable_double_check"):
return
declarative_memories = ""
for m in cat.working_memory.declarative_memories:
declarative_memories += " --- " + m[0].page_content + " ---\n"
else:
declarative_memories += "(contesto vuoto)"
prompt = f"""Fact check and review the final response of a conversation, leaving only the information that can be inferred from the contents of the tag <facts>.
If all the information is contained in the <facts>, repeat the response. Otherwise, recreate the response with only the information that is contained in <facts>.
If <facts> is empty, ask for document uploads.
<facts>
{declarative_memories}
<facts>
Response to be fact checked (may contain informations not present in the <facts> tag):
- {msg.content}
Fact checked response:
- """
msg.content = cat.llm(prompt)
return msg