DeepInfraChat.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from __future__ import annotations
  2. from ..typing import AsyncResult, Messages
  3. from .needs_auth import OpenaiAPI
  4. class DeepInfraChat(OpenaiAPI):
  5. label = "DeepInfra Chat"
  6. url = "https://deepinfra.com/chat"
  7. working = True
  8. default_model = 'meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo'
  9. models = [
  10. 'meta-llama/Meta-Llama-3.1-8B-Instruct',
  11. default_model,
  12. 'Qwen/QwQ-32B-Preview',
  13. 'microsoft/WizardLM-2-8x22B',
  14. 'Qwen/Qwen2.5-72B-Instruct',
  15. 'Qwen/Qwen2.5-Coder-32B-Instruct',
  16. 'nvidia/Llama-3.1-Nemotron-70B-Instruct',
  17. ]
  18. model_aliases = {
  19. "llama-3.1-8b": "meta-llama/Meta-Llama-3.1-8B-Instruct",
  20. "llama-3.1-70b": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
  21. "qwq-32b": "Qwen/QwQ-32B-Preview",
  22. "wizardlm-2-8x22b": "microsoft/WizardLM-2-8x22B",
  23. "qwen-2-72b": "Qwen/Qwen2.5-72B-Instruct",
  24. "qwen-2.5-coder-32b": "Qwen/Qwen2.5-Coder-32B-Instruct",
  25. "nemotron-70b": "nvidia/Llama-3.1-Nemotron-70B-Instruct",
  26. }
  27. @classmethod
  28. def create_async_generator(
  29. cls,
  30. model: str,
  31. messages: Messages,
  32. proxy: str = None,
  33. api_base: str = "https://api.deepinfra.com/v1/openai",
  34. **kwargs
  35. ) -> AsyncResult:
  36. headers = {
  37. 'Accept-Language': 'en-US,en;q=0.9',
  38. 'Content-Type': 'application/json',
  39. 'Origin': 'https://deepinfra.com',
  40. 'Referer': 'https://deepinfra.com/',
  41. 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
  42. 'X-Deepinfra-Source': 'web-page',
  43. 'accept': 'text/event-stream',
  44. }
  45. return super().create_async_generator(model, messages, proxy, api_base=api_base, headers=headers, **kwargs)