Aura.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. from __future__ import annotations
  2. from aiohttp import ClientSession
  3. from ..typing import AsyncResult, Messages
  4. from .base_provider import AsyncGeneratorProvider
  5. class Aura(AsyncGeneratorProvider):
  6. url = "https://openchat.team"
  7. working = True
  8. @classmethod
  9. async def create_async_generator(
  10. cls,
  11. model: str,
  12. messages: Messages,
  13. proxy: str = None,
  14. **kwargs
  15. ) -> AsyncResult:
  16. headers = {
  17. "Accept": "*/*",
  18. "Accept-Encoding": "gzip, deflate, br",
  19. "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
  20. "Content-Type": "application/json",
  21. "Origin": f"{cls.url}",
  22. "Referer": f"{cls.url}/",
  23. "Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
  24. "Sec-Ch-Ua-Mobile": "?0",
  25. "Sec-Ch-Ua-Platform": '"Linux"',
  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/120.0.0.0 Safari/537.36",
  30. }
  31. async with ClientSession(headers=headers) as session:
  32. new_messages = []
  33. system_message = []
  34. for message in messages:
  35. if message["role"] == "system":
  36. system_message.append(message["content"])
  37. else:
  38. new_messages.append(message)
  39. data = {
  40. "model": {
  41. "id": "openchat_v3.2_mistral",
  42. "name": "OpenChat Aura",
  43. "maxLength": 24576,
  44. "tokenLimit": 8192
  45. },
  46. "messages": new_messages,
  47. "key": "",
  48. "prompt": "\n".join(system_message),
  49. "temperature": 0.5
  50. }
  51. async with session.post(f"{cls.url}/api/chat", json=data, proxy=proxy) as response:
  52. response.raise_for_status()
  53. async for chunk in response.content.iter_any():
  54. yield chunk.decode()