返回提交历史
Added
g4f_api/ApiInterface.py
+12
-0
Added
g4f_api/__init__.py
+0
-0
Added
g4f_api/__main__.py
+23
-0
XFEstudio/gpt4free
Added code to ignore certain providers in the API
ecad7a4a
代码差异
3 个文件
+35
-0
@@ -0,0 +1,12 @@
1
import g4f
2
from g4f.api import Api
3
4
create_chat_completion_original = g4f.ChatCompletion.create
5
list_ignored_providers=[]
6
7
def create_chat_completion(*args, **kwargs):
8
kwargs['ignored']=list_ignored_providers
9
return create_chat_completion_original(*args, **kwargs)
10
11
g4f.ChatCompletion.create=create_chat_completion
12
api=Api(g4f, debug=False)
此文件没有可显示的逐行差异。
@@ -0,0 +1,23 @@
1
import typing
2
from enum import Enum
3
from g4f import Provider
4
from g4f_api import ApiInterface
5
import typer
6
7
IgnoredProviders = Enum("ignore_providers", {key:key for key in Provider.__all__})
8
9
app = typer.Typer(help="Run the G4F API")
10
11
@app.command()
12
def main(
13
bind_str: str = typer.Argument(..., envvar="G4F_API_BIND_STR", help="The bind string."),
14
i_num_threads: int = typer.Option(1, envvar="G4F_API_NUM_THREADS", help="The number of threads."),
15
list_ignored_providers: typing.List[IgnoredProviders] = typer.Option([], envvar="G4F_API_LIST_IGNORED_PROVIDERS", help="List of providers to ignore when processing request."),
16
):
17
list_ignored_providers=[provider.name for provider in list_ignored_providers]
18
ApiInterface.list_ignored_providers=list_ignored_providers
19
ApiInterface.api.run(bind_str, i_num_threads)
20
21
22
if __name__ == "__main__":
23
app()