Skip to content

Commit

Permalink
The soft prompt length must be considered here too
Browse files Browse the repository at this point in the history
  • Loading branch information
oobabooga committed Feb 17, 2023
1 parent a6ddbbf commit 596732a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,17 @@ def clean_chat_message(text):
return text

def generate_chat_prompt(text, tokens, name1, name2, context, chat_prompt_size, impersonate=False):
global soft_prompt, soft_prompt_tensor

text = clean_chat_message(text)
rows = [f"{context.strip()}\n"]
i = len(history['internal'])-1
count = 0

if soft_prompt:
chat_prompt_size -= soft_prompt_tensor.shape[1]
max_length = min(get_max_prompt_length(tokens), chat_prompt_size)

while i >= 0 and len(encode(''.join(rows), tokens)[0]) < max_length:
rows.insert(1, f"{name2}: {history['internal'][i][1].strip()}\n")
count += 1
Expand Down

0 comments on commit 596732a

Please sign in to comment.