summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/needs_auth/OpenRouter.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-04-10 08:14:50 +0200
committerGitHub <noreply@github.com>2024-04-10 08:14:50 +0200
commit00951eb79114adf74ad1a3f1ce596e9e0fa932bf (patch)
treefea75e7745d69b09d91b0003e5dbf12b77380223 /g4f/Provider/needs_auth/OpenRouter.py
parentUpdate Dockerfile (diff)
downloadgpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar.gz
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar.bz2
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar.lz
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar.xz
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.tar.zst
gpt4free-00951eb79114adf74ad1a3f1ce596e9e0fa932bf.zip
Diffstat (limited to 'g4f/Provider/needs_auth/OpenRouter.py')
-rw-r--r--g4f/Provider/needs_auth/OpenRouter.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/g4f/Provider/needs_auth/OpenRouter.py b/g4f/Provider/needs_auth/OpenRouter.py
new file mode 100644
index 00000000..e5f87076
--- /dev/null
+++ b/g4f/Provider/needs_auth/OpenRouter.py
@@ -0,0 +1,31 @@
+from __future__ import annotations
+
+import requests
+
+from .Openai import Openai
+from ...typing import AsyncResult, Messages
+
+class OpenRouter(Openai):
+ url = "https://openrouter.ai"
+ working = True
+ default_model = "openrouter/auto"
+
+ @classmethod
+ def get_models(cls):
+ if not cls.models:
+ url = 'https://openrouter.ai/api/v1/models'
+ models = requests.get(url).json()["data"]
+ cls.models = [model['id'] for model in models]
+ return cls.models
+
+ @classmethod
+ def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ api_base: str = "https://openrouter.ai/api/v1",
+ **kwargs
+ ) -> AsyncResult:
+ return super().create_async_generator(
+ model, messages, api_base=api_base, **kwargs
+ ) \ No newline at end of file