Update app.py
Browse files
app.py
CHANGED
|
@@ -181,9 +181,7 @@ def normalize_model(model: str):
|
|
| 181 |
|
| 182 |
def create_client():
|
| 183 |
|
| 184 |
-
return Client(
|
| 185 |
-
provider=g4f.Provider.Blackbox
|
| 186 |
-
)
|
| 187 |
|
| 188 |
|
| 189 |
# =====================================================
|
|
@@ -548,6 +546,19 @@ async def anthropic_messages(
|
|
| 548 |
+ "\n\n"
|
| 549 |
)
|
| 550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 551 |
# =========================================
|
| 552 |
# content_block_start
|
| 553 |
# =========================================
|
|
@@ -566,6 +577,8 @@ async def anthropic_messages(
|
|
| 566 |
+ "\n\n"
|
| 567 |
)
|
| 568 |
|
|
|
|
|
|
|
| 569 |
for chunk in response:
|
| 570 |
|
| 571 |
try:
|
|
@@ -589,6 +602,8 @@ async def anthropic_messages(
|
|
| 589 |
if not content:
|
| 590 |
continue
|
| 591 |
|
|
|
|
|
|
|
| 592 |
payload = {
|
| 593 |
"type": "content_block_delta",
|
| 594 |
"index": 0,
|
|
@@ -614,6 +629,23 @@ async def anthropic_messages(
|
|
| 614 |
f"Anthropic chunk error: {e}"
|
| 615 |
)
|
| 616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 617 |
# =========================================
|
| 618 |
# content_block_stop
|
| 619 |
# =========================================
|
|
|
|
| 181 |
|
| 182 |
def create_client():
|
| 183 |
|
| 184 |
+
return Client()
|
|
|
|
|
|
|
| 185 |
|
| 186 |
|
| 187 |
# =====================================================
|
|
|
|
| 546 |
+ "\n\n"
|
| 547 |
)
|
| 548 |
|
| 549 |
+
# =========================================
|
| 550 |
+
# ping
|
| 551 |
+
# =========================================
|
| 552 |
+
|
| 553 |
+
yield (
|
| 554 |
+
"event: ping\n"
|
| 555 |
+
"data: "
|
| 556 |
+
+ json.dumps({
|
| 557 |
+
"type": "ping"
|
| 558 |
+
})
|
| 559 |
+
+ "\n\n"
|
| 560 |
+
)
|
| 561 |
+
|
| 562 |
# =========================================
|
| 563 |
# content_block_start
|
| 564 |
# =========================================
|
|
|
|
| 577 |
+ "\n\n"
|
| 578 |
)
|
| 579 |
|
| 580 |
+
has_content = False
|
| 581 |
+
|
| 582 |
for chunk in response:
|
| 583 |
|
| 584 |
try:
|
|
|
|
| 602 |
if not content:
|
| 603 |
continue
|
| 604 |
|
| 605 |
+
has_content = True
|
| 606 |
+
|
| 607 |
payload = {
|
| 608 |
"type": "content_block_delta",
|
| 609 |
"index": 0,
|
|
|
|
| 629 |
f"Anthropic chunk error: {e}"
|
| 630 |
)
|
| 631 |
|
| 632 |
+
if not has_content:
|
| 633 |
+
|
| 634 |
+
yield (
|
| 635 |
+
"event: error\n"
|
| 636 |
+
"data: "
|
| 637 |
+
+ json.dumps({
|
| 638 |
+
"type": "error",
|
| 639 |
+
"error": {
|
| 640 |
+
"type": "api_error",
|
| 641 |
+
"message": "Empty response"
|
| 642 |
+
}
|
| 643 |
+
})
|
| 644 |
+
+ "\n\n"
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
return
|
| 648 |
+
|
| 649 |
# =========================================
|
| 650 |
# content_block_stop
|
| 651 |
# =========================================
|