1 Star 0 Fork 104

zheng19891127 / gpt4free

forked from Gitee 极速下载 / gpt4free 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
create_provider.md 1.99 KB
一键复制 编辑 原始数据 按行查看 历史
Heiner Lohaus 提交于 2024-02-24 01:31 . Add help me coding guide

Create Provider with AI Tool

Call in your terminal the create_provider script:

python -m etc.tool.create_provider
  1. Enter your name for the new provider.
  2. Copy and paste the 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

  1. Check out the current list of potential providers, or find your own provider source!
  2. Create a new file in g4f/Provider with the name of the Provider
  3. Implement a class that extends BaseProvider.
from __future__ import annotations

from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider

class HogeService(AsyncGeneratorProvider):
    url                   = "https://chat-gpt.com"
    working               = True
    supports_gpt_35_turbo = True

    @classmethod
    async def create_async_generator(
        cls,
        model: str,
        messages: Messages,
        proxy: str = None,
        **kwargs
    ) -> AsyncResult:
        yield ""
  1. Here, you can adjust the settings, for example, if the website does support streaming, set supports_stream to True...
  2. Write code to request the provider in create_async_generator and yield the response, even if it's a one-time response, do not hesitate to look at other providers for inspiration
  3. Add the Provider Import in g4f/Provider/__init__.py
from .HogeService import HogeService

__all__ = [
  HogeService,
]
  1. You are done !, test the provider by calling it:
import g4f

response = g4f.ChatCompletion.create(model='gpt-3.5-turbo', provider=g4f.Provider.PROVIDERNAME,
                                    messages=[{"role": "user", "content": "test"}], stream=g4f.Provider.PROVIDERNAME.supports_stream)

for message in response:
    print(message, flush=True, end='')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zheng19891127/gpt4free.git
git@gitee.com:zheng19891127/gpt4free.git
zheng19891127
gpt4free
gpt4free
main

搜索帮助

344bd9b3 5694891 D2dac590 5694891