AI365VIP.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 AI365VIP(AsyncGeneratorProvider, ProviderModelMixin):
  7. url = "https://chat.ai365vip.com"
  8. api_endpoint = "/api/chat"
  9. working = False
  10. default_model = 'gpt-3.5-turbo'
  11. models = [
  12. 'gpt-3.5-turbo',
  13. 'gpt-3.5-turbo-16k',
  14. 'gpt-4o',
  15. ]
  16. model_aliases = {
  17. "gpt-3.5-turbo": "gpt-3.5-turbo-16k",
  18. }
  19. @classmethod
  20. async def create_async_generator(
  21. cls,
  22. model: str,
  23. messages: Messages,
  24. proxy: str = None,
  25. **kwargs
  26. ) -> AsyncResult:
  27. headers = {
  28. "accept": "*/*",
  29. "accept-language": "en-US,en;q=0.9",
  30. "content-type": "application/json",
  31. "origin": cls.url,
  32. "referer": f"{cls.url}/en",
  33. "sec-ch-ua": '"Chromium";v="127", "Not)A;Brand";v="99"',
  34. "sec-ch-ua-arch": '"x86"',
  35. "sec-ch-ua-bitness": '"64"',
  36. "sec-ch-ua-full-version": '"127.0.6533.119"',
  37. "sec-ch-ua-full-version-list": '"Chromium";v="127.0.6533.119", "Not)A;Brand";v="99.0.0.0"',
  38. "sec-ch-ua-mobile": "?0",
  39. "sec-ch-ua-model": '""',
  40. "sec-ch-ua-platform": '"Linux"',
  41. "sec-ch-ua-platform-version": '"4.19.276"',
  42. "sec-fetch-dest": "empty",
  43. "sec-fetch-mode": "cors",
  44. "sec-fetch-site": "same-origin",
  45. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
  46. }
  47. async with ClientSession(headers=headers) as session:
  48. data = {
  49. "model": {
  50. "id": model,
  51. "name": "GPT-3.5",
  52. "maxLength": 3000,
  53. "tokenLimit": 2048
  54. },
  55. "messages": [{"role": "user", "content": format_prompt(messages)}],
  56. "key": "",
  57. "prompt": "You are a helpful assistant.",
  58. "temperature": 1
  59. }
  60. async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
  61. response.raise_for_status()
  62. async for chunk in response.content:
  63. if chunk:
  64. yield chunk.decode()