Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -35,12 +35,13 @@ def chat_completions():
|
|
| 35 |
}
|
| 36 |
|
| 37 |
print(akash_data)
|
|
|
|
| 38 |
# 发送请求到Akash API
|
| 39 |
response = requests.post(
|
| 40 |
'https://chat.akash.network/api/chat',
|
| 41 |
json=akash_data,
|
| 42 |
headers=headers,
|
| 43 |
-
stream=
|
| 44 |
)
|
| 45 |
|
| 46 |
def generate():
|
|
@@ -98,15 +99,18 @@ def chat_completions():
|
|
| 98 |
print(f"Error processing line: {e}")
|
| 99 |
continue
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
except Exception as e:
|
| 112 |
return jsonify({"error": str(e)}), 500
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
print(akash_data)
|
| 38 |
+
_stream=data.get('stream', True)
|
| 39 |
# 发送请求到Akash API
|
| 40 |
response = requests.post(
|
| 41 |
'https://chat.akash.network/api/chat',
|
| 42 |
json=akash_data,
|
| 43 |
headers=headers,
|
| 44 |
+
stream=_stream
|
| 45 |
)
|
| 46 |
|
| 47 |
def generate():
|
|
|
|
| 99 |
print(f"Error processing line: {e}")
|
| 100 |
continue
|
| 101 |
|
| 102 |
+
if _stream == True:
|
| 103 |
+
return Response(
|
| 104 |
+
generate(),
|
| 105 |
+
mimetype='text/event-stream',
|
| 106 |
+
headers={
|
| 107 |
+
'Cache-Control': 'no-cache',
|
| 108 |
+
'Connection': 'keep-alive',
|
| 109 |
+
'Content-Type': 'text/event-stream'
|
| 110 |
+
}
|
| 111 |
+
)
|
| 112 |
+
else:
|
| 113 |
+
return response
|
| 114 |
|
| 115 |
except Exception as e:
|
| 116 |
return jsonify({"error": str(e)}), 500
|