2023-10-15 23:49:30 +00:00
|
|
|
from g4f.Provider import __all__, ProviderUtils
|
|
|
|
from g4f import ChatCompletion
|
|
|
|
import concurrent.futures
|
|
|
|
|
|
|
|
_ = [
|
|
|
|
'BaseProvider',
|
|
|
|
'AsyncProvider',
|
|
|
|
'AsyncGeneratorProvider',
|
|
|
|
'RetryProvider'
|
|
|
|
]
|
|
|
|
|
|
|
|
def test_provider(provider):
|
2023-07-28 10:07:17 +00:00
|
|
|
try:
|
2023-10-15 23:49:30 +00:00
|
|
|
provider = (ProviderUtils.convert[provider])
|
|
|
|
if provider.working and not provider.needs_auth:
|
|
|
|
print('testing', provider.__name__)
|
|
|
|
completion = ChatCompletion.create(model='gpt-3.5-turbo',
|
|
|
|
messages=[{"role": "user", "content": "hello"}], provider=provider)
|
|
|
|
return completion, provider.__name__
|
2023-07-28 10:07:17 +00:00
|
|
|
except Exception as e:
|
2023-10-15 23:49:30 +00:00
|
|
|
#print(f'Failed to test provider: {provider} | {e}')
|
|
|
|
return None
|
|
|
|
|
|
|
|
with concurrent.futures.ThreadPoolExecutor() as executor:
|
2023-10-23 07:46:25 +00:00
|
|
|
futures = [
|
|
|
|
executor.submit(test_provider, provider)
|
|
|
|
for provider in __all__
|
|
|
|
if provider not in _
|
|
|
|
]
|
2023-10-15 23:49:30 +00:00
|
|
|
for future in concurrent.futures.as_completed(futures):
|
2023-10-23 07:46:25 +00:00
|
|
|
if result := future.result():
|
2023-10-15 23:49:30 +00:00
|
|
|
print(f'{result[1]} | {result[0]}')
|