-
-
Notifications
You must be signed in to change notification settings - Fork 13.6k
/
Copy pathJmuz.py
77 lines (71 loc) · 2.56 KB
/
Jmuz.py
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
68
69
70
71
72
73
74
75
76
77
from __future__ import annotations
from ..typing import AsyncResult, Messages
from .template import OpenaiTemplate
class Jmuz(OpenaiTemplate):
url = "https://discord.gg/Ew6JzjA2NR"
api_base = "https://jmuz.me/gpt/api/v2"
api_key = "prod"
working = True
supports_system_message = False
default_model = "gpt-4o"
model_aliases = {
"qwq-32b": "qwq-32b-preview",
"gemini-1.5-flash": "gemini-flash",
"gemini-1.5-pro": "gemini-pro",
"gemini-2.0-flash-thinking": "gemini-thinking",
"deepseek-chat": "deepseek-v3",
}
@classmethod
def get_models(cls, **kwargs):
if not cls.models:
cls.models = super().get_models(api_key=cls.api_key, api_base=cls.api_base)
return cls.models
@classmethod
async def create_async_generator(
cls,
model: str,
messages: Messages,
stream: bool = True,
api_key: str = None, # Remove api_key from kwargs
**kwargs
) -> AsyncResult:
model = cls.get_model(model)
headers = {
"Authorization": f"Bearer {cls.api_key}",
"Content-Type": "application/json",
"accept": "*/*",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
}
started = False
buffer = ""
async for chunk in super().create_async_generator(
model=model,
messages=messages,
api_base=cls.api_base,
api_key=cls.api_key,
stream=cls.supports_stream,
headers=headers,
**kwargs
):
if isinstance(chunk, str):
buffer += chunk
if "Join for free".startswith(buffer) or buffer.startswith("Join for free"):
if buffer.endswith("\n"):
buffer = ""
continue
if "https://discord.gg/".startswith(buffer) or "https://discord.gg/" in buffer:
if "..." in buffer:
buffer = ""
continue
if "o1-preview".startswith(buffer) or buffer.startswith("o1-preview"):
if "\n" in buffer:
buffer = ""
continue
if not started:
buffer = buffer.lstrip()
if buffer:
started = True
yield buffer
buffer = ""
else:
yield chunk