xtekky / gpt4free

The official gpt4free repository | various collection of powerful language models
https://g4f.ai
GNU General Public License v3.0
59.41k stars 13.2k forks source link

OpenaiChat with .har not working #2081

Closed krishnavalliappan closed 1 week ago

krishnavalliappan commented 4 weeks ago

code:

from g4f.client import Client
import os.path
from g4f.cookies import set_cookies_dir, read_cookie_files
from g4f.Provider import (OpenaiChat)

import g4f.debug
g4f.debug.logging = True
cookies_dir = os.path.join(os.path.dirname(__file__), "har_and_cookies")
set_cookies_dir(cookies_dir)
read_cookie_files(cookies_dir)

client = Client(provider=OpenaiChat)
response = client.chat.completions.create(
    model=g4f.models.gpt_4,
    messages=[{"role": "user", "content": "Hello"}],
)
print(response.choices[0].message.content)

error:

Read .har file: /Users/krishnakumarvalliappan/Coding/resume_builder_gpt/har_and_cookies/chatgpt.har Using OpenaiChat provider and gpt-4 model Traceback (most recent call last): File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/test.py", line 13, in response = client.chat.completions.create( File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/client/client.py", line 118, in create return response if stream else next(response) File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/client/client.py", line 57, in iter_append_model_and_provider for chunk in response: File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/client/client.py", line 29, in iter_response for idx, chunk in enumerate(response): File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/providers/base_provider.py", line 223, in create_completion yield loop.run_until_complete(await_callback(gen.anext)) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete return future.result() File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/providers/base_provider.py", line 52, in await_callback return await callback() File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 379, in create_async_generator cls.default_model = cls.get_model(await cls.get_default_model(session, cls._headers)) File "/Users/krishnakumarvalliappan/Coding/resume_builder_gpt/.venv/lib/python3.10/site-packages/g4f/Provider/needs_auth/OpenaiChat.py", line 199, in get_default_model raise MissingAuthError('Add a "api_key" or a .har file' if cls._api_key is None else "Invalid api key") g4f.errors.MissingAuthError: Add a "api_key" or a .har file

ozipoetra commented 3 weeks ago

I also still got this error on OpenaiChat even after they merge this commit https://github.com/xtekky/gpt4free/pull/2054

kloklojul commented 3 weeks ago

yup and when using only the api key you instantly run into cloudflare

github-actions[bot] commented 2 weeks ago

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] commented 1 week ago

Closing due to inactivity.