mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-25 17:29:22 +01:00
Right-truncate long chat completion prompts instead of left-truncating
Instructions are usually at the beginning of the prompt.
This commit is contained in:
parent
104573f7d4
commit
bae14c8f13
@ -197,16 +197,16 @@ def generate_chat_prompt(user_input, state, **kwargs):
|
|||||||
while right - left > 1:
|
while right - left > 1:
|
||||||
mid = (left + right) // 2
|
mid = (left + right) // 2
|
||||||
|
|
||||||
messages[-1]['content'] = user_message[mid:]
|
messages[-1]['content'] = user_message[:mid]
|
||||||
prompt = make_prompt(messages)
|
prompt = make_prompt(messages)
|
||||||
encoded_length = get_encoded_length(prompt)
|
encoded_length = get_encoded_length(prompt)
|
||||||
|
|
||||||
if encoded_length <= max_length:
|
if encoded_length <= max_length:
|
||||||
right = mid
|
|
||||||
else:
|
|
||||||
left = mid
|
left = mid
|
||||||
|
else:
|
||||||
|
right = mid
|
||||||
|
|
||||||
messages[-1]['content'] = user_message[right:]
|
messages[-1]['content'] = user_message[:left]
|
||||||
prompt = make_prompt(messages)
|
prompt = make_prompt(messages)
|
||||||
encoded_length = get_encoded_length(prompt)
|
encoded_length = get_encoded_length(prompt)
|
||||||
if encoded_length > max_length:
|
if encoded_length > max_length:
|
||||||
|
Loading…
Reference in New Issue
Block a user