From 86d5ba25289656eeddebd31ad08ce53ca7a6bdeb Mon Sep 17 00:00:00 2001 From: kqlio67 <> Date: Wed, 5 Feb 2025 18:22:42 +0200 Subject: [PATCH] Adding New Models and Enhancing Provider Functionality --- docs/providers-and-models.md | 27 +++++++------ g4f/Provider/Blackbox.py | 73 ++++++++-------------------------- g4f/Provider/BlackboxAPI.py | 30 +------------- g4f/Provider/CablyAI.py | 50 ++++++++++++++++++----- g4f/Provider/Glider.py | 2 +- g4f/Provider/OIVSCode.py | 11 ++++- g4f/Provider/PollinationsAI.py | 59 +++++++++++---------------- g4f/models.py | 30 +++++++++----- 8 files changed, 127 insertions(+), 155 deletions(-) diff --git a/docs/providers-and-models.md b/docs/providers-and-models.md index 8d2a17735ac..dfc9dbd62cb 100644 --- a/docs/providers-and-models.md +++ b/docs/providers-and-models.md @@ -39,7 +39,7 @@ This document provides an overview of various AI providers and models, including |----------|-------------|--------------|---------------|--------|--------|------|------| |[aichatfree.info](https://aichatfree.info)|No auth required|`g4f.Provider.AIChatFree`|`gemini-1.5-pro` _**(1+)**_|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[autonomous.ai](https://www.autonomous.ai/anon/)|No auth required|`g4f.Provider.AutonomousAI`|`llama-3.3-70b, qwen-2.5-coder-32b, hermes-3, llama-3.2-90b, llama-3.3-70b, llama-3-2-70b`|✔|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| -|[blackbox.ai](https://www.blackbox.ai)|No auth required|`g4f.Provider.Blackbox`|`blackboxai, gemini-1.5-flash, gemini-1.5-pro, blackboxai-pro, llama-3.1-8b, llama-3.1-70b, llama-3-1-405b, llama-3.3-70b, mixtral-small-28b, deepseek-chat, dbrx-instruct, qwq-32b, hermes-2-dpo, deepseek-r1` _**(+34)**_|`flux`|`blackboxai, gpt-4o, gemini-1.5-pro, gemini-1.5-flash, llama-3.1-8b, llama-3.1-70b, llama-3.1-405b`|✔|![](https://img.shields.io/badge/Active-brightgreen)| +|[blackbox.ai](https://www.blackbox.ai)|No auth required|`g4f.Provider.Blackbox`|`blackboxai, gpt-4, gpt-4o, o3-mini, claude-3.5-sonnet, gemini-1.5-flash, gemini-1.5-pro, blackboxai-pro, llama-3.1-8b, llama-3.1-70b, llama-3-1-405b, llama-3.3-70b, mixtral-small-28b, deepseek-chat, dbrx-instruct, qwq-32b, hermes-2-dpo, deepseek-r1` _**(+34)**_|`flux`|`blackboxai, gpt-4o, o3-mini, gemini-1.5-pro, gemini-1.5-flash, llama-3.1-8b, llama-3.1-70b, llama-3.1-405b`|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[api.blackbox.ai](https://api.blackbox.ai)|No auth required|`g4f.Provider.BlackboxAPI`|`deepseek-v3, deepseek-r1, deepseek-chat, mixtral-small-28b, dbrx-instruct, qwq-32b, hermes-2-dpo`|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[cablyai.com](https://cablyai.com)|Optional API key|`g4f.Provider.CablyAI`|`gpt-4o-mini, llama-3.1-8b, deepseek-v3, deepseek-r1, o3-mini-low` _**(2+)**_|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[chatglm.cn](https://chatglm.cn)|No auth required|`g4f.Provider.ChatGLM`|`glm-4`|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| @@ -66,7 +66,7 @@ This document provides an overview of various AI providers and models, including |[labs.perplexity.ai](https://labs.perplexity.ai)|No auth required|`g4f.Provider.PerplexityLabs`|`sonar-online, sonar-chat, llama-3.3-70b, llama-3.1-8b, llama-3.1-70b, lfm-40b`|❌|❌|✔|![Error](https://img.shields.io/badge/Active-brightgreen)| |[pi.ai/talk](https://pi.ai/talk)|[Manual cookies](https://pi.ai/talk)|`g4f.Provider.Pi`|`pi`|❌|❌|✔|![Error](https://img.shields.io/badge/Active-brightgreen)| |[pizzagpt.it](https://www.pizzagpt.it)|No auth required|`g4f.Provider.Pizzagpt`|`gpt-4o-mini`|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| -|[pollinations.ai](https://pollinations.ai)|No auth required|`g4f.Provider.PollinationsAI`|`gpt-4o-mini, gpt-4o, qwen-2.5-72b, qwen-2.5-coder-32b, llama-3.3-70b, mistral-nemo, deepseek-chat, llama-3.1-8b, deepseek-r1` _**(2+)**_|`flux, flux-pro, flux-realism, flux-cablyai, flux-anime, flux-3d, midjourney, dall-e-3, sdxl-turbo`|gpt-4o, gpt-4o-mini|✔|![](https://img.shields.io/badge/Active-brightgreen)| +|[pollinations.ai](https://pollinations.ai)|No auth required|`g4f.Provider.PollinationsAI`|`gpt-4o-mini, gpt-4o, qwen-2.5-72b, qwen-2.5-coder-32b, llama-3.3-70b, mistral-nemo, deepseek-chat, llama-3.1-8b, deepseek-r1, gemini-2.0-flash, gemini-2.0-flash-thinking` _**(3+)**_|`flux, flux-pro, flux-dev, flux-schnell, dall-e-3, sdxl-turbo`|gpt-4o, gpt-4o-mini|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[app.prodia.com](https://app.prodia.com)|No auth required|`g4f.Provider.Prodia`|❌|✔ _**(46)**_|❌|❌|![](https://img.shields.io/badge/Active-brightgreen)| |[teach-anything.com](https://www.teach-anything.com)|No auth required|`g4f.Provider.TeachAnything`|`llama-3.1-70b`|❌|❌|✔|![](https://img.shields.io/badge/Active-brightgreen)| |[you.com](https://you.com)|[Manual cookies](https://you.com)|`g4f.Provider.You`|✔|✔|✔|✔|![](https://img.shields.io/badge/Active-brightgreen)| @@ -125,11 +125,12 @@ This document provides an overview of various AI providers and models, including | Model | Base Provider | Providers | Website | |-------|---------------|-----------|---------| |gpt-4|OpenAI|10+ Providers|[platform.openai.com](https://platform.openai.com/docs/models/gpt-4-turbo-and-gpt-4)| -|gpt-4o|OpenAI|7+ Providers|[platform.openai.com](https://platform.openai.com/docs/models/gpt-4o)| +|gpt-4o|OpenAI|8+ Providers|[platform.openai.com](https://platform.openai.com/docs/models/gpt-4o)| |gpt-4o-mini|OpenAI|9+ Providers|[platform.openai.com](https://platform.openai.com/docs/models/gpt-4o-mini)| |o1|OpenAI|1+ Providers|[openai.com](https://openai.com/index/introducing-openai-o1-preview/)| |o1-preview|OpenAI|1+ Providers|[openai.com](https://openai.com/index/introducing-openai-o1-preview/)| |o1-mini|OpenAI|1+ Providers|[openai.com](https://openai.com/index/openai-o1-mini-advancing-cost-efficient-reasoning/)| +|o3-mini|OpenAI|2+ Providers|[openai.com](https://openai.com/index/openai-o3-mini/)| |o3-mini-low|OpenAI|1+ Providers|[openai.com](https://openai.com/index/openai-o3-mini/)| |gigachat|GigaChat|1+ Providers|[developers.sber.ru/gigachat](https://developers.sber.ru/gigachat)| |meta-ai|Meta|1+ Providers|[ai.meta.com](https://ai.meta.com/)| @@ -146,7 +147,7 @@ This document provides an overview of various AI providers and models, including |llama-3.3-70b|Meta Llama|6+ Providers|[ai.meta.com](https://ai.meta.com/blog/llama-3-3/)| |mixtral-8x7b|Mistral|2+ Providers|[mistral.ai](https://mistral.ai/news/mixtral-of-experts/)| |mistral-nemo|Mistral|3+ Providers|[huggingface.co](https://huggingface.co/mistralai/Mistral-Nemo-Instruct-2407)| -|mixtral-small-28b|Mistral|2+ Providers|[mistral.ai](https://mistral.ai/news/mixtral-small-28b/)| +|mixtral-small-28b|Mistral|3+ Providers|[mistral.ai](https://mistral.ai/news/mixtral-small-28b/)| |hermes-2-dpo|NousResearch|2+ Providers|[huggingface.co](https://huggingface.co/NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO)| |phi-3.5-mini|Microsoft|1+ Providers|[huggingface.co](https://huggingface.co/microsoft/Phi-3.5-mini-instruct)| |phi-4|Microsoft|1+ Providers|[techcommunity.microsoft.com](https://techcommunity.microsoft.com/blog/aiplatformblog/introducing-phi-4-microsoft%E2%80%99s-newest-small-language-model-specializing-in-comple/4357090)| @@ -155,12 +156,12 @@ This document provides an overview of various AI providers and models, including |gemini-exp|Google DeepMind|1+ Providers|[blog.google](https://blog.google/feed/gemini-exp-1206/)| |gemini-1.5-flash|Google DeepMind|5+ Providers|[deepmind.google](https://deepmind.google/technologies/gemini/flash/)| |gemini-1.5-pro|Google DeepMind|5+ Providers|[deepmind.google](https://deepmind.google/technologies/gemini/pro/)| -|gemini-2.0-flash|Google DeepMind|2+ Providers|[deepmind.google](https://deepmind.google/technologies/gemini/flash/)| +|gemini-2.0-flash|Google DeepMind|3+ Providers|[deepmind.google](https://deepmind.google/technologies/gemini/flash/)| |gemini-2.0-flash-thinking|Google DeepMind|1+ Providers|[ai.google.dev](https://ai.google.dev/gemini-api/docs/thinking-mode)| |claude-3-haiku|Anthropic|2+ Providers|[anthropic.com](https://www.anthropic.com/news/claude-3-haiku)| |claude-3-sonnet|Anthropic|1+ Providers|[anthropic.com](https://www.anthropic.com/news/claude-3-family)| |claude-3-opus|Anthropic|2+ Providers|[anthropic.com](https://www.anthropic.com/news/claude-3-family)| -|claude-3.5-sonnet|Anthropic|2+ Providers|[anthropic.com](https://www.anthropic.com/news/claude-3-5-sonnet)| +|claude-3.5-sonnet|Anthropic|3+ Providers|[anthropic.com](https://www.anthropic.com/news/claude-3-5-sonnet)| |reka-core|Reka AI|1+ Providers|[reka.ai](https://www.reka.ai/ourmodels)| |blackboxai|Blackbox AI|1+ Providers|[docs.blackbox.chat](https://docs.blackbox.chat/blackbox-ai-1)| |blackboxai-pro|Blackbox AI|1+ Providers|[docs.blackbox.chat](https://docs.blackbox.chat/blackbox-ai-1)| @@ -171,19 +172,19 @@ This document provides an overview of various AI providers and models, including |qwen-2-72b|Qwen|1+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2-72B)| |qwen-2-vl-7b|Qwen|1+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2-VL-7B)| |qwen-2.5-72b|Qwen|3+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2.5-72B-Instruct)| -|qwen-2.5-coder-32b|Qwen|4+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2.5-Coder-32B)| +|qwen-2.5-coder-32b|Qwen|3+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2.5-Coder-32B)| |qwen-2.5-1m-demo|Qwen|1+ Providers|[huggingface.co](https://huggingface.co/Qwen/Qwen2.5-1M-Demo)| -|qwq-32b|Qwen|5+ Providers|[huggingface.co](https://huggingface.co/Qwen/QwQ-32B-Preview)| +|qwq-32b|Qwen|4+ Providers|[huggingface.co](https://huggingface.co/Qwen/QwQ-32B-Preview)| |qvq-72b|Qwen|1+ Providers|[huggingface.co](https://huggingface.co/Qwen/QVQ-72B-Preview)| |pi|Inflection|1+ Providers|[inflection.ai](https://inflection.ai/blog/inflection-2-5)| |deepseek-chat|DeepSeek|4+ Providers|[huggingface.co](https://huggingface.co/deepseek-ai/deepseek-llm-67b-chat)| -|deepseek-v3|DeepSeek|4+ Providers|[api-docs.deepseek.com](https://api-docs.deepseek.com/news/news250120)| -|deepseek-r1|DeepSeek|8+ Providers|[api-docs.deepseek.com](https://api-docs.deepseek.com/news/news250120)| +|deepseek-v3|DeepSeek|5+ Providers|[api-docs.deepseek.com](https://api-docs.deepseek.com/news/news250120)| +|deepseek-r1|DeepSeek|10+ Providers|[api-docs.deepseek.com](https://api-docs.deepseek.com/news/news250120)| |grok-2|x.ai|1+|[x.ai](https://x.ai/blog/grok-2)| |sonar|Perplexity AI|1+ Providers|[docs.perplexity.ai](https://docs.perplexity.ai/)| |sonar-pro|Perplexity AI|1+ Providers|[docs.perplexity.ai](https://docs.perplexity.ai/)| |sonar-reasoning|Perplexity AI|1+ Providers|[docs.perplexity.ai](https://docs.perplexity.ai/)| -|nemotron-70b|Nvidia|3+ Providers|[build.nvidia.com](https://build.nvidia.com/nvidia/llama-3_1-nemotron-70b-instruct)| +|nemotron-70b|Nvidia|2+ Providers|[build.nvidia.com](https://build.nvidia.com/nvidia/llama-3_1-nemotron-70b-instruct)| |dbrx-instruct|Databricks|2+ Providers|[huggingface.co](https://huggingface.co/databricks/dbrx-instruct)| |glm-4|THUDM|1+ Providers|[github.com/THUDM](https://github.com/THUDM/GLM-4)| |mini_max|MiniMax|1+ Providers|[hailuo.ai](https://www.hailuo.ai/)| @@ -197,8 +198,8 @@ This document provides an overview of various AI providers and models, including |sd-3.5|Stability AI|1+ Providers|[huggingface.co](https://huggingface.co/stabilityai/stable-diffusion-3.5-large)| |flux|Black Forest Labs|3+ Providers|[github.com/black-forest-labs/flux](https://github.com/black-forest-labs/flux)| |flux-pro|Black Forest Labs|1+ Providers|[huggingface.co](https://huggingface.co/enhanceaiteam/FLUX.1-Pro)| -|flux-dev|Black Forest Labs|3+ Providers|[huggingface.co](https://huggingface.co/black-forest-labs/FLUX.1-dev)| -|flux-schnell|Black Forest Labs|3+ Providers|[huggingface.co](https://huggingface.co/black-forest-labs/FLUX.1-schnell)| +|flux-dev|Black Forest Labs|4+ Providers|[huggingface.co](https://huggingface.co/black-forest-labs/FLUX.1-dev)| +|flux-schnell|Black Forest Labs|4+ Providers|[huggingface.co](https://huggingface.co/black-forest-labs/FLUX.1-schnell)| |dall-e-3|OpenAI|5+ Providers|[openai.com](https://openai.com/index/dall-e/)| |midjourney|Midjourney|1+ Providers|[docs.midjourney.com](https://docs.midjourney.com/docs/model-versions)| diff --git a/g4f/Provider/Blackbox.py b/g4f/Provider/Blackbox.py index eac9d606f40..5ae4830157a 100644 --- a/g4f/Provider/Blackbox.py +++ b/g4f/Provider/Blackbox.py @@ -15,7 +15,7 @@ from ..image import to_data_uri from ..cookies import get_cookies_dir from .helper import format_prompt, format_image_prompt -from ..providers.response import JsonConversation, ImageResponse, Reasoning +from ..providers.response import JsonConversation, ImageResponse class Conversation(JsonConversation): validated_value: str = None @@ -39,10 +39,9 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): default_vision_model = default_model default_image_model = 'ImageGeneration' image_models = [default_image_model] - vision_models = [default_vision_model, 'gpt-4o', 'o3-mini', 'gemini-pro', 'DeepSeek-V3', 'gemini-1.5-flash', 'llama-3.1-8b', 'llama-3.1-70b', 'llama-3.1-405b'] - reasoning_models = ['DeepSeek-R1'] + vision_models = [default_vision_model, 'gpt-4o', 'o3-mini', 'gemini-pro', 'gemini-1.5-flash', 'llama-3.1-8b', 'llama-3.1-70b', 'llama-3.1-405b'] - userSelectedModel = ['gpt-4o', 'o3-mini', 'claude-sonnet-3.5', 'gemini-pro', 'blackboxai-pro'] + userSelectedModel = ['gpt-4o', 'o3-mini', 'gemini-pro', 'claude-sonnet-3.5', 'DeepSeek-V3', 'DeepSeek-R1', 'blackboxai-pro', 'Meta-Llama-3.3-70B-Instruct-Turbo', 'Mistral-Small-24B-Instruct-2501', 'DeepSeek-LLM-Chat-(67B)', 'DBRX-Instruct', 'Qwen-QwQ-32B-Preview', 'Nous-Hermes-2-Mixtral-8x7B-DPO'] agentMode = { 'DeepSeek-V3': {'mode': True, 'id': "deepseek-chat", 'name': "DeepSeek-V3"}, @@ -56,6 +55,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): } trendingAgentMode = { + "o3-mini": {'mode': True, 'id': 'o3-mini'}, "gemini-1.5-flash": {'mode': True, 'id': 'Gemini'}, "llama-3.1-8b": {'mode': True, 'id': "llama-3.1-8b"}, 'llama-3.1-70b': {'mode': True, 'id': "llama-3.1-70b"}, @@ -94,9 +94,11 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): 'builder Agent': {'mode': True, 'id': "builder Agent"}, } - models = list(dict.fromkeys([default_model, *userSelectedModel, *reasoning_models, *image_models, *list(agentMode.keys()), *list(trendingAgentMode.keys())])) + models = list(dict.fromkeys([default_model, *userSelectedModel, *image_models, *list(agentMode.keys()), *list(trendingAgentMode.keys())])) model_aliases = { + "gpt-4": "gpt-4o", + "claude-3.5-sonnet": "claude-sonnet-3.5", "gemini-1.5-flash": "gemini-1.5-flash", "gemini-1.5-pro": "gemini-pro", "deepseek-v3": "DeepSeek-V3", @@ -177,7 +179,6 @@ async def create_async_generator( messages: Messages, prompt: str = None, proxy: str = None, - web_search: bool = False, images: ImagesType = None, top_p: float = None, temperature: float = None, @@ -283,60 +284,20 @@ async def create_async_generator( "vscodeClient": False, "codeInterpreterMode": False, "customProfile": {"name": "", "occupation": "", "traits": [], "additionalInfo": "", "enableNewChats": False}, - "webSearchMode": web_search + "session": {"user":{"name":"John Doe","email":"john.doe@gmail.com","image":"https://lh3.googleusercontent.com/a/ACg8ocK9X7mNpQ2vR4jH3tY8wL5nB1xM6fDS9JW2kLpTn4Vy3hR2xN4m=s96-c"},"expires":datetime.now(timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z'), "status": "PREMIUM"}, + "webSearchMode": False } async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response: await raise_for_status(response) - response_text = await response.text() - parts = response_text.split('$~~~$') - text_to_yield = parts[2] if len(parts) >= 3 else response_text - - if not text_to_yield or text_to_yield.isspace(): - return - - if model in cls.reasoning_models and "\n\n\n" in text_to_yield: - think_split = text_to_yield.split("\n\n\n", 1) - if len(think_split) > 1: - think_content, answer = think_split[0].strip(), think_split[1].strip() - yield Reasoning(status=think_content) - yield answer - else: - yield text_to_yield - elif "" in text_to_yield: - pre_think, rest = text_to_yield.split('', 1) - think_content, post_think = rest.split('', 1) - - pre_think = pre_think.strip() - think_content = think_content.strip() - post_think = post_think.strip() - - if pre_think: - yield pre_think - if think_content: - yield Reasoning(status=think_content) - if post_think: - yield post_think - - elif "Generated by BLACKBOX.AI" in text_to_yield: - conversation.validated_value = await cls.fetch_validated(force_refresh=True) - if conversation.validated_value: - data["validated"] = conversation.validated_value - async with session.post(cls.api_endpoint, json=data, proxy=proxy) as new_response: - await raise_for_status(new_response) - new_response_text = await new_response.text() - new_parts = new_response_text.split('$~~~$') - new_text = new_parts[2] if len(new_parts) >= 3 else new_response_text - - if new_text and not new_text.isspace(): - yield new_text - else: - if text_to_yield and not text_to_yield.isspace(): - yield text_to_yield - else: - if text_to_yield and not text_to_yield.isspace(): - yield text_to_yield + full_response = [] + async for chunk in response.content.iter_any(): + if chunk: + chunk_text = chunk.decode() + full_response.append(chunk_text) + yield chunk_text if return_conversation: - conversation.message_history.append({"role": "assistant", "content": text_to_yield}) + full_response_text = ''.join(full_response) + conversation.message_history.append({"role": "assistant", "content": full_response_text}) yield conversation diff --git a/g4f/Provider/BlackboxAPI.py b/g4f/Provider/BlackboxAPI.py index d14429e48f0..4233e193473 100644 --- a/g4f/Provider/BlackboxAPI.py +++ b/g4f/Provider/BlackboxAPI.py @@ -5,7 +5,6 @@ from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from ..requests.raise_for_status import raise_for_status -from ..providers.response import Reasoning from .helper import format_prompt class BlackboxAPI(AsyncGeneratorProvider, ProviderModelMixin): @@ -20,15 +19,15 @@ class BlackboxAPI(AsyncGeneratorProvider, ProviderModelMixin): supports_message_history = True default_model = 'deepseek-ai/DeepSeek-V3' - reasoning_models = ['deepseek-ai/DeepSeek-R1'] models = [ default_model, + 'deepseek-ai/DeepSeek-R1', 'mistralai/Mistral-Small-24B-Instruct-2501', 'deepseek-ai/deepseek-llm-67b-chat', 'databricks/dbrx-instruct', 'Qwen/QwQ-32B-Preview', 'NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO' - ] + reasoning_models + ] model_aliases = { "deepseek-v3": "deepseek-ai/DeepSeek-V3", @@ -65,39 +64,14 @@ async def create_async_generator( async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response: await raise_for_status(response) - is_reasoning = False - current_reasoning = "" - async for chunk in response.content: if not chunk: continue text = chunk.decode(errors='ignore') - if model in cls.reasoning_models: - if "" in text: - text = text.replace("", "") - is_reasoning = True - current_reasoning = text - continue - - if "" in text: - text = text.replace("", "") - is_reasoning = False - current_reasoning += text - yield Reasoning(status=current_reasoning.strip()) - current_reasoning = "" - continue - - if is_reasoning: - current_reasoning += text - continue - try: if text: yield text except Exception as e: return - - if is_reasoning and current_reasoning: - yield Reasoning(status=current_reasoning.strip()) diff --git a/g4f/Provider/CablyAI.py b/g4f/Provider/CablyAI.py index 1ccc343d945..2be59b8c635 100644 --- a/g4f/Provider/CablyAI.py +++ b/g4f/Provider/CablyAI.py @@ -1,37 +1,39 @@ from __future__ import annotations -from ..errors import ModelNotSupportedError +from ..typing import AsyncResult, Messages from .template import OpenaiTemplate class CablyAI(OpenaiTemplate): - label = "CablyAI" url = "https://cablyai.com" - login_url = url + login_url = None api_base = "https://cablyai.com/v1" api_key = "sk-your-openai-api-key" - + working = True needs_auth = False + supports_stream = True + supports_system_message = True + supports_message_history = True default_model = 'gpt-4o-mini' - reasoning_models = ['deepseek-r1-uncensored'] fallback_models = [ default_model, 'searchgpt', 'llama-3.1-8b-instruct', + 'deepseek-r1-uncensored', 'deepseek-v3', 'tinyswallow1.5b', 'andy-3.5', 'o3-mini-low', - ] + reasoning_models - + ] + model_aliases = { - "searchgpt": "searchgpt (free)", "gpt-4o-mini": "searchgpt", "llama-3.1-8b": "llama-3.1-8b-instruct", "deepseek-r1": "deepseek-r1-uncensored", + "o3-mini": "o3-mini-low", } - + @classmethod def get_models(cls, api_key: str = None, api_base: str = None) -> list[str]: models = super().get_models(api_key, api_base); @@ -45,4 +47,32 @@ def get_model(cls, model: str, **kwargs) -> str: except ModelNotSupportedError: if f"f{model} (free)" in cls.models: return model - raise \ No newline at end of file + raise + + @classmethod + def create_async_generator( + cls, + model: str, + messages: Messages, + api_key: str = None, + stream: bool = True, + **kwargs + ) -> AsyncResult: + api_key = api_key or cls.api_key + headers = { + "Accept": "*/*", + "Accept-Language": "en-US,en;q=0.9", + "Authorization": f"Bearer {api_key}", + "Content-Type": "application/json", + "Origin": cls.url, + "Referer": f"{cls.url}/chat", + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36" + } + return super().create_async_generator( + model=model, + messages=messages, + api_key=api_key, + stream=stream, + headers=headers, + **kwargs + ) diff --git a/g4f/Provider/Glider.py b/g4f/Provider/Glider.py index f06feb65d91..c4108baf724 100644 --- a/g4f/Provider/Glider.py +++ b/g4f/Provider/Glider.py @@ -5,7 +5,7 @@ from ..typing import AsyncResult, Messages from .base_provider import AsyncGeneratorProvider, ProviderModelMixin from ..requests.raise_for_status import raise_for_status -from ..providers.response import FinishReason, Reasoning +from ..providers.response import FinishReason from .helper import format_prompt class Glider(AsyncGeneratorProvider, ProviderModelMixin): diff --git a/g4f/Provider/OIVSCode.py b/g4f/Provider/OIVSCode.py index fae8c1797be..46582dbc9fa 100644 --- a/g4f/Provider/OIVSCode.py +++ b/g4f/Provider/OIVSCode.py @@ -6,9 +6,16 @@ class OIVSCode(OpenaiTemplate): label = "OI VSCode Server" url = "https://oi-vscode-server.onrender.com" api_base = "https://oi-vscode-server.onrender.com/v1" + working = True needs_auth = False + supports_stream = True + supports_system_message = True + supports_message_history = True - default_model = "gpt-4o-mini" + default_model = "gpt-4o-mini-2024-07-18" default_vision_model = default_model - vision_models = [default_model, "gpt-4o-mini"] \ No newline at end of file + vision_models = [default_model, "gpt-4o-mini"] + models = vision_models + + model_aliases = {"gpt-4o-mini": "gpt-4o-mini-2024-07-18"} diff --git a/g4f/Provider/PollinationsAI.py b/g4f/Provider/PollinationsAI.py index 2af7e8d28ec..58788bc6605 100644 --- a/g4f/Provider/PollinationsAI.py +++ b/g4f/Provider/PollinationsAI.py @@ -37,21 +37,11 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin): # Models configuration default_model = "openai" + default_image_model = "flux" default_vision_model = "gpt-4o" - extra_image_models = [ - "flux", - "flux-pro", - "flux-realism", - "flux-anime", - "flux-3d", - "flux-cablyai", - "turbo", - "midjourney", - "dall-e-3", - ] + extra_image_models = ["flux-pro", "flux-dev", "flux-schnell", "midjourney", "dall-e-3"] vision_models = [default_vision_model, "gpt-4o-mini"] - reasoning_models = ['deepseek-reasoner', 'deepseek-r1'] - extra_text_models = ["claude", "claude-email", "p1"] + vision_models + reasoning_models + extra_text_models = ["claude", "claude-email", "deepseek-reasoner", "deepseek-r1"] + vision_models model_aliases = { ### Text Models ### "gpt-4o-mini": "openai", @@ -64,7 +54,6 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin): "gpt-4o-mini": "rtist", "gpt-4o": "searchgpt", "gpt-4o-mini": "p1", - "deepseek-chat": "deepseek", "deepseek-chat": "claude-hybridspace", "llama-3.1-8b": "llamalight", "gpt-4o-vision": "gpt-4o", @@ -72,33 +61,38 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin): "gpt-4o-mini": "claude", "deepseek-chat": "claude-email", "deepseek-r1": "deepseek-reasoner", + "gemini-2.0-flash": "gemini", + "gemini-2.0-flash-thinking": "gemini-thinking", ### Image Models ### "sdxl-turbo": "turbo", - "flux-schnell": "flux", - "flux-dev": "flux", } text_models = [] + image_models = [] @classmethod def get_models(cls, **kwargs): - if not cls.text_models: - url = "https://image.pollinations.ai/models" - response = requests.get(url) - raise_for_status(response) - new_image_models = response.json() - cls.extra_image_models = list(dict.fromkeys([*cls.extra_image_models, *new_image_models])) - - url = "https://text.pollinations.ai/models" - response = requests.get(url) - raise_for_status(response) - original_text_models = [model.get("name") for model in response.json()] + if not cls.text_models or not cls.image_models: + image_url = "https://image.pollinations.ai/models" + image_response = requests.get(image_url) + raise_for_status(image_response) + new_image_models = image_response.json() + + cls.image_models = list(dict.fromkeys([*cls.extra_image_models, *new_image_models])) + cls.extra_image_models = cls.image_models.copy() + + text_url = "https://text.pollinations.ai/models" + text_response = requests.get(text_url) + raise_for_status(text_response) + original_text_models = [model.get("name") for model in text_response.json()] + combined_text = cls.extra_text_models + [ model for model in original_text_models if model not in cls.extra_text_models ] cls.text_models = list(dict.fromkeys(combined_text)) - return cls.text_models + + return cls.text_models + cls.image_models @classmethod async def create_async_generator( @@ -194,7 +188,7 @@ async def _generate_image( yield ImagePreview(url, prompt) async with ClientSession(headers=DEFAULT_HEADERS, connector=get_connector(proxy=proxy)) as session: async with session.head(url) as response: - if response.status != 500: # Server is busy + if response.status != 500: await raise_for_status(response) yield ImageResponse(str(response.url), prompt) @@ -256,12 +250,7 @@ async def _generate_text( data = json.loads(json_str) choice = data["choices"][0] message = choice.get("message") or choice.get("delta", {}) - - # Handle reasoning content - if model in cls.reasoning_models: - if "reasoning_content" in message: - yield Reasoning(status=message["reasoning_content"].strip()) - + if "usage" in data: yield Usage(**data["usage"]) content = message.get("content", "") diff --git a/g4f/models.py b/g4f/models.py index 9acc74874ca..3f9678cedf6 100644 --- a/g4f/models.py +++ b/g4f/models.py @@ -96,6 +96,7 @@ class VisionModel(Model): base_provider = "", best_provider = IterListProvider([ Blackbox, + OIVSCode, PollinationsAI, HuggingSpace, GeminiPro, @@ -115,14 +116,14 @@ class VisionModel(Model): gpt_4 = Model( name = 'gpt-4', base_provider = 'OpenAI', - best_provider = IterListProvider([DDG, Jmuz, ChatGptEs, ChatGptt, PollinationsAI, Yqcloud, Copilot, OpenaiChat, Liaobots, Mhystical]) + best_provider = IterListProvider([Blackbox, DDG, Jmuz, ChatGptEs, ChatGptt, PollinationsAI, Yqcloud, Copilot, OpenaiChat, Liaobots, Mhystical]) ) # gpt-4o gpt_4o = VisionModel( name = 'gpt-4o', base_provider = 'OpenAI', - best_provider = IterListProvider([ChatGptt, Jmuz, ChatGptEs, PollinationsAI, Copilot, Liaobots, OpenaiChat]) + best_provider = IterListProvider([Blackbox, ChatGptt, Jmuz, ChatGptEs, PollinationsAI, Copilot, Liaobots, OpenaiChat]) ) gpt_4o_mini = Model( @@ -151,6 +152,12 @@ class VisionModel(Model): ) # o3 +o3_mini = Model( + name = 'o3-mini', + base_provider = 'OpenAI', + best_provider = IterListProvider([Blackbox, CablyAI]) +) + o3_mini_low = Model( name = 'o3-mini-low', base_provider = 'OpenAI', @@ -321,7 +328,7 @@ class VisionModel(Model): gemini_2_0_flash = Model( name = 'gemini-2.0-flash', base_provider = 'Google DeepMind', - best_provider = IterListProvider([GeminiPro, Liaobots]) + best_provider = IterListProvider([PollinationsAI, GeminiPro, Liaobots]) ) gemini_2_0_flash_thinking = Model( @@ -355,7 +362,7 @@ class VisionModel(Model): claude_3_5_sonnet = Model( name = 'claude-3.5-sonnet', base_provider = 'Anthropic', - best_provider = IterListProvider([Jmuz, Liaobots]) + best_provider = IterListProvider([Blackbox, Jmuz, Liaobots]) ) ### Reka AI ### @@ -556,19 +563,19 @@ class VisionModel(Model): flux_pro = ImageModel( name = 'flux-pro', base_provider = 'Black Forest Labs', - best_provider = PollinationsImage + best_provider = PollinationsAI ) flux_dev = ImageModel( name = 'flux-dev', base_provider = 'Black Forest Labs', - best_provider = IterListProvider([HuggingSpace, HuggingChat, HuggingFace]) + best_provider = IterListProvider([PollinationsImage, HuggingSpace, HuggingChat, HuggingFace]) ) flux_schnell = ImageModel( name = 'flux-schnell', base_provider = 'Black Forest Labs', - best_provider = IterListProvider([HuggingSpace, HuggingChat, HuggingFace]) + best_provider = IterListProvider([PollinationsImage, HuggingSpace, HuggingChat, HuggingFace]) ) @@ -610,6 +617,10 @@ class ModelUtils: o1.name: o1, o1_preview.name: o1_preview, o1_mini.name: o1_mini, + + # o3 + o3_mini.name: o3_mini, + o3_mini_low.name: o3_mini_low, ### Meta ### meta.name: meta, @@ -742,11 +753,10 @@ class ModelUtils: demo_models = { gpt_4o.name: [gpt_4o, [PollinationsAI, Blackbox]], - gpt_4o_mini.name: [gpt_4o_mini, [PollinationsAI, CablyAI, DDG]], - deepseek_r1.name: [deepseek_r1, [PollinationsAI, HuggingFace]], "default": [llama_3_2_11b, [HuggingFace]], qwen_2_vl_7b.name: [qwen_2_vl_7b, [HuggingFaceAPI]], qvq_72b.name: [qvq_72b, [HuggingSpace]], + deepseek_r1.name: [deepseek_r1, [HuggingFace]], command_r.name: [command_r, [HuggingSpace]], command_r_plus.name: [command_r_plus, [HuggingSpace]], command_r7b.name: [command_r7b, [HuggingSpace]], @@ -756,7 +766,7 @@ class ModelUtils: llama_3_3_70b.name: [llama_3_3_70b, [HuggingFace]], sd_3_5.name: [sd_3_5, [HuggingSpace, HuggingFace]], flux_dev.name: [flux_dev, [PollinationsImage, HuggingSpace, HuggingFace]], - flux_schnell.name: [flux_schnell, [PollinationsImage, HuggingFace, HuggingSpace]], + flux_schnell.name: [flux_schnell, [HuggingFace, HuggingSpace, PollinationsImage]], } # Create a list of all models and his providers