Spaces:
Sleeping
Sleeping
ww commited on
Commit ·
e0a657b
1
Parent(s): 342b32b
formatted
Browse files
app.py
CHANGED
|
@@ -7,25 +7,24 @@ For more information on `huggingface_hub` Inference API support, please check th
|
|
| 7 |
"""
|
| 8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1",token=os.getenv('HUGGINGFACE_TOKEN').strip())
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
def generate_response(
|
| 11 |
-
|
| 12 |
history: list[tuple[str, str]],
|
| 13 |
-
|
| 14 |
max_tokens,
|
| 15 |
temperature,
|
| 16 |
top_p,
|
| 17 |
):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
for val in history:
|
| 21 |
-
if val[0]:
|
| 22 |
-
messages.append({"role": "user", "content": val[0]})
|
| 23 |
-
if val[1]:
|
| 24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
-
|
| 26 |
-
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
stream = client.text_generation(message,stream=True, max_new_tokens=256)
|
| 29 |
output = ""
|
| 30 |
for response in stream:
|
| 31 |
output += response
|
|
|
|
| 7 |
"""
|
| 8 |
client = InferenceClient("mistralai/Mixtral-8x7B-Instruct-v0.1",token=os.getenv('HUGGINGFACE_TOKEN').strip())
|
| 9 |
|
| 10 |
+
def format_prompt(message, history):
|
| 11 |
+
prompt = "<s>"
|
| 12 |
+
for user_prompt, bot_response in history:
|
| 13 |
+
prompt += f"[INST] {user_prompt} [/INST]"
|
| 14 |
+
prompt += f" {bot_response}</s> "
|
| 15 |
+
prompt += f"[INST] {message} [/INST]"
|
| 16 |
+
return prompt
|
| 17 |
+
|
| 18 |
def generate_response(
|
| 19 |
+
prompt,
|
| 20 |
history: list[tuple[str, str]],
|
| 21 |
+
system_prompt,
|
| 22 |
max_tokens,
|
| 23 |
temperature,
|
| 24 |
top_p,
|
| 25 |
):
|
| 26 |
+
formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", history)
|
| 27 |
+
stream = client.text_generation(formatted_prompt,stream=True, max_new_tokens=256)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
output = ""
|
| 29 |
for response in stream:
|
| 30 |
output += response
|