Equing.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from __future__ import annotations
  2. import json
  3. from abc import ABC, abstractmethod
  4. import requests
  5. from ...typing import Any, CreateResult
  6. from ..base_provider import AbstractProvider
  7. class Equing(AbstractProvider):
  8. url: str = 'https://next.eqing.tech/'
  9. working = False
  10. supports_stream = True
  11. supports_gpt_35_turbo = True
  12. supports_gpt_4 = False
  13. @staticmethod
  14. @abstractmethod
  15. def create_completion(
  16. model: str,
  17. messages: list[dict[str, str]],
  18. stream: bool, **kwargs: Any) -> CreateResult:
  19. headers = {
  20. 'authority' : 'next.eqing.tech',
  21. 'accept' : 'text/event-stream',
  22. 'accept-language' : 'en,fr-FR;q=0.9,fr;q=0.8,es-ES;q=0.7,es;q=0.6,en-US;q=0.5,am;q=0.4,de;q=0.3',
  23. 'cache-control' : 'no-cache',
  24. 'content-type' : 'application/json',
  25. 'origin' : 'https://next.eqing.tech',
  26. 'plugins' : '0',
  27. 'pragma' : 'no-cache',
  28. 'referer' : 'https://next.eqing.tech/',
  29. 'sec-ch-ua' : '"Not/A)Brand";v="99", "Google Chrome";v="115", "Chromium";v="115"',
  30. 'sec-ch-ua-mobile' : '?0',
  31. 'sec-ch-ua-platform': '"macOS"',
  32. 'sec-fetch-dest' : 'empty',
  33. 'sec-fetch-mode' : 'cors',
  34. 'sec-fetch-site' : 'same-origin',
  35. 'user-agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36',
  36. 'usesearch' : 'false',
  37. 'x-requested-with' : 'XMLHttpRequest'
  38. }
  39. json_data = {
  40. 'messages' : messages,
  41. 'stream' : stream,
  42. 'model' : model,
  43. 'temperature' : kwargs.get('temperature', 0.5),
  44. 'presence_penalty' : kwargs.get('presence_penalty', 0),
  45. 'frequency_penalty' : kwargs.get('frequency_penalty', 0),
  46. 'top_p' : kwargs.get('top_p', 1),
  47. }
  48. response = requests.post('https://next.eqing.tech/api/openai/v1/chat/completions',
  49. headers=headers, json=json_data, stream=stream)
  50. if not stream:
  51. yield response.json()["choices"][0]["message"]["content"]
  52. return
  53. for line in response.iter_content(chunk_size=1024):
  54. if line:
  55. if b'content' in line:
  56. line_json = json.loads(line.decode('utf-8').split('data: ')[1])
  57. token = line_json['choices'][0]['delta'].get('content')
  58. if token:
  59. yield token