teaevo commited on
Commit
cee9f1f
·
1 Parent(s): 46920ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -46,8 +46,11 @@ def predict(input, history=[]):
46
  # tokenize the new input sentence
47
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
48
 
 
 
 
49
  # append the new user input tokens to the chat history
50
- bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
51
 
52
  # generate a response
53
  history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
@@ -60,15 +63,11 @@ def predict(input, history=[]):
60
 
61
  # Add the SQL model's response to the chat history
62
  history.extend(response_sql)
63
-
64
-
65
  # convert the tokens to text, and then split the responses into the right format
66
  response = tokenizer.decode(history[0]).split("<|endoftext|>")
67
  response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
68
-
69
 
70
-
71
-
72
  return response, history
73
 
74
 
 
46
  # tokenize the new input sentence
47
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
48
 
49
+ # Convert history tensor to a list
50
+ history_list = history.tolist() if isinstance(history, torch.Tensor) else history
51
+
52
  # append the new user input tokens to the chat history
53
+ bot_input_ids = torch.cat([torch.LongTensor(history_list), new_user_input_ids], dim=-1)
54
 
55
  # generate a response
56
  history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
 
63
 
64
  # Add the SQL model's response to the chat history
65
  history.extend(response_sql)
66
+
 
67
  # convert the tokens to text, and then split the responses into the right format
68
  response = tokenizer.decode(history[0]).split("<|endoftext|>")
69
  response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
 
70
 
 
 
71
  return response, history
72
 
73