GPROChat.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from __future__ import annotations
  2. import time
  3. import hashlib
  4. from aiohttp import ClientSession
  5. from ...typing import AsyncResult, Messages
  6. from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
  7. from ..helper import format_prompt
  8. class GPROChat(AsyncGeneratorProvider, ProviderModelMixin):
  9. url = "https://gprochat.com"
  10. api_endpoint = "https://gprochat.com/api/generate"
  11. working = False
  12. supports_stream = True
  13. supports_message_history = True
  14. default_model = 'gemini-1.5-pro'
  15. @staticmethod
  16. def generate_signature(timestamp: int, message: str) -> str:
  17. secret_key = "2BC120D4-BB36-1B60-26DE-DB630472A3D8"
  18. hash_input = f"{timestamp}:{message}:{secret_key}"
  19. signature = hashlib.sha256(hash_input.encode('utf-8')).hexdigest()
  20. return signature
  21. @classmethod
  22. async def create_async_generator(
  23. cls,
  24. model: str,
  25. messages: Messages,
  26. proxy: str = None,
  27. **kwargs
  28. ) -> AsyncResult:
  29. model = cls.get_model(model)
  30. timestamp = int(time.time() * 1000)
  31. prompt = format_prompt(messages)
  32. sign = cls.generate_signature(timestamp, prompt)
  33. headers = {
  34. "accept": "*/*",
  35. "origin": cls.url,
  36. "referer": f"{cls.url}/",
  37. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36",
  38. "content-type": "text/plain;charset=UTF-8"
  39. }
  40. data = {
  41. "messages": [{"role": "user", "parts": [{"text": prompt}]}],
  42. "time": timestamp,
  43. "pass": None,
  44. "sign": sign
  45. }
  46. async with ClientSession(headers=headers) as session:
  47. async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
  48. response.raise_for_status()
  49. async for chunk in response.content.iter_any():
  50. if chunk:
  51. yield chunk.decode()