Updated constructors for base and derived classes in chat, embedding, rerank, sequence2txt, and tts models to accept **kwargs. This change improves extensibility and allows passing additional parameters without breaking existing interfaces. - [x] Bug Fix (non-breaking change which fixes an issue) --------- Co-authored-by: IT: Sop.Son <sop.son@feavn.local> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>tags/v0.20.1
| class OpenAI_APIChat(Base): | class OpenAI_APIChat(Base): | ||||
| _FACTORY_NAME = ["VLLM", "OpenAI-API-Compatible"] | _FACTORY_NAME = ["VLLM", "OpenAI-API-Compatible"] | ||||
| def __init__(self, key, model_name, base_url): | |||||
| def __init__(self, key, model_name, base_url, **kwargs): | |||||
| if not base_url: | if not base_url: | ||||
| raise ValueError("url cannot be None") | raise ValueError("url cannot be None") | ||||
| model_name = model_name.split("___")[0] | model_name = model_name.split("___")[0] | ||||
| super().__init__(key, model_name, base_url) | |||||
| super().__init__(key, model_name, base_url, **kwargs) | |||||
| class PPIOChat(Base): | class PPIOChat(Base): |
| class Base(ABC): | class Base(ABC): | ||||
| def __init__(self, key, model_name): | |||||
| def __init__(self, key, model_name, **kwargs): | |||||
| """ | |||||
| Constructor for abstract base class. | |||||
| Parameters are accepted for interface consistency but are not stored. | |||||
| Subclasses should implement their own initialization as needed. | |||||
| """ | |||||
| pass | pass | ||||
| def encode(self, texts: list): | def encode(self, texts: list): | ||||
| class HuggingFaceEmbed(Base): | class HuggingFaceEmbed(Base): | ||||
| _FACTORY_NAME = "HuggingFace" | _FACTORY_NAME = "HuggingFace" | ||||
| def __init__(self, key, model_name, base_url=None): | |||||
| def __init__(self, key, model_name, base_url=None, **kwargs): | |||||
| if not model_name: | if not model_name: | ||||
| raise ValueError("Model name cannot be None") | raise ValueError("Model name cannot be None") | ||||
| self.key = key | self.key = key | ||||
| def __init__(self, key, model_name, base_url="https://api.302.ai/v1/embeddings"): | def __init__(self, key, model_name, base_url="https://api.302.ai/v1/embeddings"): | ||||
| if not base_url: | if not base_url: | ||||
| base_url = "https://api.302.ai/v1/embeddings" | base_url = "https://api.302.ai/v1/embeddings" | ||||
| super().__init__(key, model_name, base_url) | |||||
| super().__init__(key, model_name, base_url) |
| from rag.utils import num_tokens_from_string, truncate | from rag.utils import num_tokens_from_string, truncate | ||||
| class Base(ABC): | class Base(ABC): | ||||
| def __init__(self, key, model_name): | |||||
| def __init__(self, key, model_name, **kwargs): | |||||
| """ | |||||
| Abstract base class constructor. | |||||
| Parameters are not stored; initialization is left to subclasses. | |||||
| """ | |||||
| pass | pass | ||||
| def similarity(self, query: str, texts: list): | def similarity(self, query: str, texts: list): | ||||
| class LmStudioRerank(Base): | class LmStudioRerank(Base): | ||||
| _FACTORY_NAME = "LM-Studio" | _FACTORY_NAME = "LM-Studio" | ||||
| def __init__(self, key, model_name, base_url): | |||||
| def __init__(self, key, model_name, base_url, **kwargs): | |||||
| pass | pass | ||||
| def similarity(self, query: str, texts: list): | def similarity(self, query: str, texts: list): | ||||
| class TogetherAIRerank(Base): | class TogetherAIRerank(Base): | ||||
| _FACTORY_NAME = "TogetherAI" | _FACTORY_NAME = "TogetherAI" | ||||
| def __init__(self, key, model_name, base_url): | |||||
| def __init__(self, key, model_name, base_url, **kwargs): | |||||
| pass | pass | ||||
| def similarity(self, query: str, texts: list): | def similarity(self, query: str, texts: list): |
| class Base(ABC): | class Base(ABC): | ||||
| def __init__(self, key, model_name): | |||||
| def __init__(self, key, model_name, **kwargs): | |||||
| """ | |||||
| Abstract base class constructor. | |||||
| Parameters are not stored; initialization is left to subclasses. | |||||
| """ | |||||
| pass | pass | ||||
| def transcription(self, audio, **kwargs): | def transcription(self, audio, **kwargs): |
| class Base(ABC): | class Base(ABC): | ||||
| def __init__(self, key, model_name, base_url): | |||||
| def __init__(self, key, model_name, base_url, **kwargs): | |||||
| """ | |||||
| Abstract base class constructor. | |||||
| Parameters are not stored; subclasses should handle their own initialization. | |||||
| """ | |||||
| pass | pass | ||||
| def tts(self, audio): | def tts(self, audio): |