DeepInfraChat.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. from __future__ import annotations
  2. from ..typing import AsyncResult, Messages
  3. from .template import OpenaiTemplate
  4. class DeepInfraChat(OpenaiTemplate):
  5. url = "https://deepinfra.com/chat"
  6. api_base = "https://api.deepinfra.com/v1/openai"
  7. working = True
  8. default_model = 'meta-llama/Llama-3.3-70B-Instruct-Turbo'
  9. models = [
  10. 'meta-llama/Meta-Llama-3.1-8B-Instruct',
  11. 'meta-llama/Llama-3.2-90B-Vision-Instruct',
  12. default_model,
  13. 'deepseek-ai/DeepSeek-V3',
  14. 'mistralai/Mistral-Small-24B-Instruct-2501',
  15. 'deepseek-ai/DeepSeek-R1',
  16. 'deepseek-ai/DeepSeek-R1-Distill-Llama-70B',
  17. 'deepseek-ai/DeepSeek-R1-Distill-Qwen-32B',
  18. 'microsoft/phi-4',
  19. 'microsoft/WizardLM-2-8x22B',
  20. 'Qwen/Qwen2.5-72B-Instruct',
  21. ]
  22. model_aliases = {
  23. "llama-3.1-8b": "meta-llama/Meta-Llama-3.1-8B-Instruct",
  24. "llama-3.2-90b": "meta-llama/Llama-3.2-90B-Vision-Instruct",
  25. "llama-3.3-70b": "meta-llama/Llama-3.3-70B-Instruct-Turbo",
  26. "deepseek-v3": "deepseek-ai/DeepSeek-V3",
  27. "mixtral-small-28b": "mistralai/Mistral-Small-24B-Instruct-2501",
  28. "deepseek-r1": "deepseek-ai/DeepSeek-R1",
  29. "deepseek-r1": "deepseek-ai/DeepSeek-R1-Distill-Llama-70B",
  30. "deepseek-r1": "deepseek-ai/DeepSeek-R1-Distill-Qwen-32B",
  31. "phi-4": "microsoft/phi-4",
  32. "wizardlm-2-8x22b": "microsoft/WizardLM-2-8x22B",
  33. "qwen-2.5-72b": "Qwen/Qwen2.5-72B-Instruct",
  34. }
  35. @classmethod
  36. async def create_async_generator(
  37. cls,
  38. model: str,
  39. messages: Messages,
  40. stream: bool = True,
  41. top_p: float = 0.9,
  42. temperature: float = 0.7,
  43. max_tokens: int = None,
  44. headers: dict = {},
  45. **kwargs
  46. ) -> AsyncResult:
  47. headers = {
  48. 'Accept-Language': 'en-US,en;q=0.9',
  49. 'Origin': 'https://deepinfra.com',
  50. 'Referer': 'https://deepinfra.com/',
  51. 'X-Deepinfra-Source': 'web-page',
  52. **headers
  53. }
  54. async for chunk in super().create_async_generator(model, messages, headers=headers, **kwargs):
  55. yield chunk