summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner@lohaus.eu>2023-09-20 06:12:34 +0200
committerHeiner Lohaus <heiner@lohaus.eu>2023-09-20 06:12:34 +0200
commit82bd6f91808a383781807262c4ae1f3de9740531 (patch)
tree9a12306a3dda5e883bc21e13b2f50294892a2fc9 /README.md
parent~ | Merge pull request #914 from hlohaus/lesh (diff)
downloadgpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.gz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.bz2
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.lz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.xz
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.tar.zst
gpt4free-82bd6f91808a383781807262c4ae1f3de9740531.zip
Diffstat (limited to '')
-rw-r--r--README.md65
1 files changed, 32 insertions, 33 deletions
diff --git a/README.md b/README.md
index bf15f3a6..dc148e7d 100644
--- a/README.md
+++ b/README.md
@@ -238,43 +238,42 @@ response = g4f.ChatCompletion.create(
##### Async Support:
-To enhance speed and overall performance, execute providers asynchronously. The total execution time will be determined by the duration of the slowest provider's execution.
+To enhance speed and overall performance, execute providers asynchronously.
+The total execution time will be determined by the duration of the slowest provider's execution.
```py
import g4f, asyncio
-async def run_async():
- _providers = [
- g4f.Provider.AItianhu,
- g4f.Provider.Acytoo,
- g4f.Provider.Aichat,
- g4f.Provider.Ails,
- g4f.Provider.Aivvm,
- g4f.Provider.ChatBase,
- g4f.Provider.ChatgptAi,
- g4f.Provider.ChatgptLogin,
- g4f.Provider.CodeLinkAva,
- g4f.Provider.DeepAi,
- g4f.Provider.Opchatgpts,
- g4f.Provider.Vercel,
- g4f.Provider.Vitalentum,
- g4f.Provider.Wewordle,
- g4f.Provider.Ylokh,
- g4f.Provider.You,
- g4f.Provider.Yqcloud,
- ]
- responses = [
- provider.create_async(
- model=g4f.models.default,
- messages=[{"role": "user", "content": "Hello"}],
- )
- for provider in _providers
- ]
- responses = await asyncio.gather(*responses)
- for idx, provider in enumerate(_providers):
- print(f"{provider.__name__}:", responses[idx])
-
-asyncio.run(run_async())
+_providers = [
+ g4f.Provider.Aichat,
+ g4f.Provider.Aivvm,
+ g4f.Provider.ChatBase,
+ g4f.Provider.Bing,
+ g4f.Provider.CodeLinkAva,
+ g4f.Provider.DeepAi,
+ g4f.Provider.GptGo,
+ g4f.Provider.Wewordle,
+ g4f.Provider.You,
+ g4f.Provider.Yqcloud,
+]
+
+async def run_provider(provider: g4f.Provider.AsyncProvider):
+ try:
+ response = await provider.create_async(
+ model=g4f.models.default.name,
+ messages=[{"role": "user", "content": "Hello"}],
+ )
+ print(f"{provider.__name__}:", response)
+ except Exception as e:
+ print(f"{provider.__name__}:", e)
+
+async def run_all():
+ calls = [
+ run_provider(provider) for provider in _providers
+ ]
+ await asyncio.gather(*calls)
+
+asyncio.run(run_all())
```
### interference openai-proxy api (use with openai python package)