Mhystical.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import annotations
  2. from ..typing import AsyncResult, Messages
  3. from .needs_auth.OpenaiAPI import OpenaiAPI
  4. """
  5. Mhystical.cc
  6. ~~~~~~~~~~~~
  7. Author: NoelP.dev
  8. Last Updated: 2024-05-11
  9. Author Site: https://noelp.dev
  10. Provider Site: https://mhystical.cc
  11. """
  12. class Mhystical(OpenaiAPI):
  13. label = "Mhystical"
  14. url = "https://mhystical.cc"
  15. api_endpoint = "https://api.mhystical.cc/v1/completions"
  16. login_url = "https://mhystical.cc/dashboard"
  17. working = True
  18. needs_auth = False
  19. supports_stream = False # Set to False, as streaming is not specified in ChatifyAI
  20. supports_system_message = False
  21. default_model = 'gpt-4'
  22. models = [default_model]
  23. @classmethod
  24. def get_model(cls, model: str, **kwargs) -> str:
  25. cls.last_model = cls.default_model
  26. return cls.default_model
  27. @classmethod
  28. def create_async_generator(
  29. cls,
  30. model: str,
  31. messages: Messages,
  32. stream: bool = False,
  33. api_key: str = "mhystical",
  34. **kwargs
  35. ) -> AsyncResult:
  36. model = cls.get_model(model)
  37. headers = {
  38. "x-api-key": api_key,
  39. "Content-Type": "application/json",
  40. "accept": "*/*",
  41. "cache-control": "no-cache",
  42. "origin": cls.url,
  43. "referer": f"{cls.url}/",
  44. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
  45. }
  46. return super().create_async_generator(
  47. model=model,
  48. messages=messages,
  49. stream=cls.supports_stream,
  50. api_endpoint=cls.api_endpoint,
  51. headers=headers,
  52. **kwargs
  53. )