Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Persistent chrome (nodriver) windows openned -- python client #2582

Closed
otomay opened this issue Jan 17, 2025 · 8 comments
Closed

Persistent chrome (nodriver) windows openned -- python client #2582

otomay opened this issue Jan 17, 2025 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@otomay
Copy link

otomay commented Jan 17, 2025

When using:

from g4f.client import Client

client = Client()

while True:
  response = client.chat.completions.create(
      model="gpt-4o-mini",
      messages=[{"role": "user", "content": "Hello"}],
      web_search = False
  )
  print(response.choices[0].message.content)

for some provider, a nodriver window is openned with headless = false (for some, it's not). And stays there openned using resources untill the script is finished, when I got:

successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver
successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver
successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver
successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver
successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver
successfully removed temp profile C:\Users\xxx\AppData\Local\g4f-nodriver\g4f-nodriver

It doesn't use the same chrome window, it keeps oppening up new ones.
am I doing something wrong?

@otomay otomay added the bug Something isn't working label Jan 17, 2025
@hlohaus
Copy link
Collaborator

hlohaus commented Jan 24, 2025

Only the Cloudflare provider need nodriver to do work.
But it should cache the result in auth_.json file.
I don't know why it's not working for you.
Maybe add Cloudflare to your provider ignore list.

@otomay
Copy link
Author

otomay commented Jan 24, 2025

Hey, thanks!

How can I do this? I searched for "ignore" in the client api docs, but didn't found anything.

@otomay
Copy link
Author

otomay commented Jan 24, 2025

I was looking at https://github.com/xtekky/gpt4free/blob/main/docs/providers-and-models.md

I'm using gpt-4o-mini on my script. I think cloudflare is not an provider option to it, if we're talking about https://playground.ai.cloudflare.com

Is there a way to identify which provider was used on the generation?

@otomay
Copy link
Author

otomay commented Jan 24, 2025

I learned how to see the provider

Just print(response) and it's possible to see in the console.
So here is the results of my tests:

It's random. Example: sometimes the PollinationsAI opens a nodriver windows (headless = false) and sometimes don't. Same for DDG, and I supose for almost all providers.

So, the reason for me to have a lot of chrome windows (headless = false) in my desktop it's bc the providers require it in some point and each one use 1 instance of it. They keep using only one window like @hlohaus said, but as each one needs one nodriver isntance, after sometime I get lots of chrome windows openned.

@hlohaus
Copy link
Collaborator

hlohaus commented Jan 24, 2025

We do not employ headless browser instances due to their incompatibility with our operational requirements. Authentication is managed through non-headless browser instances; following successful authentication, the request is terminated, and the browser instances are closed or the web server is shut down. Alternatively, the lightweight GPT4Free alternative may be more appropriate. To uninstall nodriver, please execute: pip uninstall nodriver.

@otomay

@otomay
Copy link
Author

otomay commented Jan 24, 2025

I may be wrong, but it's possible that I'm experiencing this bc my default profile for chrome opens up 3 tabs.

I recall that I had trouble closing selenium with driver.close(), cuz this only closes the current tab and not the entire browser. So I had to do a loop to close all tabs, or use the .quit() method.

Anyways, thanks for helping!

@hlohaus
Copy link
Collaborator

hlohaus commented Jan 25, 2025

@otomay, I have added a lock file for nodriver in the new version to ensure that only one browser instance starts at a time. Additionally, I have added a finally block to stop the browser in all nodriver calls within g4f. This should help prevent any issues with multiple browser instances running simultaneously.

@otomay
Copy link
Author

otomay commented Jan 27, 2025

Thanks @hlohaus! I can confirm it fixed the behavior!

@otomay otomay closed this as completed Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants