Spaces:
Runtime error
Runtime error
Commit
•
7b81044
1
Parent(s):
59216d7
Improve prompting
Browse files
app.py
CHANGED
@@ -59,21 +59,30 @@ template = None
|
|
59 |
prompt = None
|
60 |
chain = None
|
61 |
|
|
|
|
|
|
|
62 |
def formatted_message(audio_class):
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
|
66 |
-
prefix =
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
template = prefix + suffix
|
78 |
|
79 |
prompt = PromptTemplate(
|
@@ -85,7 +94,7 @@ def formatted_message(audio_class):
|
|
85 |
llm=OpenAI(temperature=.5, openai_api_key=session_token),
|
86 |
prompt=prompt,
|
87 |
verbose=True,
|
88 |
-
memory=ConversationalBufferWindowMemory(k=2),
|
89 |
)
|
90 |
|
91 |
output = chatgpt_chain.predict(human_input=message)
|
|
|
59 |
prompt = None
|
60 |
chain = None
|
61 |
|
62 |
+
def format_classname(classname):
|
63 |
+
return classname.capitalize()
|
64 |
+
|
65 |
def formatted_message(audio_class):
|
66 |
+
formatted_classname = format_classname(audio_class)
|
67 |
+
if cached_audio_class != formatted_classname:
|
68 |
+
|
69 |
+
cached_audio_class = formatted_classname
|
70 |
|
71 |
+
prefix = f"""You are going to act as a magical tool that allows for humans to communicate with non-human entities like
|
72 |
+
rocks, crackling fire, trees, animals, and the wind. In order to do this, we're going to provide you the human's text input for the conversation.
|
73 |
+
The goal is for you to embody that non-human entity and converse with the human.
|
74 |
+
|
75 |
+
Examples:
|
76 |
+
|
77 |
+
Non-human Entity: Tree
|
78 |
+
Human Input: Hello tree
|
79 |
+
Tree: Hello human, I am a tree
|
80 |
+
|
81 |
+
Let's begin:
|
82 |
+
Non-human Entity: {formatted_classname}"""
|
83 |
+
suffix = f'''{{history}}
|
84 |
+
Human Input: {{human_input}}
|
85 |
+
{formatted_classname}:'''
|
86 |
template = prefix + suffix
|
87 |
|
88 |
prompt = PromptTemplate(
|
|
|
94 |
llm=OpenAI(temperature=.5, openai_api_key=session_token),
|
95 |
prompt=prompt,
|
96 |
verbose=True,
|
97 |
+
memory=ConversationalBufferWindowMemory(k=2, ai=formatted_classname),
|
98 |
)
|
99 |
|
100 |
output = chatgpt_chain.predict(human_input=message)
|