smgc commited on
Commit
2c7972e
1 Parent(s): 2cfb9fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,6 +1,5 @@
1
  from flask import Flask, request, Response
2
- from werkzeug.middleware.dispatcher import DispatcherMiddleware
3
- from werkzeug.wrappers import Response as WerkzeugResponse
4
  import requests
5
  import json
6
  import os
@@ -21,7 +20,7 @@ logging.basicConfig(
21
  logger = logging.getLogger(__name__)
22
 
23
  @app.route('/chat/completions', methods=['POST'])
24
- async def chat():
25
  """
26
  Handle chat completion requests.
27
  """
@@ -33,7 +32,7 @@ async def chat():
33
  logger.info(f"Request headers: {dict(request.headers)}")
34
 
35
  # Get the payload from the request
36
- payload = await request.get_json()
37
  logger.info(f"Request payload: {json.dumps(payload, indent=2)}")
38
 
39
  # Get the model from the payload, defaulting to "claude-3-5-sonnet-20240620"
@@ -112,13 +111,13 @@ async def chat():
112
  return Response(generate(), content_type='application/octet-stream')
113
 
114
  @app.route('/', methods=['GET'])
115
- async def home():
116
  return "Welcome to the Chat Completion API", 200
117
 
118
  # 创建 ASGI 应用
119
- asgi_app = DispatcherMiddleware(app)
120
 
121
  if __name__ == '__main__':
122
  import uvicorn
123
  logger.info("Starting the application")
124
- uvicorn.run(asgi_app, host="0.0.0.0", port=8000, log_level="info")
 
1
  from flask import Flask, request, Response
2
+ from asgiref.wsgi import WsgiToAsgi
 
3
  import requests
4
  import json
5
  import os
 
20
  logger = logging.getLogger(__name__)
21
 
22
  @app.route('/chat/completions', methods=['POST'])
23
+ def chat():
24
  """
25
  Handle chat completion requests.
26
  """
 
32
  logger.info(f"Request headers: {dict(request.headers)}")
33
 
34
  # Get the payload from the request
35
+ payload = request.json
36
  logger.info(f"Request payload: {json.dumps(payload, indent=2)}")
37
 
38
  # Get the model from the payload, defaulting to "claude-3-5-sonnet-20240620"
 
111
  return Response(generate(), content_type='application/octet-stream')
112
 
113
  @app.route('/', methods=['GET'])
114
+ def home():
115
  return "Welcome to the Chat Completion API", 200
116
 
117
  # 创建 ASGI 应用
118
+ asgi_app = WsgiToAsgi(app)
119
 
120
  if __name__ == '__main__':
121
  import uvicorn
122
  logger.info("Starting the application")
123
+ uvicorn.run("app:asgi_app", host="0.0.0.0", port=8000, log_level="info")