GptTalkRu.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from __future__ import annotations
  2. from aiohttp import ClientSession
  3. from ..typing import AsyncResult, Messages
  4. from .base_provider import AsyncGeneratorProvider
  5. class GptTalkRu(AsyncGeneratorProvider):
  6. url = "https://gpttalk.ru"
  7. working = True
  8. supports_gpt_35_turbo = True
  9. @classmethod
  10. async def create_async_generator(
  11. cls,
  12. model: str,
  13. messages: Messages,
  14. proxy: str = None,
  15. **kwargs
  16. ) -> AsyncResult:
  17. if not model:
  18. model = "gpt-3.5-turbo"
  19. headers = {
  20. "Accept": "application/json, text/plain, */*",
  21. "Accept-Language": "en-US",
  22. "Connection": "keep-alive",
  23. "Content-Type": "application/json",
  24. "Origin": "https://gpttalk.ru",
  25. "Referer": "https://gpttalk.ru/",
  26. "Sec-Fetch-Dest": "empty",
  27. "Sec-Fetch-Mode": "cors",
  28. "Sec-Fetch-Site": "same-origin",
  29. "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36",
  30. "sec-ch-ua": '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
  31. "sec-ch-ua-mobile": "?0",
  32. "sec-ch-ua-platform": '"Linux"',
  33. }
  34. async with ClientSession(headers=headers) as session:
  35. data = {
  36. "model": model,
  37. "modelType": 1,
  38. "prompt": messages,
  39. "responseType": "stream",
  40. }
  41. async with session.post(f"{cls.url}/gpt2", json=data, proxy=proxy) as response:
  42. response.raise_for_status()
  43. async for chunk in response.content.iter_any():
  44. yield chunk.decode()