:recycle: [Refactor] Move AVAILABLE_MODELS(_DICTS) to constants
Browse files- apis/chat_api.py +7 -46
- constants/models.py +48 -0
- messagers/message_composer.py +5 -11
apis/chat_api.py
CHANGED
@@ -5,16 +5,19 @@ import sys
|
|
5 |
import uvicorn
|
6 |
|
7 |
from pathlib import Path
|
|
|
|
|
8 |
from fastapi import FastAPI, Depends
|
9 |
from fastapi.responses import HTMLResponse
|
10 |
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
11 |
from pydantic import BaseModel, Field
|
12 |
-
from typing import Union
|
13 |
from sse_starlette.sse import EventSourceResponse, ServerSentEvent
|
14 |
-
|
15 |
-
from networks.message_streamer import MessageStreamer
|
16 |
from messagers.message_composer import MessageComposer
|
17 |
from mocks.stream_chat_mocker import stream_chat_mock
|
|
|
|
|
|
|
18 |
|
19 |
|
20 |
class ChatAPIApp:
|
@@ -28,49 +31,7 @@ class ChatAPIApp:
|
|
28 |
self.setup_routes()
|
29 |
|
30 |
def get_available_models(self):
|
31 |
-
|
32 |
-
# ANCHOR[id=available-models]: Available models
|
33 |
-
self.available_models = {
|
34 |
-
"object": "list",
|
35 |
-
"data": [
|
36 |
-
{
|
37 |
-
"id": "mixtral-8x7b",
|
38 |
-
"description": "[mistralai/Mixtral-8x7B-Instruct-v0.1]: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
39 |
-
"object": "model",
|
40 |
-
"created": 1700000000,
|
41 |
-
"owned_by": "mistralai",
|
42 |
-
},
|
43 |
-
{
|
44 |
-
"id": "nous-mixtral-8x7b",
|
45 |
-
"description": "[NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO]: https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
46 |
-
"object": "model",
|
47 |
-
"created": 1700000000,
|
48 |
-
"owned_by": "NousResearch",
|
49 |
-
},
|
50 |
-
{
|
51 |
-
"id": "mistral-7b",
|
52 |
-
"description": "[mistralai/Mistral-7B-Instruct-v0.2]: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2",
|
53 |
-
"object": "model",
|
54 |
-
"created": 1700000000,
|
55 |
-
"owned_by": "mistralai",
|
56 |
-
},
|
57 |
-
{
|
58 |
-
"id": "openchat-3.5",
|
59 |
-
"description": "[openchat/openchat-3.5-0106]: https://huggingface.co/openchat/openchat-3.5-0106",
|
60 |
-
"object": "model",
|
61 |
-
"created": 1700000000,
|
62 |
-
"owned_by": "openchat",
|
63 |
-
},
|
64 |
-
{
|
65 |
-
"id": "gemma-7b",
|
66 |
-
"description": "[google/gemma-7b-it]: https://huggingface.co/google/gemma-7b-it",
|
67 |
-
"object": "model",
|
68 |
-
"created": 1700000000,
|
69 |
-
"owned_by": "Google",
|
70 |
-
},
|
71 |
-
],
|
72 |
-
}
|
73 |
-
return self.available_models
|
74 |
|
75 |
def extract_api_key(
|
76 |
credentials: HTTPAuthorizationCredentials = Depends(
|
|
|
5 |
import uvicorn
|
6 |
|
7 |
from pathlib import Path
|
8 |
+
from typing import Union
|
9 |
+
|
10 |
from fastapi import FastAPI, Depends
|
11 |
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
|
18 |
+
from networks.message_streamer import MessageStreamer
|
19 |
+
from utils.logger import logger
|
20 |
+
from constants.models import AVAILABLE_MODELS_DICTS
|
21 |
|
22 |
|
23 |
class ChatAPIApp:
|
|
|
31 |
self.setup_routes()
|
32 |
|
33 |
def get_available_models(self):
|
34 |
+
return {"object": "list", "data": AVAILABLE_MODELS_DICTS}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
def extract_api_key(
|
37 |
credentials: HTTPAuthorizationCredentials = Depends(
|
constants/models.py
CHANGED
@@ -25,3 +25,51 @@ TOKEN_LIMIT_MAP = {
|
|
25 |
}
|
26 |
|
27 |
TOKEN_RESERVED = 20
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
}
|
26 |
|
27 |
TOKEN_RESERVED = 20
|
28 |
+
|
29 |
+
|
30 |
+
AVAILABLE_MODELS = [
|
31 |
+
"mixtral-8x7b",
|
32 |
+
"nous-mixtral-8x7b",
|
33 |
+
"mistral-7b",
|
34 |
+
"openchat-3.5",
|
35 |
+
"gemma-7b",
|
36 |
+
]
|
37 |
+
|
38 |
+
# https://platform.openai.com/docs/api-reference/models/list
|
39 |
+
AVAILABLE_MODELS_DICTS = [
|
40 |
+
{
|
41 |
+
"id": "mixtral-8x7b",
|
42 |
+
"description": "[mistralai/Mixtral-8x7B-Instruct-v0.1]: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1",
|
43 |
+
"object": "model",
|
44 |
+
"created": 1700000000,
|
45 |
+
"owned_by": "mistralai",
|
46 |
+
},
|
47 |
+
{
|
48 |
+
"id": "nous-mixtral-8x7b",
|
49 |
+
"description": "[NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO]: https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
|
50 |
+
"object": "model",
|
51 |
+
"created": 1700000000,
|
52 |
+
"owned_by": "NousResearch",
|
53 |
+
},
|
54 |
+
{
|
55 |
+
"id": "mistral-7b",
|
56 |
+
"description": "[mistralai/Mistral-7B-Instruct-v0.2]: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2",
|
57 |
+
"object": "model",
|
58 |
+
"created": 1700000000,
|
59 |
+
"owned_by": "mistralai",
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"id": "openchat-3.5",
|
63 |
+
"description": "[openchat/openchat-3.5-0106]: https://huggingface.co/openchat/openchat-3.5-0106",
|
64 |
+
"object": "model",
|
65 |
+
"created": 1700000000,
|
66 |
+
"owned_by": "openchat",
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"id": "gemma-7b",
|
70 |
+
"description": "[google/gemma-7b-it]: https://huggingface.co/google/gemma-7b-it",
|
71 |
+
"object": "model",
|
72 |
+
"created": 1700000000,
|
73 |
+
"owned_by": "Google",
|
74 |
+
},
|
75 |
+
]
|
messagers/message_composer.py
CHANGED
@@ -1,21 +1,15 @@
|
|
1 |
import re
|
2 |
from pprint import pprint
|
3 |
-
|
4 |
from transformers import AutoTokenizer
|
5 |
|
|
|
|
|
|
|
6 |
|
7 |
class MessageComposer:
|
8 |
-
# LINK - apis/chat_api.py#available-models
|
9 |
-
AVALAIBLE_MODELS = [
|
10 |
-
"mixtral-8x7b",
|
11 |
-
"mistral-7b",
|
12 |
-
"nous-mixtral-8x7b",
|
13 |
-
"openchat-3.5",
|
14 |
-
"gemma-7b",
|
15 |
-
]
|
16 |
-
|
17 |
def __init__(self, model: str = None):
|
18 |
-
if model in
|
19 |
self.model = model
|
20 |
else:
|
21 |
self.model = "mixtral-8x7b"
|
|
|
1 |
import re
|
2 |
from pprint import pprint
|
3 |
+
|
4 |
from transformers import AutoTokenizer
|
5 |
|
6 |
+
from constants.models import AVAILABLE_MODELS
|
7 |
+
from utils.logger import logger
|
8 |
+
|
9 |
|
10 |
class MessageComposer:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
def __init__(self, model: str = None):
|
12 |
+
if model in AVAILABLE_MODELS:
|
13 |
self.model = model
|
14 |
else:
|
15 |
self.model = "mixtral-8x7b"
|