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

Fix: debug.logging not work in retry provider #1098

Merged
merged 1 commit into from
Oct 19, 2023

Conversation

Lin-jun-xiang
Copy link
Contributor

@Lin-jun-xiang Lin-jun-xiang commented Oct 19, 2023

When using RetryProvider, we want to identify the specific Provider being used (according to #1094 requirements).

According to the source code, I noticed that g4f.logging is likely intended for this purpose, facilitating better debugging for developers (please correct me if I'm wrong).

However, the logging attribute in retry_provider.py does not change along with g4f.logging = True. (always be False)

if logging:
print(f"Using {provider.__name__} provider")

Therefore, in this case, I have defined logging as a class variable in RetryProvider.

Example

import g4f

g4f.logging = True

print(
    g4f.ChatCompletion.create(
            model='gpt-3.5-turbo',
            messages=[{"role": "user", "content": "hello"}],
    )
)

Results

Using RetryProvider provider
Using ChatgptAi provider
Using AItianhuSpace provider
AItianhuSpace: RuntimeError: g4f.provider.AItianhuSpace requires cookies
Using GptGo provider
Hello! How can I assist you today?

Noted: I'm not sure if this modification is the optimal solution. If there is a better way, I welcome assistance.

@xtekky
Copy link
Owner

xtekky commented Oct 19, 2023

Yes, I noticed that, you found a great solution !!

@xtekky xtekky merged commit 4c72acc into xtekky:main Oct 19, 2023
@nitsik
Copy link

nitsik commented Oct 27, 2023

Hello. I always see "Using RetryProvider provider" when I use "g4f.logging = True". I not see "Using ChatgptAi provider" and others. Why? What its means? Is RetryProvider it single rpovider? Why I not see other providers? Thank you.

@Lin-jun-xiang
Copy link
Contributor Author

@nitsik

Use g4f.debug.logging=True instead of g4f.logging=True.

@nitsik
Copy link

nitsik commented Oct 27, 2023

@nitsik

Use g4f.debug.logging=True instead of g4f.logging=True.

When I use "g4f.debug.logging=True" I not see, what kind of provider I use.

@Lin-jun-xiang
Copy link
Contributor Author

@nitsik

Make sure you have used new version g4f: pip install -U g4f

If you still not see the provider, could you show your code for me ? Thanks to u!

The following is my test:

import g4f

g4f.debug.logging = True

print(
    g4f.ChatCompletion.create(
            model='gpt-3.5-turbo',
            messages=[{"role": "user", "content": "hello"}],
            # ignored=["Ylokh", "GptGo", "AItianhu", "Aibn", "Myshell", "FreeGpt"],
        )
)
Using RetryProvider provider
Using ChatBase provider
Hello! How can I assist you today?

@nitsik
Copy link

nitsik commented Oct 27, 2023

I am use docker. How can I update? How to view version g4f?

@nitsik

Make sure you have used new version g4f: pip install -U g4f

If you still not see the provider, could you show your code for me ? Thanks to u!

The following is my test:

import g4f

g4f.debug.logging = True

print(
    g4f.ChatCompletion.create(
            model='gpt-3.5-turbo',
            messages=[{"role": "user", "content": "hello"}],
            # ignored=["Ylokh", "GptGo", "AItianhu", "Aibn", "Myshell", "FreeGpt"],
        )
)
Using RetryProvider provider
Using ChatBase provider
Hello! How can I assist you today?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants