Skip to main content

Smart g4f provider selector

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

smartg4f-1.2.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

smartg4f-1.2-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file smartg4f-1.2.tar.gz.

File metadata

  • Download URL: smartg4f-1.2.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for smartg4f-1.2.tar.gz
Algorithm Hash digest
SHA256 b6ac459ad068204e972481bff12e7fcc325b1fb63505a8311e7e6f7a18daecd3
MD5 f63fa3d275e6112a8e24db5486c06e44
BLAKE2b-256 c75214f16e5fb30b061ce1d55534d70f58453cfdad814a4a0cdc886084237362

See more details on using hashes here.

File details

Details for the file smartg4f-1.2-py3-none-any.whl.

File metadata

  • Download URL: smartg4f-1.2-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.0

File hashes

Hashes for smartg4f-1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8a1b2ec9d5f1d96bac5831c02484e4d28267fa4f2dff51c532143142818f3e0a
MD5 71f567b3c544eb56c335d67924ad7975
BLAKE2b-256 63c9b846d52334754d8909bf87addec75f35d5fed628ae55ff8262a6ee584316

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page