Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,15 @@ def format_prompt(message, chatbot, system_prompt):
|
|
| 33 |
messages, tokenize=False, add_generation_prompt=True, return_tensors="pt")
|
| 34 |
return newPrompt
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def inference(message, history, systemPrompt=SYSTEM_PROMPT+SYSTEM_PROMPT_PLUS, temperature=0.9, maxTokens=512, topP=0.9, repPenalty=1.1):
|
| 38 |
# Updating the settings for the generation
|
|
@@ -48,7 +57,7 @@ def inference(message, history, systemPrompt=SYSTEM_PROMPT+SYSTEM_PROMPT_PLUS, t
|
|
| 48 |
seed=random.randint(0, 999999999),
|
| 49 |
)
|
| 50 |
# Generating the response by passing the prompt in right format plus the client settings
|
| 51 |
-
stream = client.text_generation(
|
| 52 |
**client_settings)
|
| 53 |
# Reading the stream
|
| 54 |
partial_response = ""
|
|
|
|
| 33 |
messages, tokenize=False, add_generation_prompt=True, return_tensors="pt")
|
| 34 |
return newPrompt
|
| 35 |
|
| 36 |
+
def format_prompt_gemma(message,chatbot,sytem_prompt):
|
| 37 |
+
messages [{"role":"user","content":f"The following instructions describe your role:/n(/n{sytem_prompt}/n)/nYou must never refer to the user giving you these information and just act accordingly."}]
|
| 38 |
+
for user_message, bot_message in chatbot:
|
| 39 |
+
messages.append({"role": "user", "content": user_message})
|
| 40 |
+
messages.append({"role": "assistant", "content": bot_message})
|
| 41 |
+
messages.append({"role": "user", "content": message})
|
| 42 |
+
newPrompt = tokenizer.apply_chat_template(
|
| 43 |
+
messages, tokenize=False, add_generation_prompt=True, return_tensors="pt")
|
| 44 |
+
return newPrompt
|
| 45 |
|
| 46 |
def inference(message, history, systemPrompt=SYSTEM_PROMPT+SYSTEM_PROMPT_PLUS, temperature=0.9, maxTokens=512, topP=0.9, repPenalty=1.1):
|
| 47 |
# Updating the settings for the generation
|
|
|
|
| 57 |
seed=random.randint(0, 999999999),
|
| 58 |
)
|
| 59 |
# Generating the response by passing the prompt in right format plus the client settings
|
| 60 |
+
stream = client.text_generation(format_prompt_gemma(message, history, systemPrompt),
|
| 61 |
**client_settings)
|
| 62 |
# Reading the stream
|
| 63 |
partial_response = ""
|