Update app.py
Browse files
app.py
CHANGED
@@ -6,10 +6,13 @@ client = InferenceClient(
|
|
6 |
)
|
7 |
|
8 |
def character_prompt(dict, max_new_tokens):
|
9 |
-
system_prompt = f
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
def generate(prompt, history, name, description, user_name, max_new_tokens):
|
15 |
generate_kwargs = dict(
|
@@ -19,7 +22,7 @@ def generate(prompt, history, name, description, user_name, max_new_tokens):
|
|
19 |
repetition_penalty=1.0,
|
20 |
do_sample=True,
|
21 |
)
|
22 |
-
system_setting = character_prompt({"
|
23 |
formatted_prompt = format_prompt(prompt, history, system_setting)
|
24 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
25 |
output = ""
|
@@ -29,10 +32,10 @@ def generate(prompt, history, name, description, user_name, max_new_tokens):
|
|
29 |
return output
|
30 |
|
31 |
def format_prompt(prompt, history, system_setting):
|
32 |
-
formatted_prompt = "<
|
33 |
for user_prompt, bot_response in history:
|
34 |
-
formatted_prompt += f"[INST] {user_prompt} [/INST] {bot_response} </
|
35 |
-
formatted_prompt += f"[INST] {system_setting}, {prompt} [/INST]"
|
36 |
return formatted_prompt
|
37 |
|
38 |
additional_inputs = [
|
|
|
6 |
)
|
7 |
|
8 |
def character_prompt(dict, max_new_tokens):
|
9 |
+
system_prompt = f'<SYSTEM> <the person whose name is {dict["name"]} and your description {dict["description"]}.'
|
10 |
+
system_prompt += f'users name is {dict["user_name"]}.'
|
11 |
+
system_prompt += f'make sure that the greeting is only at the first request.'
|
12 |
+
system_prompt += f'add emojis to enhance the emotions of your message.'
|
13 |
+
system_prompt += f'ensure responses are no longer than {max_new_tokens} tokens.>'
|
14 |
+
|
15 |
+
return system_prompt
|
16 |
|
17 |
def generate(prompt, history, name, description, user_name, max_new_tokens):
|
18 |
generate_kwargs = dict(
|
|
|
22 |
repetition_penalty=1.0,
|
23 |
do_sample=True,
|
24 |
)
|
25 |
+
system_setting = character_prompt({"name": name, "description": description, "user_name": user_name}, max_new_tokens)
|
26 |
formatted_prompt = format_prompt(prompt, history, system_setting)
|
27 |
stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
|
28 |
output = ""
|
|
|
32 |
return output
|
33 |
|
34 |
def format_prompt(prompt, history, system_setting):
|
35 |
+
formatted_prompt = "<history>"
|
36 |
for user_prompt, bot_response in history:
|
37 |
+
formatted_prompt += f"[INST] {user_prompt} [/INST] {bot_response} </history> "
|
38 |
+
formatted_prompt += f"[INST] {system_setting}, <user>{prompt}</user> [/INST]"
|
39 |
return formatted_prompt
|
40 |
|
41 |
additional_inputs = [
|