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