mirror of
https://github.com/xtekky/gpt4free.git
synced 2026-04-22 15:47:11 +08:00
fix: Update active_by_default to False for Claude and Cohere providers; refactor Gemini login methods and enhance OpenRouterFree class
This commit is contained in:
@@ -11,7 +11,7 @@ class Claude(OpenaiTemplate):
|
||||
url = "https://claude.ai"
|
||||
base_url = "https://g4f.space/api/claude"
|
||||
working = True
|
||||
active_by_default = True
|
||||
active_by_default = False
|
||||
login_url = "https://discord.gg/qXA4Wf4Fsm"
|
||||
organization_id = None
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ class Cohere(AsyncGeneratorProvider, ProviderModelMixin):
|
||||
login_url = "https://dashboard.cohere.com/api-keys"
|
||||
api_endpoint = "https://api.cohere.ai/v2/chat"
|
||||
working = True
|
||||
active_by_default = True
|
||||
active_by_default = False
|
||||
needs_auth = True
|
||||
models_needs_auth = True
|
||||
supports_stream = True
|
||||
|
||||
@@ -105,7 +105,7 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
|
||||
rotate_tasks = {}
|
||||
|
||||
@classmethod
|
||||
async def login(cls, proxy: str = None) -> AsyncIterator[str]:
|
||||
async def login_generator(cls, proxy: str = None) -> AsyncIterator[str]:
|
||||
if not has_nodriver:
|
||||
debug.log("Skip nodriver login in Gemini provider")
|
||||
return
|
||||
@@ -122,6 +122,12 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
|
||||
finally:
|
||||
await stop_browser()
|
||||
|
||||
@classmethod
|
||||
async def login(cls, proxy: str = None) -> AsyncIterator[str]:
|
||||
async for _ in cls.login_generator(proxy):
|
||||
pass
|
||||
return {"success": True, "message": "Login successful"}
|
||||
|
||||
@classmethod
|
||||
async def start_auto_refresh(cls, proxy: str = None) -> None:
|
||||
"""
|
||||
@@ -200,7 +206,7 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
|
||||
await cls.fetch_snlm0e(session, cls._cookies) if cls._cookies else None
|
||||
if not cls._snlm0e:
|
||||
try:
|
||||
async for chunk in cls.login(proxy):
|
||||
async for chunk in cls.login_generator(proxy):
|
||||
yield chunk
|
||||
except Exception as e:
|
||||
raise MissingAuthError('Missing or invalid "__Secure-1PSID" cookie', e)
|
||||
|
||||
@@ -11,10 +11,14 @@ class OpenRouter(OpenaiTemplate):
|
||||
needs_auth = True
|
||||
default_model = "openrouter/auto"
|
||||
|
||||
class OpenRouterFree(OpenRouter):
|
||||
class OpenRouterFree(OpenaiTemplate):
|
||||
label = "OpenRouter (free)"
|
||||
base_url = "https://g4f.space/api/openrouter"
|
||||
max_tokens = 4096
|
||||
url = "https://openrouter.ai"
|
||||
login_url = "https://openrouter.ai/settings/keys"
|
||||
base_url = "https://openrouter.ai/api/v1"
|
||||
backup_url = "https://g4f.space/api/openrouter"
|
||||
max_tokens = 8192
|
||||
working = True
|
||||
active_by_default = True
|
||||
default_model = "openrouter/free"
|
||||
|
||||
|
||||
@@ -39,8 +39,10 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
|
||||
"""Get the quota information for the API key."""
|
||||
if not api_key:
|
||||
api_key = AuthManager.load_api_key(cls)
|
||||
if cls.models_needs_auth and cls.quota_url is None:
|
||||
if api_key and cls.models_needs_auth and cls.quota_url is None:
|
||||
cls.quota_url = f"{cls.base_url}/models"
|
||||
if cls.quota_url is None and cls.backup_url is not None:
|
||||
cls.quota_url = f"{cls.backup_url}/chat/completions"
|
||||
if cls.quota_url is not None:
|
||||
return await super().get_quota(api_key=api_key, **kwargs)
|
||||
if not api_key and cls.needs_auth:
|
||||
|
||||
Reference in New Issue
Block a user