yangtb24 commited on
Commit
13e7a6a
·
verified ·
1 Parent(s): 3ae260c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -1
app.py CHANGED
@@ -661,7 +661,25 @@ def handsome_chat_completions():
661
  }
662
  ],
663
  }
 
 
 
 
 
 
 
 
 
 
 
664
 
 
 
 
 
 
 
 
665
  except (KeyError, ValueError, IndexError) as e:
666
  logging.error(
667
  f"解析响应 JSON 失败: {e}, "
@@ -683,7 +701,6 @@ def handsome_chat_completions():
683
  }
684
  ],
685
  }
686
-
687
  logging.info(
688
  f"使用的key: {api_key}, "
689
  f"总共用时: {total_time:.4f}秒, "
 
661
  }
662
  ],
663
  }
664
+
665
+ if data.get("stream", False):
666
+ def generate():
667
+ yield f"data: {json.dumps(response_data)}\n\n"
668
+ yield "data: [DONE]\n\n"
669
+
670
+ logging.info(
671
+ f"使用的key: {api_key}, "
672
+ f"总共用时: {total_time:.4f}秒, "
673
+ f"使用的模型: {model_name}"
674
+ )
675
 
676
+ with data_lock:
677
+ request_timestamps.append(time.time())
678
+ token_counts.append(0) # Image generation doesn't use tokens
679
+ return Response(
680
+ stream_with_context(generate()),
681
+ content_type='text/event-stream'
682
+ )
683
  except (KeyError, ValueError, IndexError) as e:
684
  logging.error(
685
  f"解析响应 JSON 失败: {e}, "
 
701
  }
702
  ],
703
  }
 
704
  logging.info(
705
  f"使用的key: {api_key}, "
706
  f"总共用时: {total_time:.4f}秒, "