TimeRobber commited on
Commit
7b81044
1 Parent(s): 59216d7

Improve prompting

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -59,21 +59,30 @@ template = None
59
  prompt = None
60
  chain = None
61
 
 
 
 
62
  def formatted_message(audio_class):
63
- if cached_audio_class != audio_class:
64
- cached_audio_class = audio_class
 
 
65
 
66
- prefix = '''You are going to act as a magical tool that allows for humans to communicate with non-human entities like
67
- rocks, crackling fire, trees, animals, and the wind. In order to do this, we're going to provide you a data string which
68
- represents the audio input, the source of the audio, and the human's text input for the conversation.
69
- The goal is for you to embody the source of the audio, and use the length and variance in the signal data to produce
70
- plausible responses to the humans input. Remember to embody the the source data. When we start the conversation,
71
- you should generate a "personality profile" for the source and utilize that personality profile in your responses.
72
- Let's begin:'''
73
- suffix = f'''Source: {audio_class}
74
- Length of Audio in Seconds: {audio_length}
75
- Human Input: {userText}
76
- {audio_class} Response:'''
 
 
 
 
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)