Jmuz.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from __future__ import annotations
  2. from ..typing import AsyncResult, Messages
  3. from .template import OpenaiTemplate
  4. class Jmuz(OpenaiTemplate):
  5. url = "https://discord.gg/Ew6JzjA2NR"
  6. api_base = "https://jmuz.me/gpt/api/v2"
  7. api_key = "prod"
  8. working = True
  9. supports_system_message = False
  10. default_model = "gpt-4o"
  11. model_aliases = {
  12. "qwq-32b": "qwq-32b-preview",
  13. "gemini-1.5-flash": "gemini-flash",
  14. "gemini-1.5-pro": "gemini-pro",
  15. "gemini-2.0-flash-thinking": "gemini-thinking",
  16. "deepseek-chat": "deepseek-v3",
  17. }
  18. @classmethod
  19. def get_models(cls, **kwargs):
  20. if not cls.models:
  21. cls.models = super().get_models(api_key=cls.api_key, api_base=cls.api_base)
  22. return cls.models
  23. @classmethod
  24. async def create_async_generator(
  25. cls,
  26. model: str,
  27. messages: Messages,
  28. stream: bool = True,
  29. api_key: str = None, # Remove api_key from kwargs
  30. **kwargs
  31. ) -> AsyncResult:
  32. model = cls.get_model(model)
  33. headers = {
  34. "Authorization": f"Bearer {cls.api_key}",
  35. "Content-Type": "application/json",
  36. "accept": "*/*",
  37. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
  38. }
  39. started = False
  40. buffer = ""
  41. async for chunk in super().create_async_generator(
  42. model=model,
  43. messages=messages,
  44. api_base=cls.api_base,
  45. api_key=cls.api_key,
  46. stream=cls.supports_stream,
  47. headers=headers,
  48. **kwargs
  49. ):
  50. if isinstance(chunk, str):
  51. buffer += chunk
  52. if "Join for free".startswith(buffer) or buffer.startswith("Join for free"):
  53. if buffer.endswith("\n"):
  54. buffer = ""
  55. continue
  56. if "https://discord.gg/".startswith(buffer) or "https://discord.gg/" in buffer:
  57. if "..." in buffer:
  58. buffer = ""
  59. continue
  60. if "o1-preview".startswith(buffer) or buffer.startswith("o1-preview"):
  61. if "\n" in buffer:
  62. buffer = ""
  63. continue
  64. if not started:
  65. buffer = buffer.lstrip()
  66. if buffer:
  67. started = True
  68. yield buffer
  69. buffer = ""
  70. else:
  71. yield chunk