import g4f
g4f.debug.logging = False # enable logging
g4f.check_version = False # Disable automatic version checking
print(g4f.version) # check version
print(g4f.Provider.Ails.params) # supported args
# Automatic selection of provider
# streamed completion
response = g4f.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello"}],
stream=True,
)
for message in response:
print(message, flush=True, end="")
# normal response
response = g4f.ChatCompletion.create(
model=g4f.models.gpt_4,
messages=[{"role": "user", "content": "Hello"}],
) # alternative model setting
print(response)
<module 'g4f.version' from 'C:\\Users\\Rodion\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python311\\site-packages\\g4f\\version.py'>
g4f.Provider.Ails supports: (
model: str
messages: Messages
stream: bool
proxy: str = None
)
Hello! How can I assist you today?Traceback (most recent call last):
File "e:\Code\VSCode\PYTHON\test.py", line 21, in <module>
response = g4f.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rodion\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\g4f\__init__.py", line 146, in create
return result if stream else ''.join([str(chunk) for chunk in result])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rodion\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\g4f\__init__.py", line 146, in <listcomp>
return result if stream else ''.join([str(chunk) for chunk in result])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Rodion\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\g4f\providers\retry_provider.py", line 81, in create_completion
raise_exceptions(exceptions)
File "C:\Users\Rodion\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.11_qbz5n2kfra8p0\LocalCache\local-packages\Python311\site-packages\g4f\providers\retry_provider.py", line 201, in raise_exceptions
raise RetryProviderError("RetryProvider failed:\n" + "\n".join([
g4f.errors.RetryProviderError: RetryProvider failed:
Liaobots: ClientResponseError: 401, message='Unauthorized', url=URL('https://liaobots.work/api/user')
Bing: RuntimeError: Response:
provider=g4f.Provider.You
, смотреть активные провайдеры здесь.import g4f
response = g4f.ChatCompletion.create(
model=g4f.models.gpt_4,
messages=[{"role": "user", "content": "Hello"}],
provider=g4f.Provider.You,
stream=True,
)
for message in response:
print(message, flush=True, end="")
from g4f.client import Client
client = Client(
api_key="...",
...
)