Spaces:
Build error
Build error
:recycle: [Refactor] Configure api info with config.json
Browse files- apis/chat_api.py +13 -9
- configs/__init__.py +0 -0
- configs/config.json +6 -0
- constants/{env.py → envs.py} +9 -3
- tests/openai.py +1 -1
apis/chat_api.py
CHANGED
@@ -12,6 +12,10 @@ from fastapi.responses import HTMLResponse
|
|
12 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
13 |
from pydantic import BaseModel, Field
|
14 |
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
|
|
|
|
|
|
|
|
15 |
|
16 |
from messagers.message_composer import MessageComposer
|
17 |
from mocks.stream_chat_mocker import stream_chat_mock
|
@@ -24,9 +28,9 @@ class ChatAPIApp:
|
|
24 |
def __init__(self):
|
25 |
self.app = FastAPI(
|
26 |
docs_url="/",
|
27 |
-
title="
|
28 |
swagger_ui_parameters={"defaultModelsExpandDepth": -1},
|
29 |
-
version="
|
30 |
)
|
31 |
self.setup_routes()
|
32 |
|
@@ -152,17 +156,17 @@ class ArgParser(argparse.ArgumentParser):
|
|
152 |
|
153 |
self.add_argument(
|
154 |
"-s",
|
155 |
-
"--
|
156 |
type=str,
|
157 |
-
default="
|
158 |
-
help="
|
159 |
)
|
160 |
self.add_argument(
|
161 |
"-p",
|
162 |
"--port",
|
163 |
type=int,
|
164 |
-
default=
|
165 |
-
help="
|
166 |
)
|
167 |
|
168 |
self.add_argument(
|
@@ -181,9 +185,9 @@ app = ChatAPIApp().app
|
|
181 |
if __name__ == "__main__":
|
182 |
args = ArgParser().args
|
183 |
if args.dev:
|
184 |
-
uvicorn.run("__main__:app", host=args.
|
185 |
else:
|
186 |
-
uvicorn.run("__main__:app", host=args.
|
187 |
|
188 |
# python -m apis.chat_api # [Docker] on product mode
|
189 |
# python -m apis.chat_api -d # [Dev] on develop mode
|
|
|
12 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
13 |
from pydantic import BaseModel, Field
|
14 |
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
15 |
+
from tclogger import logger
|
16 |
+
|
17 |
+
from constants.models import AVAILABLE_MODELS_DICTS
|
18 |
+
from constants.envs import CONFIG
|
19 |
|
20 |
from messagers.message_composer import MessageComposer
|
21 |
from mocks.stream_chat_mocker import stream_chat_mock
|
|
|
28 |
def __init__(self):
|
29 |
self.app = FastAPI(
|
30 |
docs_url="/",
|
31 |
+
title=CONFIG["app_name"],
|
32 |
swagger_ui_parameters={"defaultModelsExpandDepth": -1},
|
33 |
+
version=CONFIG["version"],
|
34 |
)
|
35 |
self.setup_routes()
|
36 |
|
|
|
156 |
|
157 |
self.add_argument(
|
158 |
"-s",
|
159 |
+
"--host",
|
160 |
type=str,
|
161 |
+
default=CONFIG["host"],
|
162 |
+
help=f"Host for {CONFIG['app_name']}",
|
163 |
)
|
164 |
self.add_argument(
|
165 |
"-p",
|
166 |
"--port",
|
167 |
type=int,
|
168 |
+
default=CONFIG["port"],
|
169 |
+
help=f"Port for {CONFIG['app_name']}",
|
170 |
)
|
171 |
|
172 |
self.add_argument(
|
|
|
185 |
if __name__ == "__main__":
|
186 |
args = ArgParser().args
|
187 |
if args.dev:
|
188 |
+
uvicorn.run("__main__:app", host=args.host, port=args.port, reload=True)
|
189 |
else:
|
190 |
+
uvicorn.run("__main__:app", host=args.host, port=args.port, reload=False)
|
191 |
|
192 |
# python -m apis.chat_api # [Docker] on product mode
|
193 |
# python -m apis.chat_api -d # [Dev] on develop mode
|
configs/__init__.py
ADDED
File without changes
|
configs/config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"app_name": "HuggingFace LLM API",
|
3 |
+
"version": "1.0.7",
|
4 |
+
"host": "0.0.0.0",
|
5 |
+
"port": 23333
|
6 |
+
}
|
constants/{env.py → envs.py}
RENAMED
@@ -1,10 +1,13 @@
|
|
1 |
from pathlib import Path
|
2 |
from tclogger import logger, OSEnver
|
3 |
|
4 |
-
secrets_path = Path(__file__).parents[1] / "secrets.json"
|
5 |
-
ENVER = OSEnver(secrets_path)
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
8 |
if http_proxy:
|
9 |
logger.note(f"> Using proxy: {http_proxy}")
|
10 |
PROXIES = {
|
@@ -13,3 +16,6 @@ if http_proxy:
|
|
13 |
}
|
14 |
else:
|
15 |
PROXIES = None
|
|
|
|
|
|
|
|
1 |
from pathlib import Path
|
2 |
from tclogger import logger, OSEnver
|
3 |
|
|
|
|
|
4 |
|
5 |
+
config_root = Path(__file__).parents[1] / "configs"
|
6 |
+
|
7 |
+
secrets_path = config_root / "secrets.json"
|
8 |
+
SECRETS = OSEnver(secrets_path)
|
9 |
+
|
10 |
+
http_proxy = SECRETS["http_proxy"]
|
11 |
if http_proxy:
|
12 |
logger.note(f"> Using proxy: {http_proxy}")
|
13 |
PROXIES = {
|
|
|
16 |
}
|
17 |
else:
|
18 |
PROXIES = None
|
19 |
+
|
20 |
+
config_path = config_root / "config.json"
|
21 |
+
CONFIG = OSEnver(config_path)
|
tests/openai.py
CHANGED
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
7 |
|
8 |
from curl_cffi import requests
|
9 |
from tclogger import logger, OSEnver
|
10 |
-
from constants.
|
11 |
|
12 |
|
13 |
class OpenaiAPI:
|
|
|
7 |
|
8 |
from curl_cffi import requests
|
9 |
from tclogger import logger, OSEnver
|
10 |
+
from constants.envs import PROXIES
|
11 |
|
12 |
|
13 |
class OpenaiAPI:
|