mirror of
https://github.com/oobabooga/text-generation-webui.git
synced 2024-11-22 16:17:57 +01:00
Don't strip leading spaces in OpenAI API
This commit is contained in:
parent
4a45dc4041
commit
97c21e5667
@ -287,13 +287,7 @@ def chat_completions_common(body: dict, is_legacy: bool = False, stream=False) -
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
seen_content = answer
|
seen_content = answer
|
||||||
|
|
||||||
# strip extra leading space off new generated content
|
|
||||||
if len_seen == 0 and new_content[0] == ' ':
|
|
||||||
new_content = new_content[1:]
|
|
||||||
|
|
||||||
chunk = chat_streaming_chunk(new_content)
|
chunk = chat_streaming_chunk(new_content)
|
||||||
|
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
completion_token_count = len(encode(answer)[0])
|
completion_token_count = len(encode(answer)[0])
|
||||||
@ -390,10 +384,6 @@ def completions_common(body: dict, is_legacy: bool = False, stream=False):
|
|||||||
for a in generator:
|
for a in generator:
|
||||||
answer = a
|
answer = a
|
||||||
|
|
||||||
# strip extra leading space off new generated content
|
|
||||||
if answer and answer[0] == ' ':
|
|
||||||
answer = answer[1:]
|
|
||||||
|
|
||||||
completion_token_count = len(encode(answer)[0])
|
completion_token_count = len(encode(answer)[0])
|
||||||
total_completion_token_count += completion_token_count
|
total_completion_token_count += completion_token_count
|
||||||
stop_reason = "stop"
|
stop_reason = "stop"
|
||||||
@ -474,19 +464,9 @@ def completions_common(body: dict, is_legacy: bool = False, stream=False):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
seen_content = answer
|
seen_content = answer
|
||||||
|
|
||||||
# strip extra leading space off new generated content
|
|
||||||
if len_seen == 0 and new_content[0] == ' ':
|
|
||||||
new_content = new_content[1:]
|
|
||||||
|
|
||||||
chunk = text_streaming_chunk(new_content)
|
chunk = text_streaming_chunk(new_content)
|
||||||
|
|
||||||
yield chunk
|
yield chunk
|
||||||
|
|
||||||
# to get the correct count, we strip the leading space if present
|
|
||||||
if answer and answer[0] == ' ':
|
|
||||||
answer = answer[1:]
|
|
||||||
|
|
||||||
completion_token_count = len(encode(answer)[0])
|
completion_token_count = len(encode(answer)[0])
|
||||||
stop_reason = "stop"
|
stop_reason = "stop"
|
||||||
if token_count + completion_token_count >= generate_params['truncation_length'] or completion_token_count >= max_tokens:
|
if token_count + completion_token_count >= generate_params['truncation_length'] or completion_token_count >= max_tokens:
|
||||||
|
Loading…
Reference in New Issue
Block a user