Spaces:
Paused
Paused
:recycle: [Refactor] Move AVAILABLE_MODELS(_DICTS) to constants
Browse filesFiles changed (3)
4 unmodified lines5678910111213121414151516171819202122237 unmodified lines31323331323334353637383940414243444546474849505152535455565758596061626364656667686970717273343536374 unmodified linesimport uvicorn
from pathlib import Pathfrom typing import Union
from 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 MessageStreamer
from 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_DICTS
class ChatAPIApp:7 unmodified lines self.setup_routes()
def get_available_models(self): # https://platform.openai.com/docs/api-reference/models/list # ANCHOR[id=available-models]: Available models self.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_models return {"object": "list", "data": AVAILABLE_MODELS_DICTS}
def extract_api_key( credentials: HTTPAuthorizationCredentials = Depends(24 unmodified lines25262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747524 unmodified lines}
TOKEN_RESERVED = 20
AVAILABLE_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", },]1233456789108910111213141516111812131415import refrom pprint import pprintfrom utils.logger import logger
from transformers import AutoTokenizer
from constants.models import AVAILABLE_MODELSfrom utils.logger import logger
class MessageComposer: # LINK - apis/chat_api.py#available-models AVALAIBLE_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: if model in AVAILABLE_MODELS: self.model = model else: self.model = "mixtral-8x7b"apis/chat_api.py+7-46
constants/models.py+48
messagers/message_composer.py+5-11