-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
62 lines (45 loc) Β· 1.53 KB
/
app.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
55
56
57
58
59
60
61
62
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"],
)
async def chat(request: Request):
return await common.achat(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 == "new_bing":
from to_chatgpt.new_bing import NewBingAdapter
adapter = NewBingAdapter()
elif args.adapter == "claude":
from to_chatgpt.claude import ClaudeAdapter
adapter = ClaudeAdapter()
elif args.adapter == "cohere":
from to_chatgpt.cohere import CohereAdapter
adapter = CohereAdapter()
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()