gpt4free icon indicating copy to clipboard operation
gpt4free copied to clipboard

Fails to read har file with You provider (MissingRequirementsError) in Jupyter Notebook

Open Infinitay opened this issue 3 months ago • 9 comments

Issue

When trying to run the You provider, it fails to read my har file and keeps throwing MissingRequirementsError: Add .har file from you.com or install "nodriver" package | pip install -U nodriver despite placing the respective har file within the current working directory under ./har_and_cookies/you.com.har. I am using gpt4free's module within a jupyter notebook.

Code

client = Client()
response = client.chat.completions.create(
    model="claude-3-sonnet",
	provider="You",
    messages=[{"role": "user", "content": """Hello World"""}]
)
print(response.choices[0].message.content)

Environment

Python: 3.12.3 g4f: 0.3.0.7 miniconda: 23.7.4

Stacktrace

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File c:\Users\admin\miniconda3\envs\gpt4free\Lib\site-packages\g4f\Provider\you\har_file.py:85, in get_telemetry_ids(proxy)
     84 try:
---> 85     from nodriver import start
     86 except ImportError:

ModuleNotFoundError: No module named 'nodriver'

During handling of the above exception, another exception occurred:

MissingRequirementsError                  Traceback (most recent call last)
Cell In[4], line 2
      1 client = Client()
----> 2 response = client.chat.completions.create(
      3     model="claude-3-sonnet",
      4 	provider="You",
      5     messages=[{"role": "user", "content": """Hello World"""}]
      6 )
      7 print(response.choices[0].message.content)

File c:\Users\admin\miniconda3\envs\gpt4free\Lib\site-packages\g4f\client\client.py:114, in Completions.create(self, messages, model, provider, stream, proxy, response_format, max_tokens, stop, api_key, ignored, ignore_working, ignore_stream, **kwargs)
    112 response = iter_response(response, stream, response_format, max_tokens, stop)
    113 response = iter_append_model_and_provider(response)
--> 114 return response if stream else next(response)
...
---> 87     raise MissingRequirementsError('Add .har file from you.com or install "nodriver" package | pip install -U nodriver')
     88 page = None
     89 try:

MissingRequirementsError: Add .har file from you.com or install "nodriver" package | pip install -U nodriver

Infinitay avatar Apr 30 '24 21:04 Infinitay

You obviously should download the nodriver try to to this: pip install -U nodriver

noneherel avatar May 03 '24 00:05 noneherel

I thought it will extract the cookies found in the HAR file and use raw requests so I didn't install the web driver. Also the error itself said add the HAR file or install the "nodriver" package, so I thought I could either supply the HAR which I did or install the package. Nonetheless, I did what you said and after installing the package, I'm now receiving another error:

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
Cell In[1], line 3
      1 from g4f.client import Client
      2 client = Client()
----> 3 response = client.chat.completions.create(
      4     model="claude-3-sonnet",
      5     messages=[{"role": "user", "content": """Hello World"""}]
      6 )
      7 print(response.choices[0].message.content)

File c:\Users\admin\miniconda3\envs\gpt4free\Lib\site-packages\g4f\client\client.py:114, in Completions.create(self, messages, model, provider, stream, proxy, response_format, max_tokens, stop, api_key, ignored, ignore_working, ignore_stream, **kwargs)
    112 response = iter_response(response, stream, response_format, max_tokens, stop)
    113 response = iter_append_model_and_provider(response)
--> 114 return response if stream else next(response)

File c:\Users\admin\miniconda3\envs\gpt4free\Lib\site-packages\g4f\client\client.py:53, in iter_append_model_and_provider(response)
     51 def iter_append_model_and_provider(response: IterResponse) -> IterResponse:
     52     last_provider = None
---> 53     for chunk in response:
     54         last_provider = get_last_provider(True) if last_provider is None else last_provider
     55         chunk.model = last_provider.get("model")

File c:\Users\admin\miniconda3\envs\gpt4free\Lib\site-packages\g4f\client\client.py:28, in iter_response(response, stream, response_format, max_tokens, stop)
     26 finish_reason = None
...
    522                                      extra=None, **kwargs):
    523     """Create subprocess transport."""
--> 524     raise NotImplementedError

NotImplementedError: 

Infinitay avatar May 03 '24 15:05 Infinitay

try this code and you can thank me later:

from g4f.client import Client as client_ai
from g4f.Provider import You
client = client_ai(provider=You)
response = client.chat.completions.create(
            model="gpt-4-turbo",
            messages=[{"role": "user", "content": 'hello how are you?'}],
                                    )
print(response.choices[0].message.content)

Keep in mind you should be downloaded the nodriver and if you have a probelm with generating image AI, feel free to ask me.

noneherel avatar May 04 '24 12:05 noneherel

Hey Infinitay, I noticed you're using a different event loop in your code. Just a heads up, Nodriver doesn't support that. You might see some warnings from curl_cffi, but don't worry about them.

hlohaus avatar May 04 '24 13:05 hlohaus

@noneherel

try this code and you can thank me later:

Thanks for your help. I tried it but it still didn't work. It turns out the issue was in fact using a different event loop as @hlohaus mentioned. I stopped attempting to use the You provider within a Jupyter Notebook and moved it into it's own Python file and I stopped getting the HAR file/nodriver issue. However now unfortunately I'm receiving Cloudflare 403 issues even on my own IP and not sending any requests to You after over 48 hours via g4f or manually via their website. I will try later as maybe my Cloudflare issue is due to accessing another site instead of You.

Infinitay avatar May 05 '24 15:05 Infinitay

@noneherel

try this code and you can thank me later:

Thanks for your help. I tried it but it still didn't work. It turns out the issue was in fact using a different event loop as @hlohaus mentioned. I stopped attempting to use the You provider within a Jupyter Notebook and moved it into it's own Python file and I stopped getting the HAR file/nodriver issue. However now unfortunately I'm receiving Cloudflare 403 issues even on my own IP and not sending any requests to You after over 48 hours via g4f or manually via their website. I will try later as maybe my Cloudflare issue is due to accessing another site instead of You.

Yo bro i've just got (Cloudflare detected) on onther IP i think i can help you i will give you a link to a specific version of Proton Vpn that might helps you (https://github.com/ProtonVPN/win-app/releases/download/2.4.1/ProtonVPN_win_v2.4.1.exe) i prefer this version because it helped me so much with changing my IP address and i hope it will help you as well, you can try it and then run your own code of YOU provider I'm sure a 100% it will help you. be sure to connect on Netherlands not japan because i tried it and i got ( Cloudflare detected error ) it helped me on my RDP and I thought it will be good to help another person with this. if you have any problem with downloading Proton Vpn version 2.4.1, feel free to ask me and you can ask me on instagram if you like (@noneherell) this is my IG i will answer you quickly. i didn't type all this for nothing but i've just got this problem, you are lucky because i've just found a solution hahahha.

noneherel avatar May 05 '24 22:05 noneherel

Hey, to get past that cloudflare detection, you can use curl_cffi. Just install it with "pip install curl_cffi" and you're good to go!

hlohaus avatar May 05 '24 23:05 hlohaus

Hey, to get past that cloudflare detection, you can use curl_cffi. Just install it with "pip install curl_cffi" and you're good to go!

I did this but i still get this error and i fixed it temporarily with use VPN

noneherel avatar May 06 '24 17:05 noneherel

Bumping this issue because it has been open for 7 days with no activity. Closing automatically in 7 days unless it becomes active again.

github-actions[bot] avatar May 14 '24 00:05 github-actions[bot]