Update app.py
Browse files
app.py
CHANGED
@@ -379,38 +379,6 @@ def billing_usage():
|
|
379 |
"total_usage": 0
|
380 |
})
|
381 |
|
382 |
-
@app.route('/handsome/v1/dashboard/billing/subscription', methods=['GET'])
|
383 |
-
def billing_subscription():
|
384 |
-
if not check_authorization(request):
|
385 |
-
return jsonify({"error": "Unauthorized"}), 401
|
386 |
-
|
387 |
-
total_balance = get_billing_info()
|
388 |
-
|
389 |
-
return jsonify({
|
390 |
-
"object": "billing_subscription",
|
391 |
-
"has_payment_method": False,
|
392 |
-
"canceled": False,
|
393 |
-
"canceled_at": None,
|
394 |
-
"delinquent": None,
|
395 |
-
"access_until": int(datetime(9999, 12, 31).timestamp()),
|
396 |
-
"soft_limit": 0,
|
397 |
-
"hard_limit": total_balance,
|
398 |
-
"system_hard_limit": total_balance,
|
399 |
-
"soft_limit_usd": 0,
|
400 |
-
"hard_limit_usd": total_balance,
|
401 |
-
"system_hard_limit_usd": total_balance,
|
402 |
-
"plan": {
|
403 |
-
"name": "SiliconFlow API",
|
404 |
-
"id": "siliconflow-api"
|
405 |
-
},
|
406 |
-
"account_name": "SiliconFlow User",
|
407 |
-
"po_number": None,
|
408 |
-
"billing_email": None,
|
409 |
-
"tax_ids": [],
|
410 |
-
"billing_address": None,
|
411 |
-
"business_address": None
|
412 |
-
})
|
413 |
-
|
414 |
@app.route('/handsome/v1/chat/completions', methods=['POST'])
|
415 |
def handsome_chat_completions():
|
416 |
if not check_authorization(request):
|
@@ -463,7 +431,7 @@ def handsome_chat_completions():
|
|
463 |
def generate():
|
464 |
first_chunk_time = None
|
465 |
full_response_content = ""
|
466 |
-
|
467 |
for chunk in response.iter_content(chunk_size=1024):
|
468 |
if chunk:
|
469 |
if first_chunk_time is None:
|
@@ -497,20 +465,18 @@ def handsome_chat_completions():
|
|
497 |
"usage"
|
498 |
]["completion_tokens"]
|
499 |
|
500 |
-
# Improved
|
501 |
if model_name == "deepseek-reasoner" and "choices" in response_json and len(response_json["choices"]) > 0:
|
502 |
delta = response_json["choices"][0].get("delta", {})
|
503 |
-
if "reasoning_content" in delta
|
504 |
-
|
505 |
if "content" in delta and delta["content"]:
|
506 |
-
#
|
507 |
-
if
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
response_content += f"> {reasoning_line}\n"
|
513 |
-
pending_reasoning_lines = [] # Clear pending lines
|
514 |
response_content += delta["content"]
|
515 |
elif "choices" in response_json and len(response_json["choices"]) > 0:
|
516 |
delta = response_json["choices"][0].get("delta", {})
|
@@ -534,13 +500,6 @@ def handsome_chat_completions():
|
|
534 |
f"解析流式响应单行 JSON 失败: {e}, "
|
535 |
f"行内容: {line}"
|
536 |
)
|
537 |
-
|
538 |
-
# Process any remaining reasoning lines after all chunks are received
|
539 |
-
if pending_reasoning_lines:
|
540 |
-
for reasoning_line in pending_reasoning_lines:
|
541 |
-
response_content += f"> {reasoning_line}"
|
542 |
-
if not response_content.endswith("\n"):
|
543 |
-
response_content += "\n"
|
544 |
|
545 |
user_content = ""
|
546 |
messages = data.get("messages", [])
|
|
|
379 |
"total_usage": 0
|
380 |
})
|
381 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
382 |
@app.route('/handsome/v1/chat/completions', methods=['POST'])
|
383 |
def handsome_chat_completions():
|
384 |
if not check_authorization(request):
|
|
|
431 |
def generate():
|
432 |
first_chunk_time = None
|
433 |
full_response_content = ""
|
434 |
+
accumulated_reasoning = "" # Accumulate reasoning content
|
435 |
for chunk in response.iter_content(chunk_size=1024):
|
436 |
if chunk:
|
437 |
if first_chunk_time is None:
|
|
|
465 |
"usage"
|
466 |
]["completion_tokens"]
|
467 |
|
468 |
+
# Improved handling for deepseek-reasoner in streaming mode
|
469 |
if model_name == "deepseek-reasoner" and "choices" in response_json and len(response_json["choices"]) > 0:
|
470 |
delta = response_json["choices"][0].get("delta", {})
|
471 |
+
if "reasoning_content" in delta:
|
472 |
+
accumulated_reasoning += delta["reasoning_content"]
|
473 |
if "content" in delta and delta["content"]:
|
474 |
+
# Prepend accumulated reasoning before content
|
475 |
+
if accumulated_reasoning:
|
476 |
+
reasoning_lines = accumulated_reasoning.splitlines()
|
477 |
+
formatted_reasoning = "\n".join(f"> {line}" for line in reasoning_lines)
|
478 |
+
response_content += formatted_reasoning + "\n"
|
479 |
+
accumulated_reasoning = "" # Reset
|
|
|
|
|
480 |
response_content += delta["content"]
|
481 |
elif "choices" in response_json and len(response_json["choices"]) > 0:
|
482 |
delta = response_json["choices"][0].get("delta", {})
|
|
|
500 |
f"解析流式响应单行 JSON 失败: {e}, "
|
501 |
f"行内容: {line}"
|
502 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
503 |
|
504 |
user_content = ""
|
505 |
messages = data.get("messages", [])
|