Skip to content

Commit

Permalink
Merge branch 'xtekky:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kqlio67 authored Nov 24, 2024
2 parents 9104755 + f36e6a2 commit ed3df83
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
20 changes: 7 additions & 13 deletions g4f/Provider/needs_auth/Gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from ..helper import format_prompt, get_cookies
from ...requests.raise_for_status import raise_for_status
from ...requests.aiohttp import get_connector
from ...requests import get_nodriver
from ...errors import MissingAuthError
from ...image import ImageResponse, to_bytes
from ... import debug
Expand Down Expand Up @@ -68,17 +69,7 @@ async def nodriver_login(cls, proxy: str = None) -> AsyncIterator[str]:
if debug.logging:
print("Skip nodriver login in Gemini provider")
return
try:
from platformdirs import user_config_dir
user_data_dir = user_config_dir("g4f-nodriver")
except:
user_data_dir = None
if debug.logging:
print(f"Open nodriver with user_dir: {user_data_dir}")
browser = await nodriver.start(
user_data_dir=user_data_dir,
browser_args=None if proxy is None else [f"--proxy-server={proxy}"],
)
browser = await get_nodriver(proxy=proxy)
login_url = os.environ.get("G4F_LOGIN_URL")
if login_url:
yield f"Please login: [Google Gemini]({login_url})\n\n"
Expand Down Expand Up @@ -118,8 +109,11 @@ async def create_async_generator(
if not cls._snlm0e:
await cls.fetch_snlm0e(session, cls._cookies) if cls._cookies else None
if not cls._snlm0e:
async for chunk in cls.nodriver_login(proxy):
yield chunk
try:
async for chunk in cls.nodriver_login(proxy):
yield chunk
except Exception as e:
raise MissingAuthError('Missing "__Secure-1PSID" cookie', e)
if not cls._snlm0e:
if cls._cookies is None or "__Secure-1PSID" not in cls._cookies:
raise MissingAuthError('Missing "__Secure-1PSID" cookie')
Expand Down
12 changes: 10 additions & 2 deletions g4f/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ class ProviderResponseModel(BaseModel):
object: str = "provider"
created: int
owned_by: Optional[str]
url: Optional[str]
label: Optional[str]
class ProviderResponseModelDetail(ProviderResponseModel):
models: list[str]
image_models: list[str]
vision_models: list[str]
params: list[str]

class ModelResponseModel(BaseModel):
id: str
Expand Down Expand Up @@ -299,7 +307,7 @@ async def providers() -> list[ProviderResponseModel]:
} for provider in __providers__ if provider.working]

@self.app.get("/v1/providers/{provider}")
async def providers_info(provider: str) -> ProviderResponseModel:
async def providers_info(provider: str) -> ProviderResponseModelDetail:
if provider not in ProviderUtils.convert:
return JSONResponse({"error": "The provider does not exist."}, 404)
provider: ProviderType = ProviderUtils.convert[provider]
Expand Down Expand Up @@ -396,4 +404,4 @@ def run_api(
use_colors=use_colors,
factory=True,
reload=reload
)
)
1 change: 0 additions & 1 deletion g4f/gui/server/internet.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ async def search(query: str, n_results: int = 5, max_words: int = 2500, add_text
safesearch="moderate",
timelimit="y",
max_results=n_results,
backend="html"
):
results.append(SearchResultEntry(
result["title"],
Expand Down

0 comments on commit ed3df83

Please sign in to comment.