Skip to main content

SmartG4F

View on GitHub

A python package that selects g4f providers for you.

Use pip install smartg4f to install the package

Instead of supplying a provider, enter get_provider(). This function will validate each g4f provider and return a RetryProvider list

Synchronous client

Note: With the synchronous client, you cannot set a custom timeout!

import g4f
from smartg4f import get_provider

response = g4f.ChatCompletion.create(
    model=model,
    provider=get_provider(),
    messages=messages,
)
get_provider(
    prompt: String #Prompt that tests the providers (Default: "Say hello")
    validation: Function #Validation function (Default: returns True if the output is of type str)
    model: ModelType #(Default: gpt-4o)
    log: Boolean #Log providers
)

# Example usage
get_provider(
    prompt="How is the weather today?",
    model="gpt-4",
    log=False,
)

Asynchronous client

import g4f
from smartg4f import async_get_provider

response = g4f.ChatCompletion.create(
    model=model,
    provider=await async_get_provider(),
    messages=messages,
)
async_get_provider(
    prompt: String #Prompt that tests the providers (Default: "Say hello")
    validation: Function #Validation function (Default: returns True if the output is of type str)
    model: ModelType #(Default: gpt-4o)
    timeout: Integer #When a provider is too slow (Default: 15 seconds)
    log: Boolean #Log providers
)

# Example usage
await async_get_provider(
    prompt="How is the weather today?",
    model="gpt-4",
    timeout=5,
    log=False,
)

Troubleshooting

  1. Use await async_get_provider(*args) and get_provider(*args)
  2. If you use the await async_get_provider() method inside a function, you need async.
  3. If you use the await async_get_provider() method outside a function, you need asyncio.run().
  4. Make sure you have g4f installed

Metadata

Release files for smartg4f 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for smartg4f 1.2
File Size Uploaded Provenance Actions
smartg4f-1.2.tar.gz 2.9 kB Without provenance Details for smartg4f-1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for smartg4f 1.2
File Interpreter ABI Platform Actions
smartg4f-1.2-py3-none-any.whl Python 3 none any Details for smartg4f-1.2-py3-none-any.whl

Total release size: 5.9 kB

Release files / smartg4f-1.2.tar.gz

Download URL smartg4f-1.2.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b6ac459ad068204e972481bff12e7fcc325b1fb63505a8311e7e6f7a18daecd3
BLAKE2b-256 checksum
How to use checksums
c75214f16e5fb30b061ce1d55534d70f58453cfdad814a4a0cdc886084237362
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.0

Release files / smartg4f-1.2-py3-none-any.whl

Download URL smartg4f-1.2-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8a1b2ec9d5f1d96bac5831c02484e4d28267fa4f2dff51c532143142818f3e0a
BLAKE2b-256 checksum
How to use checksums
63c9b846d52334754d8909bf87addec75f35d5fed628ae55ff8262a6ee584316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.0

Security for smartg4f 1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page