Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -28,11 +28,7 @@ def respond(
|
|
| 28 |
response = ""
|
| 29 |
|
| 30 |
for message in client.chat_completion(
|
| 31 |
-
messages,
|
| 32 |
-
max_tokens=max_tokens,
|
| 33 |
-
stream=True,
|
| 34 |
-
temperature=temperature,
|
| 35 |
-
top_p=top_p,
|
| 36 |
):
|
| 37 |
token = message.choices[0].delta.content
|
| 38 |
|
|
@@ -40,95 +36,21 @@ def respond(
|
|
| 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 |
-
|
| 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 |
-
|
| 108 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
| 109 |
gr.Textbox(
|
| 110 |
-
|
| 111 |
-
|
| 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,5 +61,6 @@ demo = gr.ChatInterface(
|
|
| 139 |
],
|
| 140 |
)
|
| 141 |
|
|
|
|
| 142 |
if __name__ == "__main__":
|
| 143 |
demo.launch()
|
|
|
|
| 28 |
response = ""
|
| 29 |
|
| 30 |
for message in client.chat_completion(
|
| 31 |
+
messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
):
|
| 33 |
token = message.choices[0].delta.content
|
| 34 |
|
|
|
|
| 36 |
yield response
|
| 37 |
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
"""
|
| 40 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
| 41 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
demo = gr.ChatInterface(
|
| 43 |
+
respond,
|
| 44 |
additional_inputs=[
|
| 45 |
+
gr.Textbox(value="**I am a large language model trained on a massive dataset of text and code. I can follow your instructions and complete your requests thoughtfully. I will use my knowledge to craft the perfect prompt for your desired outcome.**", label="System message"),
|
| 46 |
+
gr.Textbox(label="**Task:**", placeholder="Write your desired task here"),
|
| 47 |
+
gr.Textbox(label="**Context:**", placeholder="Provide any relevant background information"),
|
| 48 |
gr.Textbox(
|
| 49 |
+
label="**Response format:**",
|
| 50 |
+
placeholder="Specify how you want the output presented (e.g., list, code, essay)",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
),
|
| 52 |
+
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 53 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
| 54 |
gr.Slider(
|
| 55 |
minimum=0.1,
|
| 56 |
maximum=1.0,
|
|
|
|
| 61 |
],
|
| 62 |
)
|
| 63 |
|
| 64 |
+
|
| 65 |
if __name__ == "__main__":
|
| 66 |
demo.launch()
|