halimbahae commited on
Commit
f9fe40e
·
verified ·
1 Parent(s): e3b619a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +88 -8
app.py CHANGED
@@ -39,15 +39,96 @@ def respond(
39
  response += token
40
  yield response
41
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  demo = gr.ChatInterface(
46
- respond,
47
  additional_inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  gr.Slider(
52
  minimum=0.1,
53
  maximum=1.0,
@@ -58,6 +139,5 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
61
-
62
  if __name__ == "__main__":
63
- demo.launch()
 
39
  response += token
40
  yield response
41
 
42
+
43
+ # Define the prompt template
44
+ prompt_template = """
45
+ Act as an expert in prompt engineering. Your task is to deeply understand what the user wants, and in return respond with a well-crafted prompt that, if fed to a separate AI, will get the exact result the user desires.
46
+
47
+ ### Task:
48
+ {task}
49
+
50
+ ### Context:
51
+ Make sure to include *any* context that is needed for the LLM to accurately, and reliably respond as needed.
52
+
53
+ ### Response format:
54
+ Outline the ideal response format for this prompt.
55
+
56
+ ### Important Notes:
57
+ - Instruct the model to list out its thoughts before giving an answer.
58
+ - If complex reasoning is required, include directions for the LLM to think step by step, and weigh all sides of the topic before settling on an answer.
59
+ - Where appropriate, make sure to utilize advanced prompt engineering techniques. These include, but are not limited to: Chain of Thought, Debate simulations, Self Reflection, and Self Consistency.
60
+ - Strictly use text, no code please
61
+
62
+ ### Input:
63
+ [Type here what you want from the model]
64
  """
65
+
66
+ # Update the `respond` function to include the prompt template
67
+ def respond_with_prompt(
68
+ task,
69
+ message,
70
+ history: list[tuple[str, str]],
71
+ system_message,
72
+ max_tokens,
73
+ temperature,
74
+ top_p,
75
+ ):
76
+ # Insert the task into the prompt template
77
+ prompt = prompt_template.format(task=task)
78
+
79
+ messages = [{"role": "system", "content": system_message}]
80
+
81
+ for val in history:
82
+ if val[0]:
83
+ messages.append({"role": "user", "content": val[0]})
84
+ if val[1]:
85
+ messages.append({"role": "assistant", "content": val[1]})
86
+
87
+ messages.append({"role": "user", "content": message})
88
+
89
+ response = ""
90
+
91
+ for message in client.chat_completion(
92
+ messages,
93
+ prompt=prompt,
94
+ max_tokens=max_tokens,
95
+ stream=True,
96
+ temperature=temperature,
97
+ top_p=top_p,
98
+ ):
99
+ token = message.choices[0].delta.content
100
+
101
+ response += token
102
+ yield response
103
+
104
+
105
+ # Define the ChatInterface with additional inputs
106
  demo = gr.ChatInterface(
107
+ respond_with_prompt,
108
  additional_inputs=[
109
+ gr.Textbox(
110
+ value="Describe your task...",
111
+ label="Task Description",
112
+ lines=7,
113
+ ),
114
+ gr.Textbox(
115
+ value="You are a friendly Chatbot.",
116
+ label="System message",
117
+ ),
118
+ gr.Slider(
119
+ minimum=1,
120
+ maximum=2048,
121
+ value=512,
122
+ step=1,
123
+ label="Max new tokens",
124
+ ),
125
+ gr.Slider(
126
+ minimum=0.1,
127
+ maximum=4.0,
128
+ value=0.7,
129
+ step=0.1,
130
+ label="Temperature",
131
+ ),
132
  gr.Slider(
133
  minimum=0.1,
134
  maximum=1.0,
 
139
  ],
140
  )
141
 
 
142
  if __name__ == "__main__":
143
+ demo.launch()