Spaces:
Sleeping
Sleeping
Update app.py
Browse files31 unmodified lines323334353637382 unmodified lines414243444546474831 unmodified linesdef generate_response(input_text):# If it's the first interaction, add the system prompt to the conversation historyif not st.session_state['history']:system_prompt = get_system_prompt()st.session_state['conversation'].append(f"System: {system_prompt}")system_input_ids = tokenizer.encode(system_prompt + tokenizer.eos_token, return_tensors='pt').to(device)2 unmodified lines# Encode the new user input, add end of string tokennew_user_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors='pt').to(device)# If there is conversation history, append the new input to itif st.session_state['history']:history_tensor = torch.tensor(st.session_state['history']).unsqueeze(0).to(device)bot_input_ids = torch.cat([history_tensor, new_user_input_ids], dim=-1)else:31 unmodified lines323334353637382 unmodified lines414243444546474831 unmodified linesdef generate_response(input_text):# If it's the first interaction, add the system prompt to the conversation historyif len(st.session_state['history']) == 0:system_prompt = get_system_prompt()st.session_state['conversation'].append(f"System: {system_prompt}")system_input_ids = tokenizer.encode(system_prompt + tokenizer.eos_token, return_tensors='pt').to(device)2 unmodified lines# Encode the new user input, add end of string tokennew_user_input_ids = tokenizer.encode(input_text + tokenizer.eos_token, return_tensors='pt').to(device)# Append the new user input to the historyif len(st.session_state['history']) > 0:history_tensor = torch.tensor(st.session_state['history']).unsqueeze(0).to(device)bot_input_ids = torch.cat([history_tensor, new_user_input_ids], dim=-1)else:
app.py+3-3