Spaces:
Running
Running
:recycle: [Refactor] Move AVAILABLE_MODELS(_DICTS) to constants
Browse filesFiles changed (3)
4 unmodified lines5678910111213141516171819207 unmodified lines282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475764 unmodified linesimport uvicornfrom pathlib import Pathfrom fastapi import FastAPI, Dependsfrom fastapi.responses import HTMLResponsefrom fastapi.security import HTTPBearer, HTTPAuthorizationCredentialsfrom pydantic import BaseModel, Fieldfrom typing import Unionfrom sse_starlette.sse import EventSourceResponse, ServerSentEventfrom utils.logger import loggerfrom networks.message_streamer import MessageStreamerfrom messagers.message_composer import MessageComposerfrom mocks.stream_chat_mocker import stream_chat_mockclass ChatAPIApp:7 unmodified linesself.setup_routes()def get_available_models(self):# https://platform.openai.com/docs/api-reference/models/list# ANCHOR[id=available-models]: Available modelsself.available_models = {"object": "list","data": [{"id": "mixtral-8x7b","description": "[mistralai/Mixtral-8x7B-Instruct-v0.1]: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1","object": "model","created": 1700000000,"owned_by": "mistralai",},{"id": "nous-mixtral-8x7b","description": "[NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO]: https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO","object": "model","created": 1700000000,"owned_by": "NousResearch",},{"id": "mistral-7b","description": "[mistralai/Mistral-7B-Instruct-v0.2]: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2","object": "model","created": 1700000000,"owned_by": "mistralai",},{"id": "openchat-3.5","description": "[openchat/openchat-3.5-0106]: https://huggingface.co/openchat/openchat-3.5-0106","object": "model","created": 1700000000,"owned_by": "openchat",},{"id": "gemma-7b","description": "[google/gemma-7b-it]: https://huggingface.co/google/gemma-7b-it","object": "model","created": 1700000000,"owned_by": "Google",},],}return self.available_modelsdef extract_api_key(credentials: HTTPAuthorizationCredentials = Depends(4 unmodified lines5678910111213141516171819202122237 unmodified lines313233343536374 unmodified linesimport uvicornfrom pathlib import Pathfrom typing import Unionfrom fastapi import FastAPI, Dependsfrom fastapi.responses import HTMLResponsefrom fastapi.security import HTTPBearer, HTTPAuthorizationCredentialsfrom pydantic import BaseModel, Fieldfrom sse_starlette.sse import EventSourceResponse, ServerSentEventfrom messagers.message_composer import MessageComposerfrom mocks.stream_chat_mocker import stream_chat_mockfrom networks.message_streamer import MessageStreamerfrom utils.logger import loggerfrom constants.models import AVAILABLE_MODELS_DICTSclass ChatAPIApp:7 unmodified linesself.setup_routes()def get_available_models(self):return {"object": "list", "data": AVAILABLE_MODELS_DICTS}def extract_api_key(credentials: HTTPAuthorizationCredentials = Depends(
24 unmodified lines25262724 unmodified lines}TOKEN_RESERVED = 2024 unmodified lines25262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747524 unmodified lines}TOKEN_RESERVED = 20AVAILABLE_MODELS = ["mixtral-8x7b","nous-mixtral-8x7b","mistral-7b","openchat-3.5","gemma-7b",]# https://platform.openai.com/docs/api-reference/models/listAVAILABLE_MODELS_DICTS = [{"id": "mixtral-8x7b","description": "[mistralai/Mixtral-8x7B-Instruct-v0.1]: https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1","object": "model","created": 1700000000,"owned_by": "mistralai",},{"id": "nous-mixtral-8x7b","description": "[NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO]: https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO","object": "model","created": 1700000000,"owned_by": "NousResearch",},{"id": "mistral-7b","description": "[mistralai/Mistral-7B-Instruct-v0.2]: https://huggingface.co/mistralai/Mistral-7B-Instruct-v0.2","object": "model","created": 1700000000,"owned_by": "mistralai",},{"id": "openchat-3.5","description": "[openchat/openchat-3.5-0106]: https://huggingface.co/openchat/openchat-3.5-0106","object": "model","created": 1700000000,"owned_by": "openchat",},{"id": "gemma-7b","description": "[google/gemma-7b-it]: https://huggingface.co/google/gemma-7b-it","object": "model","created": 1700000000,"owned_by": "Google",},]
123456789101112131415161718192021import refrom pprint import pprintfrom utils.logger import loggerfrom transformers import AutoTokenizerclass MessageComposer:# LINK - apis/chat_api.py#available-modelsAVALAIBLE_MODELS = ["mixtral-8x7b","mistral-7b","nous-mixtral-8x7b","openchat-3.5","gemma-7b",]def __init__(self, model: str = None):if model in self.AVALAIBLE_MODELS:self.model = modelelse:self.model = "mixtral-8x7b"123456789101112131415import refrom pprint import pprintfrom transformers import AutoTokenizerfrom constants.models import AVAILABLE_MODELSfrom utils.logger import loggerclass MessageComposer:def __init__(self, model: str = None):if model in AVAILABLE_MODELS:self.model = modelelse:self.model = "mixtral-8x7b"
apis/chat_api.py+7-46
constants/models.py+48
messagers/message_composer.py+5-11