Aura.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. 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. headers = {
  18. "Accept": "*/*",
  19. "Accept-Encoding": "gzip, deflate, br",
  20. "Accept-Language": "en-GB,en-US;q=0.9,en;q=0.8",
  21. "Content-Type": "application/json",
  22. "Origin": f"{cls.url}",
  23. "Referer": f"{cls.url}/",
  24. "Sec-Ch-Ua": '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
  25. "Sec-Ch-Ua-Mobile": "?0",
  26. "Sec-Ch-Ua-Platform": '"Linux"',
  27. "Sec-Fetch-Dest": "empty",
  28. "Sec-Fetch-Mode": "cors",
  29. "Sec-Fetch-Site": "same-origin",
  30. "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
  31. }
  32. async with ClientSession(headers=headers) as session:
  33. new_messages = []
  34. system_message = []
  35. for message in messages:
  36. if message["role"] == "system":
  37. system_message.append(message["content"])
  38. else:
  39. new_messages.append(message)
  40. data = {
  41. "model": {
  42. "id": "openchat_v3.2_mistral",
  43. "name": "OpenChat Aura",
  44. "maxLength": 24576,
  45. "tokenLimit": 8192
  46. },
  47. "messages": new_messages,
  48. "key": "",
  49. "prompt": "\n".join(system_message),
  50. "temperature": 0.5
  51. }
  52. async with session.post(f"{cls.url}/api/chat", json=data, proxy=proxy) as response:
  53. response.raise_for_status()
  54. async for chunk in response.content.iter_any():
  55. yield chunk.decode()