(fix) anyscale streaming detect [DONE] special char

This commit is contained in:
ishaan-jaff 2023-11-04 13:22:46 -07:00
parent 6b40546e59
commit 56ba58b35b

View file

@ -3800,7 +3800,13 @@ class CustomStreamWrapper:
text = "" text = ""
is_finished = False is_finished = False
finish_reason = None finish_reason = None
if str_line.startswith("data:"): if str_line == "data: [DONE]":
# anyscale returns a [DONE] special char for streaming, this cannot be json loaded. This is the end of stream
text = ""
is_finished = True
finish_reason = "stop"
return {"text": text, "is_finished": is_finished, "finish_reason": finish_reason}
elif str_line.startswith("data:"):
data_json = json.loads(str_line[5:]) data_json = json.loads(str_line[5:])
print_verbose(f"delta content: {data_json['choices'][0]['delta']}") print_verbose(f"delta content: {data_json['choices'][0]['delta']}")
text = data_json["choices"][0]["delta"].get("content", "") text = data_json["choices"][0]["delta"].get("content", "")