Spaces:
Running
Running
added system prompt
Browse files
app.py
CHANGED
@@ -5,17 +5,18 @@ client = InferenceClient(
|
|
5 |
"mistralai/Mistral-7B-Instruct-v0.3"
|
6 |
)
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
16 |
|
17 |
def generate(
|
18 |
-
prompt, history, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
19 |
):
|
20 |
temperature = float(temperature)
|
21 |
if temperature < 1e-2:
|
@@ -31,7 +32,7 @@ def generate(
|
|
31 |
seed=42,
|
32 |
)
|
33 |
|
34 |
-
formatted_prompt = format_prompt(prompt, history)
|
35 |
|
36 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
37 |
output = ""
|
@@ -43,6 +44,12 @@ def generate(
|
|
43 |
|
44 |
|
45 |
additional_inputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
gr.Slider(
|
47 |
label="Temperature",
|
48 |
value=0.9,
|
|
|
5 |
"mistralai/Mistral-7B-Instruct-v0.3"
|
6 |
)
|
7 |
|
8 |
+
def format_prompt(message, history, system_prompt=None):
|
9 |
+
prompt = "<s>"
|
10 |
+
for user_prompt, bot_response in history:
|
11 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
12 |
+
prompt += f" {bot_response}</s> "
|
13 |
+
if system_prompt:
|
14 |
+
prompt += f"[SYS] {system_prompt} [/SYS]"
|
15 |
+
prompt += f"[INST] {message} [/INST]"
|
16 |
+
return prompt
|
17 |
|
18 |
def generate(
|
19 |
+
prompt, history, system_prompt=None, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
|
20 |
):
|
21 |
temperature = float(temperature)
|
22 |
if temperature < 1e-2:
|
|
|
32 |
seed=42,
|
33 |
)
|
34 |
|
35 |
+
formatted_prompt = format_prompt(prompt, history, system_prompt)
|
36 |
|
37 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
38 |
output = ""
|
|
|
44 |
|
45 |
|
46 |
additional_inputs=[
|
47 |
+
gr.Slider(
|
48 |
+
label="System message",
|
49 |
+
value="",
|
50 |
+
interactive=True,
|
51 |
+
info="context",
|
52 |
+
),
|
53 |
gr.Slider(
|
54 |
label="Temperature",
|
55 |
value=0.9,
|