-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_sync.py
54 lines (39 loc) Β· 1.26 KB
/
app_sync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import argparse
from typing import Optional
import uvicorn
from fastapi import Request
from to_chatgpt import common
from to_chatgpt.common import BaseAdapter, init_app
adapter: Optional[BaseAdapter] = None
app = init_app()
server_name = "new_bing"
@app.get("/")
async def hello():
return f"hello, {server_name} to chatgpt server"
@app.api_route(
"/v1/chat/completions", methods=["POST", "OPTIONS"],
)
def chat(request: Request):
return common.chat(adapter, request)
def run():
parser = argparse.ArgumentParser()
parser.add_argument(
"-s", "--host", default="0.0.0.0", help="the hostname to listen on"
)
parser.add_argument(
"-p", "--port", type=int, default=8000, help="the port to listen on"
)
parser.add_argument(
"-a", "--adapter", default=server_name, help="the name of server adapter"
)
parser.add_argument("-l", "--log", default="debug", help="the log level")
args = parser.parse_args()
global adapter
if args.adapter == "bard":
from to_chatgpt.bard import BardAdapter
adapter = BardAdapter()
else:
raise ValueError(f"unknown adapter: {args.adapter}")
uvicorn.run(app, host=args.host, port=args.port, log_level=args.log)
if __name__ == "__main__":
run()