summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/needs_auth/OpenRouter.py
blob: 5e0bf336d643bbf5c0e2cdcc07f1afad8ea14b7b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from __future__ import annotations

import requests

from .Openai import Openai
from ...typing import AsyncResult, Messages

class OpenRouter(Openai):
    label = "OpenRouter"
    url = "https://openrouter.ai"
    working = False
    default_model = "mistralai/mistral-7b-instruct:free"

    @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
        )