summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrazrab <razrab@PimoLin>2023-10-22 11:45:18 +0200
committerrazrab <razrab@PimoLin>2023-10-22 11:45:18 +0200
commitecad7a4ac8e0493efbb09be26e73b0d747d49e0f (patch)
treef359bc9eed97b048e9923d47d5059b71ba1931b5
parent~ | Merge pull request #1112 from lategege/main (diff)
downloadgpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar.gz
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar.bz2
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar.lz
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar.xz
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.tar.zst
gpt4free-ecad7a4ac8e0493efbb09be26e73b0d747d49e0f.zip
Diffstat (limited to '')
-rw-r--r--g4f_api/ApiInterface.py12
-rw-r--r--g4f_api/__init__.py0
-rw-r--r--g4f_api/__main__.py23
3 files changed, 35 insertions, 0 deletions
diff --git a/g4f_api/ApiInterface.py b/g4f_api/ApiInterface.py
new file mode 100644
index 00000000..f6572912
--- /dev/null
+++ b/g4f_api/ApiInterface.py
@@ -0,0 +1,12 @@
+import g4f
+from g4f.api import Api
+
+create_chat_completion_original = g4f.ChatCompletion.create
+list_ignored_providers=[]
+
+def create_chat_completion(*args, **kwargs):
+ kwargs['ignored']=list_ignored_providers
+ return create_chat_completion_original(*args, **kwargs)
+
+g4f.ChatCompletion.create=create_chat_completion
+api=Api(g4f, debug=False)
diff --git a/g4f_api/__init__.py b/g4f_api/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/g4f_api/__init__.py
diff --git a/g4f_api/__main__.py b/g4f_api/__main__.py
new file mode 100644
index 00000000..58267686
--- /dev/null
+++ b/g4f_api/__main__.py
@@ -0,0 +1,23 @@
+import typing
+from enum import Enum
+from g4f import Provider
+from g4f_api import ApiInterface
+import typer
+
+IgnoredProviders = Enum("ignore_providers", {key:key for key in Provider.__all__})
+
+app = typer.Typer(help="Run the G4F API")
+
+@app.command()
+def main(
+ bind_str: str = typer.Argument(..., envvar="G4F_API_BIND_STR", help="The bind string."),
+ i_num_threads: int = typer.Option(1, envvar="G4F_API_NUM_THREADS", help="The number of threads."),
+ list_ignored_providers: typing.List[IgnoredProviders] = typer.Option([], envvar="G4F_API_LIST_IGNORED_PROVIDERS", help="List of providers to ignore when processing request."),
+):
+ list_ignored_providers=[provider.name for provider in list_ignored_providers]
+ ApiInterface.list_ignored_providers=list_ignored_providers
+ ApiInterface.api.run(bind_str, i_num_threads)
+
+
+if __name__ == "__main__":
+ app() \ No newline at end of file