Skip to content

Commit

Permalink
fix the format issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cuauty committed Dec 13, 2024
1 parent 75a57c3 commit c9a9a46
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions fastchat/serve/api_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1326,21 +1326,25 @@ def bailing_api_stream_iter(
curr_buf += new_buf
while True:
x_part = curr_buf.split("\n\n", 1)
if len(x_part) > 1: # part can be sent
y_part = x_part[0][len("data:"):].strip()
if len(x_part) > 1: # part can be sent
y_part = x_part[0][len("data:") :].strip()
try:
y = json.loads(y_part)
output_text = y["choices"][0]["delta"]["content"]
except Exception as e:
curr_buf = x_part[1] # finish one response
logger.error(f"Read the error content. Content: {y_part}, Info:{e}")
curr_buf = x_part[1] # finish one response
logger.error(
f"Read the error content. Content: {y_part}, Info:{e}"
)
continue # skip current part
total_text += output_text
curr_buf = x_part[1] # finish one response and look to leftover
curr_buf = x_part[
1
] # finish one response and look to leftover
yield {"text": total_text, "error_code": 0}
else: # no part can be sent and continue to read
else: # no part can be sent and continue to read
break
return # finish the total
return # finish the total
else:
logger.error(
f"Error occurs and retry if possible. status_code={resp.status_code}"
Expand Down

0 comments on commit c9a9a46

Please sign in to comment.