Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -54,23 +54,23 @@ class FalconChatBot:
|
|
54 |
def predict(self, system_prompt, user_message, assistant_message, history, temperature, max_new_tokens, top_p, repetition_penalty):
|
55 |
|
56 |
# Process the history to remove special commands
|
57 |
-
|
58 |
|
59 |
# Combine the user and assistant messages into a conversation
|
60 |
-
|
61 |
|
62 |
# Encode the conversation using the tokenizer
|
63 |
-
|
64 |
|
65 |
# Generate a response using the Falcon model
|
66 |
-
|
67 |
|
68 |
# Generate the formatted conversation in Falcon message format
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
|
75 |
return response_text
|
76 |
|
|
|
54 |
def predict(self, system_prompt, user_message, assistant_message, history, temperature, max_new_tokens, top_p, repetition_penalty):
|
55 |
|
56 |
# Process the history to remove special commands
|
57 |
+
processed_history = self.process_history(history)
|
58 |
|
59 |
# Combine the user and assistant messages into a conversation
|
60 |
+
conversation = f"{system_prompt}\nFalcon: {assistant_message if assistant_message else ''} User: {user_message}\nFalcon:\n"
|
61 |
|
62 |
# Encode the conversation using the tokenizer
|
63 |
+
input_ids = tokenizer.encode(conversation, return_tensors="pt", add_special_tokens=False)
|
64 |
|
65 |
# Generate a response using the Falcon model
|
66 |
+
response_text = peft_model.generate(input_ids=input_ids, max_length=max_length, use_cache=True, early_stopping=True, bos_token_id=peft_model.config.bos_token_id, eos_token_id=peft_model.config.eos_token_id, pad_token_id=peft_model.config.eos_token_id, temperature=0.4, do_sample=True)
|
67 |
|
68 |
# Generate the formatted conversation in Falcon message format
|
69 |
+
conversation = f"{system_prompt}\n"
|
70 |
+
for message in processed_history:
|
71 |
+
user_message = message["user"]
|
72 |
+
assistant_message = message["assistant"]
|
73 |
+
conversation += f"Falcon:{' ' + assistant_message if assistant_message else ''} User: {user_message}\n Falcon:\n"
|
74 |
|
75 |
return response_text
|
76 |
|