Yqcloud.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import os
  2. import time
  3. import requests
  4. from ...typing import sha256, Dict, get_type_hints
  5. url = 'https://chat9.yqcloud.top/'
  6. model = [
  7. 'gpt-3.5-turbo',
  8. ]
  9. supports_stream = True
  10. needs_auth = False
  11. def _create_completion(model: str, messages: list, stream: bool, **kwargs):
  12. headers = {
  13. 'authority': 'api.aichatos.cloud',
  14. 'origin': 'https://chat9.yqcloud.top',
  15. 'referer': 'https://chat9.yqcloud.top/',
  16. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36',
  17. }
  18. json_data = {
  19. 'prompt': 'always respond in english | %s' % messages[-1]['content'],
  20. 'userId': f'#/chat/{int(time.time() * 1000)}',
  21. 'network': True,
  22. 'apikey': '',
  23. 'system': '',
  24. 'withoutContext': False,
  25. }
  26. response = requests.post('https://api.aichatos.cloud/api/generateStream', headers=headers, json=json_data, stream=True)
  27. for token in response.iter_content(chunk_size=2046):
  28. if not b'always respond in english' in token:
  29. yield (token.decode('utf-8'))
  30. params = f'g4f.Providers.{os.path.basename(__file__)[:-3]} supports: ' + \
  31. '(%s)' % ', '.join([f"{name}: {get_type_hints(_create_completion)[name].__name__}" for name in _create_completion.__code__.co_varnames[:_create_completion.__code__.co_argcount]])