Pizzagpt.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 Pizzagpt(AsyncGeneratorProvider, ProviderModelMixin):
  7. url = "https://www.pizzagpt.it"
  8. api_endpoint = "/api/chatx-completion"
  9. working = True
  10. default_model = 'gpt-4o-mini'
  11. @classmethod
  12. async def create_async_generator(
  13. cls,
  14. model: str,
  15. messages: Messages,
  16. proxy: str = None,
  17. **kwargs
  18. ) -> AsyncResult:
  19. headers = {
  20. "accept": "application/json",
  21. "accept-language": "en-US,en;q=0.9",
  22. "content-type": "application/json",
  23. "origin": cls.url,
  24. "referer": f"{cls.url}/en",
  25. "sec-ch-ua": '"Chromium";v="127", "Not)A;Brand";v="99"',
  26. "sec-ch-ua-mobile": "?0",
  27. "sec-ch-ua-platform": '"Linux"',
  28. "sec-fetch-dest": "empty",
  29. "sec-fetch-mode": "cors",
  30. "sec-fetch-site": "same-origin",
  31. "user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36",
  32. "x-secret": "Marinara"
  33. }
  34. async with ClientSession(headers=headers) as session:
  35. prompt = format_prompt(messages)
  36. data = {
  37. "question": prompt
  38. }
  39. async with session.post(f"{cls.url}{cls.api_endpoint}", json=data, proxy=proxy) as response:
  40. response.raise_for_status()
  41. response_json = await response.json()
  42. content = response_json.get("answer", response_json).get("content")
  43. if content:
  44. yield content