From f05d06989679ae7ca0b920fce6d50e6ae50cb361 Mon Sep 17 00:00:00 2001 From: Heiner Lohaus Date: Tue, 7 Jan 2025 17:09:10 +0100 Subject: Add DeepSeek Provider Add get api keys urls to GUI --- g4f/Provider/GizAI.py | 1 - g4f/Provider/Mhystical.py | 4 +++- g4f/Provider/PollinationsAI.py | 23 +++++++++++------------ g4f/Provider/needs_auth/DeepInfra.py | 1 + g4f/Provider/needs_auth/DeepSeek.py | 14 ++++++++++++++ g4f/Provider/needs_auth/GlhfChat.py | 1 + g4f/Provider/needs_auth/OpenaiAPI.py | 2 +- g4f/Provider/needs_auth/__init__.py | 1 + 8 files changed, 32 insertions(+), 15 deletions(-) create mode 100644 g4f/Provider/needs_auth/DeepSeek.py (limited to 'g4f/Provider') diff --git a/g4f/Provider/GizAI.py b/g4f/Provider/GizAI.py index c33f82df..a8401b43 100644 --- a/g4f/Provider/GizAI.py +++ b/g4f/Provider/GizAI.py @@ -6,7 +6,6 @@ from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from .helper import format_prompt - class GizAI(AsyncGeneratorProvider, ProviderModelMixin): url = "https://app.giz.ai/assistant" api_endpoint = "https://app.giz.ai/api/data/users/inferenceServer.infer" diff --git a/g4f/Provider/Mhystical.py b/g4f/Provider/Mhystical.py index 42a70396..570cc85c 100644 --- a/g4f/Provider/Mhystical.py +++ b/g4f/Provider/Mhystical.py @@ -18,6 +18,7 @@ class Mhystical(OpenaiAPI): label = "Mhystical" url = "https://mhystical.cc" api_endpoint = "https://api.mhystical.cc/v1/completions" + login_url = "https://mhystical.cc/dashboard" working = True needs_auth = False supports_stream = False # Set to False, as streaming is not specified in ChatifyAI @@ -37,11 +38,12 @@ class Mhystical(OpenaiAPI): model: str, messages: Messages, stream: bool = False, + api_key: str = "mhystical", **kwargs ) -> AsyncResult: model = cls.get_model(model) headers = { - "x-api-key": "mhystical", + "x-api-key": api_key, "Content-Type": "application/json", "accept": "*/*", "cache-control": "no-cache", diff --git a/g4f/Provider/PollinationsAI.py b/g4f/Provider/PollinationsAI.py index 3df3fafd..4990a869 100644 --- a/g4f/Provider/PollinationsAI.py +++ b/g4f/Provider/PollinationsAI.py @@ -7,12 +7,12 @@ from urllib.parse import quote from typing import Optional from aiohttp import ClientSession +from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from ..requests.raise_for_status import raise_for_status from ..typing import AsyncResult, Messages from ..image import ImageResponse -from .needs_auth.OpenaiAPI import OpenaiAPI -class PollinationsAI(OpenaiAPI): +class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin): label = "Pollinations AI" url = "https://pollinations.ai" @@ -21,21 +21,21 @@ class PollinationsAI(OpenaiAPI): supports_stream = True supports_system_message = True supports_message_history = True - + # API endpoints base api_base = "https://text.pollinations.ai/openai" - + # API endpoints text_api_endpoint = "https://text.pollinations.ai" image_api_endpoint = "https://image.pollinations.ai" - + # Models configuration default_model = "openai" default_image_model = "flux" - + image_models = [] models = [] - + additional_models_image = ["midjourney", "dall-e-3"] additional_models_text = ["sur", "sur-mistral", "claude"] model_aliases = { @@ -100,7 +100,7 @@ class PollinationsAI(OpenaiAPI): **kwargs ) -> AsyncResult: model = cls.get_model(model) - + # Check if models # Image generation if model in cls.image_models: @@ -151,7 +151,6 @@ class PollinationsAI(OpenaiAPI): if seed is None: seed = random.randint(0, 10000) - headers = { 'Accept': '*/*', 'Accept-Language': 'en-US,en;q=0.9', @@ -177,7 +176,7 @@ class PollinationsAI(OpenaiAPI): async with session.head(url, proxy=proxy) as response: if response.status == 200: - image_response = ImageResponse(images=url, alt=messages[-1]["content"]) + image_response = ImageResponse(images=url, alt=messages[-1]["content"] if prompt is None else prompt) yield image_response @classmethod @@ -195,7 +194,7 @@ class PollinationsAI(OpenaiAPI): ) -> AsyncResult: if api_key is None: api_key = "dummy" # Default value if api_key is not provided - + headers = { "accept": "*/*", "accept-language": "en-US,en;q=0.9", @@ -215,7 +214,7 @@ class PollinationsAI(OpenaiAPI): "jsonMode": False, "stream": stream } - + async with session.post(cls.text_api_endpoint, json=data, proxy=proxy) as response: response.raise_for_status() async for chunk in response.content: diff --git a/g4f/Provider/needs_auth/DeepInfra.py b/g4f/Provider/needs_auth/DeepInfra.py index c5ebac1e..ea114a1b 100644 --- a/g4f/Provider/needs_auth/DeepInfra.py +++ b/g4f/Provider/needs_auth/DeepInfra.py @@ -7,6 +7,7 @@ from .OpenaiAPI import OpenaiAPI class DeepInfra(OpenaiAPI): label = "DeepInfra" url = "https://deepinfra.com" + login_url = "https://deepinfra.com/dash/api_keys" working = True api_base = "https://api.deepinfra.com/v1/openai", needs_auth = True diff --git a/g4f/Provider/needs_auth/DeepSeek.py b/g4f/Provider/needs_auth/DeepSeek.py new file mode 100644 index 00000000..88b187be --- /dev/null +++ b/g4f/Provider/needs_auth/DeepSeek.py @@ -0,0 +1,14 @@ +from __future__ import annotations + +from .OpenaiAPI import OpenaiAPI + +class DeepSeek(OpenaiAPI): + label = "DeepSeek" + url = "https://platform.deepseek.com" + login_url = "https://platform.deepseek.com/api_keys" + working = True + api_base = "https://api.deepseek.com" + needs_auth = True + supports_stream = True + supports_message_history = True + default_model = "deepseek-chat" \ No newline at end of file diff --git a/g4f/Provider/needs_auth/GlhfChat.py b/g4f/Provider/needs_auth/GlhfChat.py index c0bf8e7e..f3a578af 100644 --- a/g4f/Provider/needs_auth/GlhfChat.py +++ b/g4f/Provider/needs_auth/GlhfChat.py @@ -5,6 +5,7 @@ from .OpenaiAPI import OpenaiAPI class GlhfChat(OpenaiAPI): label = "GlhfChat" url = "https://glhf.chat" + login_url = "https://glhf.chat/users/settings/api" api_base = "https://glhf.chat/api/openai/v1" working = True model_aliases = { diff --git a/g4f/Provider/needs_auth/OpenaiAPI.py b/g4f/Provider/needs_auth/OpenaiAPI.py index 7ff9b555..75c3574f 100644 --- a/g4f/Provider/needs_auth/OpenaiAPI.py +++ b/g4f/Provider/needs_auth/OpenaiAPI.py @@ -8,7 +8,7 @@ from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin, RaiseErr from ...typing import Union, Optional, AsyncResult, Messages, ImagesType from ...requests import StreamSession, raise_for_status from ...providers.response import FinishReason, ToolCalls, Usage -from ...errors import MissingAuthError, ResponseError +from ...errors import MissingAuthError from ...image import to_data_uri from ... import debug diff --git a/g4f/Provider/needs_auth/__init__.py b/g4f/Provider/needs_auth/__init__.py index 24282f0f..4b800ff4 100644 --- a/g4f/Provider/needs_auth/__init__.py +++ b/g4f/Provider/needs_auth/__init__.py @@ -5,6 +5,7 @@ from .Cerebras import Cerebras from .CopilotAccount import CopilotAccount from .DeepInfra import DeepInfra from .DeepInfraImage import DeepInfraImage +from .DeepSeek import DeepSeek from .Gemini import Gemini from .GeminiPro import GeminiPro from .GithubCopilot import GithubCopilot -- cgit v1.2.3