gpt4free/g4f/Provider/needs_auth/DeepInfra.py

59 lines
2.0 KiB
Python
Raw Normal View History

2023-10-26 22:32:49 +03:00
from __future__ import annotations
import requests
from ...typing import AsyncResult, Messages
2024-11-09 10:48:34 +03:00
from .OpenaiAPI import OpenaiAPI
2023-10-26 22:32:49 +03:00
2024-11-09 10:48:34 +03:00
class DeepInfra(OpenaiAPI):
2024-04-12 21:58:40 +03:00
label = "DeepInfra"
2024-01-02 01:23:45 +03:00
url = "https://deepinfra.com"
working = True
needs_auth = True
2024-01-02 01:23:45 +03:00
supports_stream = True
supports_message_history = True
default_model = "meta-llama/Meta-Llama-3.1-70B-Instruct"
@classmethod
def get_models(cls):
if not cls.models:
url = 'https://api.deepinfra.com/models/featured'
2024-01-30 06:15:25 +03:00
models = requests.get(url).json()
cls.models = [model['model_name'] for model in models if model["type"] == "text-generation"]
return cls.models
@classmethod
def create_async_generator(
cls,
2024-01-02 01:23:45 +03:00
model: str,
messages: Messages,
stream: bool,
api_base: str = "https://api.deepinfra.com/v1/openai",
temperature: float = 0.7,
max_tokens: int = 1028,
2024-01-02 01:23:45 +03:00
**kwargs
) -> AsyncResult:
2023-10-26 22:32:49 +03:00
headers = {
2024-01-02 01:23:45 +03:00
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US',
2023-11-24 17:16:00 +03:00
'Connection': 'keep-alive',
'Origin': 'https://deepinfra.com',
'Referer': 'https://deepinfra.com/',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-site',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36',
'X-Deepinfra-Source': 'web-embed',
'sec-ch-ua': '"Google Chrome";v="119", "Chromium";v="119", "Not?A_Brand";v="24"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"macOS"',
2023-10-26 22:32:49 +03:00
}
return super().create_async_generator(
model, messages,
stream=stream,
api_base=api_base,
temperature=temperature,
max_tokens=max_tokens,
headers=headers,
**kwargs
)