mirror of
https://github.com/NicolasBohn/NexQuant.git
synced 2026-08-01 09:27:43 +00:00
97c1f7a021
* File structure for supporting litellm * more litellm support * feat: Add CachedAPIBackend class and dynamic API backend retrieval function * fix: update benchmark folder path and add default values for architecture and hyperparameters * feat: add LiteLLMAPIBackend and DeprecBackend ; changed structure of the project ; with bus * fix : deprec_backend * feat: Add LiteLLMAPIBackend class and related features; update configuration and test cases. * feat: Enhance LiteLLMAPIBackend with encoder support and dynamic argument handling;Enhance log Colors * lint * fix lint... * fix: Lint * fix:make auto-lint * fix:test oai * fix:redundant _abckend.py * fix: Optimize LiteLLMAPIBackend on token counting functiona, and clean up unused code;add test on this function * feat: Add LiteLLMSettings class and update model settings usage * fix: Update LiteLLMSettings environment variable prefix and model configurations * fix : gitignore * test: Consolidate and relocate test files for litellm backend and oai * fix : lint * fix: lint * auto lint * lint * LINT * lint * chore: remove deprecated backend configuration comments * refactor: Remove unused functions and imports from deprec.py and llm_utils.py * refactor: Move md5_hash function from deprec.py to llm_utils.py * chore: Remove extra newline and add missing import in deprec.py * lint * refactor: Move md5_hash function to utils module * lint * lint * lint --------- Co-authored-by: Young <afe.young@gmail.com> Co-authored-by: Yihua Chen <v-yihuachen@microsoft.com>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
from abc import ABC, abstractmethod
|
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
|
|
|
|
class APIBackend(ABC):
|
|
"""Abstract base class for LLM API backends"""
|
|
|
|
@abstractmethod
|
|
def build_chat_session(
|
|
self, conversation_id: Optional[str] = None, session_system_prompt: Optional[str] = None
|
|
) -> Any:
|
|
"""Create a new chat session"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def build_messages_and_create_chat_completion(
|
|
self,
|
|
user_prompt: str,
|
|
system_prompt: Optional[str] = None,
|
|
former_messages: Optional[List[Any]] = None,
|
|
chat_cache_prefix: str = "",
|
|
shrink_multiple_break: bool = False,
|
|
*args: Any,
|
|
**kwargs: Any,
|
|
) -> str:
|
|
"""Build messages and get chat completion"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def create_embedding(
|
|
self, input_content: Union[str, List[str]], *args: Any, **kwargs: Any
|
|
) -> Union[List[Any], Any]:
|
|
"""Create embeddings for input text"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def build_messages_and_calculate_token(
|
|
self,
|
|
user_prompt: str,
|
|
system_prompt: Optional[str],
|
|
former_messages: Optional[List[Dict[str, Any]]] = None,
|
|
*,
|
|
shrink_multiple_break: bool = False,
|
|
) -> int:
|
|
"""Build messages and calculate their token count"""
|
|
pass
|
|
|
|
|
|
# TODO: seperate cache layer. try to be tranparent.
|
|
class CachedAPIBackend(APIBackend):
|
|
...
|
|
# @abstractmethod
|
|
# def none_cache_function ...
|