summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/V50.py
blob: 7b873979862241c4a1edca3a2004c2e0b72d17a7 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import annotations

import uuid

import requests

from ..typing import Any, CreateResult
from .base_provider import BaseProvider


class V50(BaseProvider):
    url                     = 'https://p5.v50.ltd'
    supports_gpt_35_turbo   = True
    supports_stream         = False
    needs_auth              = False
    working                 = False

    @staticmethod
    def create_completion(
        model: str,
        messages: list[dict[str, str]],
        stream: bool, **kwargs: Any) -> CreateResult:
        
        conversation = "\n".join(f"{message['role']}: {message['content']}" for message in messages)
        conversation += "\nassistant: "

        payload = {
            "prompt"        : conversation,
            "options"       : {},
            "systemMessage" : ".",
            "temperature"   : kwargs.get("temperature", 0.4),
            "top_p"         : kwargs.get("top_p", 0.4),
            "model"         : model,
            "user"          : str(uuid.uuid4())
        }
        
        headers = {
            'authority'         : 'p5.v50.ltd',
            'accept'            : 'application/json, text/plain, */*',
            'accept-language'   : 'id-ID,id;q=0.9,en-US;q=0.8,en;q=0.7',
            'content-type'      : 'application/json',
            'origin'            : 'https://p5.v50.ltd',
            'referer'           : 'https://p5.v50.ltd/',
            'sec-ch-ua-platform': '"Windows"',
            'sec-fetch-dest'    : 'empty',
            'sec-fetch-mode'    : 'cors',
            'sec-fetch-site'    : 'same-origin',
            'user-agent'        : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
        }
        response = requests.post("https://p5.v50.ltd/api/chat-process", 
                                json=payload, headers=headers, proxies=kwargs['proxy'] if 'proxy' in kwargs else {})
        
        if "https://fk1.v50.ltd" not in response.text:
            yield response.text

    @classmethod
    @property
    def params(cls):
        params = [
            ("model", "str"),
            ("messages", "list[dict[str, str]]"),
            ("stream", "bool"),
            ("temperature", "float"),
            ("top_p", "int"),
        ]
        param = ", ".join([": ".join(p) for p in params])
        return f"g4f.Provider.{cls.__name__} supports: ({param})"