Editee.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. from __future__ import annotations
  2. from aiohttp import ClientSession
  3. from ..typing import AsyncResult, Messages
  4. from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
  5. from .helper import format_prompt
  6. class Editee(AsyncGeneratorProvider, ProviderModelMixin):
  7. label = "Editee"
  8. url = "https://editee.com"
  9. api_endpoint = "https://editee.com/submit/chatgptfree"
  10. working = True
  11. supports_gpt_4 = True
  12. supports_stream = True
  13. supports_system_message = True
  14. supports_message_history = True
  15. default_model = 'claude'
  16. models = ['claude', 'gpt4', 'gemini' 'mistrallarge']
  17. model_aliases = {
  18. "claude-3.5-sonnet": "claude",
  19. "gpt-4o": "gpt4",
  20. "gemini-pro": "gemini",
  21. "mistral-large": "mistrallarge",
  22. }
  23. @classmethod
  24. def get_model(cls, model: str) -> str:
  25. if model in cls.models:
  26. return model
  27. elif model in cls.model_aliases:
  28. return cls.model_aliases[model]
  29. else:
  30. return cls.default_model
  31. @classmethod
  32. async def create_async_generator(
  33. cls,
  34. model: str,
  35. messages: Messages,
  36. proxy: str = None,
  37. **kwargs
  38. ) -> AsyncResult:
  39. model = cls.get_model(model)
  40. headers = {
  41. "Accept": "application/json, text/plain, */*",
  42. "Accept-Language": "en-US,en;q=0.9",
  43. "Cache-Control": "no-cache",
  44. "Content-Type": "application/json",
  45. "Origin": cls.url,
  46. "Pragma": "no-cache",
  47. "Priority": "u=1, i",
  48. "Referer": f"{cls.url}/chat-gpt",
  49. "Sec-CH-UA": '"Chromium";v="129", "Not=A?Brand";v="8"',
  50. "Sec-CH-UA-Mobile": '?0',
  51. "Sec-CH-UA-Platform": '"Linux"',
  52. "Sec-Fetch-Dest": 'empty',
  53. "Sec-Fetch-Mode": 'cors',
  54. "Sec-Fetch-Site": 'same-origin',
  55. "User-Agent": 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36',
  56. "X-Requested-With": 'XMLHttpRequest',
  57. }
  58. async with ClientSession(headers=headers) as session:
  59. prompt = format_prompt(messages)
  60. data = {
  61. "user_input": prompt,
  62. "context": " ",
  63. "template_id": "",
  64. "selected_model": model
  65. }
  66. async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
  67. response.raise_for_status()
  68. response_data = await response.json()
  69. yield response_data['text']