nanoppa commited on
Commit
8452340
·
verified ·
1 Parent(s): bd84d38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -10
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=True
44
  )
45
 
46
  def generate():
@@ -98,15 +99,18 @@ def chat_completions():
98
  print(f"Error processing line: {e}")
99
  continue
100
 
101
- return Response(
102
- generate(),
103
- mimetype='text/event-stream',
104
- headers={
105
- 'Cache-Control': 'no-cache',
106
- 'Connection': 'keep-alive',
107
- 'Content-Type': 'text/event-stream'
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