Create Provider with AI Tool Call in your terminal the createprovider script:…
- User
User: Create Provider with AI Tool Call in your terminal the create_provider script:
python -m etc.tool.create_provider Enter your name for the new provider. Copy and paste the cURL command from your browser developer tools. Let the AI create the provider for you. Customize the provider according to your needs. Create Provider Check out the current list of potential providers, or find your own provider source! Create a new file in g4f/Provider with the name of the Provider. 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
code@classmethod async def create_async_generator( cls, model: str, messages: Messages, proxy: str = None, **kwargs ) -> AsyncResult: yield ""Here, you can adjust the settings, for example, if the website does support streaming, set supports_stream to True... 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. Add the Provider Import in g4f/Provider/init.py from .HogeService import HogeService
all = [ HogeService, ] 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='')
啥意思 Assistant: This guide describes how to create a new provider for a given AI tool, specifically for a framework or system that uses a plugin architecture to extend functionality with new service providers. Here's a breakdown of the steps involved:
-
Launch Script: You begin by executing a command in your terminal to start creating a provider. This involves invoking a specific Python module,
etc.tool.create_provider. -
Name the Provider: You'll be prompted to enter a name for your new provider. This could be the name of a service or API that offers AI functionality.
-
Capture cURL Command: You need to copy a cURL command from your browser's developer tools. This is typically done by making a request to the service you want to create a provider for, and capturing the network request in the browser.
-
- Assistant
这份指南描述了如何为一个特定的AI工具创建新的服务提供者,特别是对于使用插件架构来扩展功能的新服务提供者。以下是主要步骤的分解:
-
启动脚本:首先,你需要在终端中执行一个命令来开始创建提供者。这涉及调用一个特定的Python模块
etc.tool.create_provider。 -
命名提供者:系统会提示你为新提供者输入一个名称。这可以是提供AI功能的服务或API的名称。
-
捕获cURL命令:你需要从浏览器的开发者工具中复制一个cURL命令。通常你需要对想要创建提供者的服务发出请求,并在浏览器中捕获网络请求。
-
自动创建:这个AI工具会使用从cURL命令中获取的信息来协助你设置提供者。
-
自定义提供者:你可以根据需要调整提供者的设置,例如,如果网站支持流式处理,可以将
supports_stream设置为True。 -
实现逻辑:在创建一个表示提供者的类时,它必须继承自
BaseProvider。你需要编写代码来发送请求,并在create_async_generator方法中返回响应。 -
添加导入:在
g4f/Provider/__init__.py文件中,添加你新创建的提供者以便其他地方可以使用它。 -
测试提供者:最后,通过调用提供者来测试它的功能,确保它能正常地响应请求。
这就是如何在该系统中集成一个新的AI服务提供者的基本流程。
-