mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 10:40:43 -08:00
Enhance Yupp provider to support API key management in model fetching
This commit is contained in:
parent
ef0867c0dc
commit
fec4185215
2 changed files with 16 additions and 7 deletions
|
|
@ -9,6 +9,7 @@ from ..providers.base_provider import AbstractProvider, ProviderModelMixin
|
||||||
from ..providers.response import Reasoning, PlainTextResponse, PreviewResponse
|
from ..providers.response import Reasoning, PlainTextResponse, PreviewResponse
|
||||||
from ..errors import RateLimitError, ProviderException
|
from ..errors import RateLimitError, ProviderException
|
||||||
from ..cookies import get_cookies
|
from ..cookies import get_cookies
|
||||||
|
from ..tools.auth import AuthManager
|
||||||
from .yupp.models import YuppModelManager
|
from .yupp.models import YuppModelManager
|
||||||
from ..debug import log
|
from ..debug import log
|
||||||
|
|
||||||
|
|
@ -161,10 +162,15 @@ class Yupp(AbstractProvider, ProviderModelMixin):
|
||||||
active_by_default = True
|
active_by_default = True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_models(cls) -> List[Dict[str, Any]]:
|
def get_models(cls, api_key: str = None, **kwargs) -> List[Dict[str, Any]]:
|
||||||
if not cls.models:
|
if not cls.models:
|
||||||
manager = YuppModelManager()
|
if not api_key:
|
||||||
|
api_key = AuthManager.load_api_key(cls)
|
||||||
|
if not api_key:
|
||||||
|
api_key = get_cookies("yupp.ai", False).get("__Secure-yupp.session-token")
|
||||||
|
manager = YuppModelManager(api_key=api_key)
|
||||||
models = manager.client.fetch_models()
|
models = manager.client.fetch_models()
|
||||||
|
if models:
|
||||||
cls.models = [model.get("name") for model in models]
|
cls.models = [model.get("name") for model in models]
|
||||||
return cls.models
|
return cls.models
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,9 +17,10 @@ class ModelConfig:
|
||||||
class YuppAPIClient:
|
class YuppAPIClient:
|
||||||
"""Yupp API client for fetching model data"""
|
"""Yupp API client for fetching model data"""
|
||||||
|
|
||||||
def __init__(self, config: ModelConfig = None):
|
def __init__(self, config: ModelConfig = None, api_key: str = None):
|
||||||
self.config = config or ModelConfig()
|
self.config = config or ModelConfig()
|
||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
|
self.api_key = api_key
|
||||||
self._setup_session()
|
self._setup_session()
|
||||||
|
|
||||||
def _setup_session(self) -> None:
|
def _setup_session(self) -> None:
|
||||||
|
|
@ -47,6 +48,8 @@ class YuppAPIClient:
|
||||||
self.session.cookies.set("__Secure-yupp.session-token", token)
|
self.session.cookies.set("__Secure-yupp.session-token", token)
|
||||||
|
|
||||||
def _get_session_token(self) -> Optional[str]:
|
def _get_session_token(self) -> Optional[str]:
|
||||||
|
if self.api_key:
|
||||||
|
return self.api_key
|
||||||
"""Get session token from environment variable"""
|
"""Get session token from environment variable"""
|
||||||
env_tokens = os.getenv("YUPP_TOKENS")
|
env_tokens = os.getenv("YUPP_TOKENS")
|
||||||
if not env_tokens:
|
if not env_tokens:
|
||||||
|
|
@ -221,9 +224,9 @@ class DataManager:
|
||||||
class YuppModelManager:
|
class YuppModelManager:
|
||||||
"""Main manager class for Yupp model operations"""
|
"""Main manager class for Yupp model operations"""
|
||||||
|
|
||||||
def __init__(self, config: ModelConfig = None):
|
def __init__(self, config: ModelConfig = None, api_key: str = None):
|
||||||
self.config = config or ModelConfig()
|
self.config = config or ModelConfig()
|
||||||
self.client = YuppAPIClient(config)
|
self.client = YuppAPIClient(config, api_key)
|
||||||
self.processor = ModelProcessor()
|
self.processor = ModelProcessor()
|
||||||
self.data_manager = DataManager()
|
self.data_manager = DataManager()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue