Acytoo.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. from __future__ import annotations
  2. from aiohttp import ClientSession
  3. from ...typing import AsyncResult, Messages
  4. from ..base_provider import AsyncGeneratorProvider
  5. class Acytoo(AsyncGeneratorProvider):
  6. url = 'https://chat.acytoo.com'
  7. working = False
  8. supports_message_history = True
  9. supports_gpt_35_turbo = True
  10. @classmethod
  11. async def create_async_generator(
  12. cls,
  13. model: str,
  14. messages: Messages,
  15. proxy: str = None,
  16. **kwargs
  17. ) -> AsyncResult:
  18. async with ClientSession(
  19. headers=_create_header()
  20. ) as session:
  21. async with session.post(
  22. f'{cls.url}/api/completions',
  23. proxy=proxy,
  24. json=_create_payload(messages, **kwargs)
  25. ) as response:
  26. response.raise_for_status()
  27. async for stream in response.content.iter_any():
  28. if stream:
  29. yield stream.decode()
  30. def _create_header():
  31. return {
  32. 'accept': '*/*',
  33. 'content-type': 'application/json',
  34. }
  35. def _create_payload(messages: Messages, temperature: float = 0.5, **kwargs):
  36. return {
  37. 'key' : '',
  38. 'model' : 'gpt-3.5-turbo',
  39. 'messages' : messages,
  40. 'temperature' : temperature,
  41. 'password' : ''
  42. }