Pizzagpt.py 1.8 KB

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