smgc commited on
Commit
88f8e77
1 Parent(s): ae87889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -1,4 +1,3 @@
1
- from asgiref.wsgi import WsgiToAsgi
2
  from flask import Flask, request, Response
3
  import requests
4
  import json
@@ -19,7 +18,7 @@ logging.basicConfig(
19
  )
20
  logger = logging.getLogger(__name__)
21
 
22
- @app.route('/chat/completions', methods=['POST'])
23
  async def chat():
24
  """
25
  Handle chat completion requests.
@@ -87,7 +86,7 @@ async def chat():
87
  proxies = {'http': proxy, 'https': proxy} if proxy else None
88
  logger.info(f"Using proxy: {proxy}")
89
 
90
- async def generate():
91
  try:
92
  logger.info("Sending request to LLM API")
93
  with requests.post(url, headers=headers, json=llm_payload, stream=True, proxies=proxies, allow_redirects=True) as response:
@@ -110,10 +109,10 @@ async def chat():
110
  logger.info("Returning streaming response")
111
  return Response(generate(), content_type='application/octet-stream')
112
 
113
- # Convert the Flask app to an ASGI app
114
- asgi_app = WsgiToAsgi(app)
 
115
 
116
  if __name__ == '__main__':
117
- import uvicorn
118
  logger.info("Starting the application")
119
- uvicorn.run(asgi_app, host="0.0.0.0", port=8000)
 
 
1
  from flask import Flask, request, Response
2
  import requests
3
  import json
 
18
  )
19
  logger = logging.getLogger(__name__)
20
 
21
+ @app.route('/ai/v1/chat/completions', methods=['POST'])
22
  async def chat():
23
  """
24
  Handle chat completion requests.
 
86
  proxies = {'http': proxy, 'https': proxy} if proxy else None
87
  logger.info(f"Using proxy: {proxy}")
88
 
89
+ def generate():
90
  try:
91
  logger.info("Sending request to LLM API")
92
  with requests.post(url, headers=headers, json=llm_payload, stream=True, proxies=proxies, allow_redirects=True) as response:
 
109
  logger.info("Returning streaming response")
110
  return Response(generate(), content_type='application/octet-stream')
111
 
112
+ @app.route('/', methods=['GET'])
113
+ def home():
114
+ return "Welcome to the Chat Completion API", 200
115
 
116
  if __name__ == '__main__':
 
117
  logger.info("Starting the application")
118
+ app.run(host="0.0.0.0", port=8000)