From 7a699c8ca0c49a6e887e2e1debd0dcff23d696f9 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 9 Oct 2023 13:12:07 +0200 Subject: Readme: Create Provider with AI Tool --- README.md | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 927e5c93..0a4c9ab6 100644 --- a/README.md +++ b/README.md @@ -521,38 +521,50 @@ if __name__ == "__main__": ## Contribute -to add another provider, its very simple: +####Create Provider with AI Tool + +Call in your terminal the "create_provider" script: +```bash +$ python etc/tool/create_provider.py +``` +1. Enter your name for the new provider. +2. Copy&Paste cURL command from your browser developer tools. +3. Let the AI ​​create the provider for you. +4. Customize the provider according to your needs. + +####Create Provider 0. Check out the current [list of potential providers](https://github.com/zukixa/cool-ai-stuff#ai-chat-websites), or find your own provider source! 1. Create a new file in [g4f/provider](./g4f/provider) with the name of the Provider 2. Implement a class that extends [BaseProvider](./g4f/provider/base_provider.py). ```py -from .base_provider import BaseProvider -from ..typing import CreateResult, Any +from __future__ import annotations +from ..typing import AsyncResult, Messages +from .base_provider import AsyncGeneratorProvider -class HogeService(BaseProvider): - url = "http://hoge.com" - working = True +class HogeService(AsyncGeneratorProvider): + url = "https://chat-gpt.com" supports_gpt_35_turbo = True + working = True - @staticmethod - def create_completion( + @classmethod + async def create_async_generator( + cls, model: str, - messages: list[dict[str, str]], - stream: bool, - **kwargs: Any, - ) -> CreateResult: - pass + messages: Messages, + proxy: str = None, + **kwargs + ) -> AsyncResult: + yield "" ``` -3. Here, you can adjust the settings, for example if the website does support streaming, set `working` to `True`... -4. Write code to request the provider in `create_completion` and `yield` the response, _even if_ its a one-time response, do not hesitate to look at other providers for inspiration +3. Here, you can adjust the settings, for example if the website does support streaming, set `supports_stream` to `True`... +4. Write code to request the provider in `create_async_generator` and `yield` the response, _even if_ its a one-time response, do not hesitate to look at other providers for inspiration 5. Add the Provider Name in [g4f/provider/**init**.py](./g4f/provider/__init__.py) ```py -from .base_provider import BaseProvider from .HogeService import HogeService __all__ = [ -- cgit v1.2.3 From c6b33e527c9af9c72a615a7b23c8d40b5783862f Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Mon, 9 Oct 2023 13:33:20 +0200 Subject: Add Proxy Support and Create Provider to Readme Add proxy support to many providers --- README.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 0a4c9ab6..542f92fb 100644 --- a/README.md +++ b/README.md @@ -224,19 +224,15 @@ from g4f.Provider import ( Bing, ChatBase, ChatgptAi, - ChatgptLogin, - CodeLinkAva, DeepAi, H2o, HuggingChat, - Opchatgpts, OpenAssistant, OpenaiChat, Raycast, Theb, Vercel, Vitalentum, - Wewordle, Ylokh, You, Yqcloud, @@ -284,19 +280,18 @@ _providers = [ g4f.Provider.Aichat, 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): +async def run_provider(provider: g4f.Provider.BaseProvider): try: - response = await provider.create_async( - model=g4f.models.default.name, + response = await g4f.ChatCompletion.create_async( + model=g4f.models.default, messages=[{"role": "user", "content": "Hello"}], + provider=provider, ) print(f"{provider.__name__}:", response) except Exception as e: @@ -311,6 +306,22 @@ async def run_all(): asyncio.run(run_all()) ``` +##### Proxy Support: + +All providers support specifying a proxy in the create function. + +```py +import g4f + +response = await g4f.ChatCompletion.create( + model=g4f.models.default, + messages=[{"role": "user", "content": "Hello"}], + proxy="http://host:port", + # or socks5://user:pass@host:port +) +print(f"Result:", response) +``` + ### interference openai-proxy api (use with openai python package) #### run interference from pypi package: @@ -528,7 +539,7 @@ Call in your terminal the "create_provider" script: $ python etc/tool/create_provider.py ``` 1. Enter your name for the new provider. -2. Copy&Paste cURL command from your browser developer tools. +2. Copy&Paste a cURL command from your browser developer tools. 3. Let the AI ​​create the provider for you. 4. Customize the provider according to your needs. -- cgit v1.2.3 From b8febf67e324ada0e8ea7a15ec59ef47c3097803 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:49:45 +0100 Subject: ~ | g4f `v-0.1.5.7` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 542f92fb..4e16a063 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ By using this repository or any code related to it, you agree to the [legal notice](./LEGAL_NOTICE.md). The author is not responsible for any copies, forks, reuploads made by other users, or anything else related to gpt4free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses. -- latest pypi version: ([0.1.5.6](https://pypi.org/project/g4f/0.1.5.6)): +- latest pypi version: `[0.1.5.7](https://pypi.org/project/g4f/0.1.5.7)``: ```sh pip install -U g4f ``` -- cgit v1.2.3 From 6135f4ac08508f902cc417ef1e9d11b299ab5fd9 Mon Sep 17 00:00:00 2001 From: abc <98614666+xtekky@users.noreply.github.com> Date: Mon, 9 Oct 2023 23:51:47 +0100 Subject: ~ | g4f `v-0.1.5.7` --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4e16a063..691c5857 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ By using this repository or any code related to it, you agree to the [legal notice](./LEGAL_NOTICE.md). The author is not responsible for any copies, forks, reuploads made by other users, or anything else related to gpt4free. This is the author's only account and repository. To prevent impersonation or irresponsible actions, please comply with the GNU GPL license this Repository uses. -- latest pypi version: `[0.1.5.7](https://pypi.org/project/g4f/0.1.5.7)``: +- latest pypi version: `[0.1.5.7](https://pypi.org/project/g4f/0.1.5.7)`: ```sh pip install -U g4f ``` -- cgit v1.2.3