Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -32,7 +32,7 @@ def get_system_prompt():
|
|
32 |
|
33 |
def generate_response(input_text):
|
34 |
# If it's the first interaction, add the system prompt to the conversation history
|
35 |
-
if
|
36 |
system_prompt = get_system_prompt()
|
37 |
st.session_state['conversation'].append(f"System: {system_prompt}")
|
38 |
system_input_ids = tokenizer.encode(system_prompt + tokenizer.eos_token, return_tensors='pt').to(device)
|
@@ -41,8 +41,8 @@ def generate_response(input_text):
|
|
41 |
# Encode the new user input, add end of string token
|
42 |
new_user_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors='pt').to(device)
|
43 |
|
44 |
-
#
|
45 |
-
if st.session_state['history']:
|
46 |
history_tensor = torch.tensor(st.session_state['history']).unsqueeze(0).to(device)
|
47 |
bot_input_ids = torch.cat([history_tensor, new_user_input_ids], dim=-1)
|
48 |
else:
|
|
|
32 |
|
33 |
def generate_response(input_text):
|
34 |
# If it's the first interaction, add the system prompt to the conversation history
|
35 |
+
if len(st.session_state['history']) == 0:
|
36 |
system_prompt = get_system_prompt()
|
37 |
st.session_state['conversation'].append(f"System: {system_prompt}")
|
38 |
system_input_ids = tokenizer.encode(system_prompt + tokenizer.eos_token, return_tensors='pt').to(device)
|
|
|
41 |
# Encode the new user input, add end of string token
|
42 |
new_user_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors='pt').to(device)
|
43 |
|
44 |
+
# Append the new user input to the history
|
45 |
+
if len(st.session_state['history']) > 0:
|
46 |
history_tensor = torch.tensor(st.session_state['history']).unsqueeze(0).to(device)
|
47 |
bot_input_ids = torch.cat([history_tensor, new_user_input_ids], dim=-1)
|
48 |
else:
|