summaryrefslogtreecommitdiffstats
path: root/README.md
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-09-22 21:40:59 +0200
committerGitHub <noreply@github.com>2023-09-22 21:40:59 +0200
commitba287e89b55118965ff0e151e54636b1f50d3b38 (patch)
treedc69218fecae4971c90ae391ff6919c032b93540 /README.md
parent~ | gpt-3.5-turbo-0613 (diff)
parentAdd RetryProvider (diff)
downloadgpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.gz
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.bz2
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.lz
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.xz
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.tar.zst
gpt4free-ba287e89b55118965ff0e151e54636b1f50d3b38.zip
Diffstat (limited to 'README.md')
-rw-r--r--README.md65
1 files changed, 32 insertions, 33 deletions
diff --git a/README.md b/README.md
index 763417ba..ed8dc577 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)