xtekky / gpt4free

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

Choosing a provider #1226

Closed toxa1818 closed 11 months ago

toxa1818 commented 1 year ago

Greetings! I'm trying to use a library to get a short description of the text of a news story that I get after scraping a news site. I use this short description for publication in the telegram channel. I'm using the following function:

import g4f

g4f.debug.logging = True

def get_summary(article, max_length=900, max_attempts=10):
    ignored_providers = [g4f.Provider.FreeGpt.__name__, g4f.Provider.FakeGpt.__name__, g4f.Provider.AiAsk.__name__, 
                                      g4f.Provider.GptChatly.__name__, g4f.Provider.Phind.__name__, g4f.Provider.NoowAi.__name__, 
                                      g4f.Provider.GptForLove.__name__, g4f.Provider.Aichat.__name__] 
    attempt = 0
    while attempt <= max_attempts:
        try:
            response = g4f.ChatCompletion.create(
                model="gpt-3.5-turbo-16k", 
                messages=[{"role": "user", "content": f"{article}\n Summarize this article in Ukrainian language. Sammary must meet the 
                                      following criteria:\n - Structure sammary as social media post, use emojies and make a list if needed.\n - The 
                                      max length of the summary must be no more than {max_length} characters and do not include links in the 
                                      summary."}], 
                ignored=ignored_providers
            )
            if len(response) <= max_length:
                return response
            else:
                raise ValueError(f"Summary length {len(response)} exceeds maximum length {max_length}.")
        except Exception as e:
            print(f"Error with provider: {e}")
            attempt += 1

    raise ValueError("Failed to generate summary after maximum attempts.")

When I run the use of this function in a loop for several news stories, the console shows the use of only two providers: You and GeekGpt. However, there are many more providers in total. And at each iteration, RetryProvider is used. Maybe this is the reason?

Can you also explain how to use cookies correctly in my case? So that I can use more providers...

xTimop commented 1 year ago

Most providers just don't work. For example, only FakeGPT, GeekGPT, and Phind work for me. What's the problem with using them?

toxa1818 commented 1 year ago

Most providers just don't work. For example, only FakeGPT, GeekGPT, and Phind work for me. What's the problem with using them?

With these providers I get the following errors: GeekGpt: HTTPError: 403 Client Error: Forbidden for url: https://ai.fakeopen.com/v1/chat/completio Phind: RuntimeError: HTTP Error 403:

ywgdjryf commented 1 year ago

Only FreeGPT, Hashnode work for me. With GeekGpt, Phind, I get the same errors.

github-actions[bot] commented 12 months 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 11 months ago

Closing due to inactivity.

thanhtoan1196 commented 11 months ago

any updates?