XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/gpt4free

feat(g4f): Major provider updates and new model support (#2437)

* refactor(g4f/Provider/Airforce.py): Enhance Airforce provider with dynamic model fetching * refactor(g4f/Provider/Blackbox.py): Enhance Blackbox AI provider configuration and streamline code * feat(g4f/Provider/RobocodersAPI.py): Add RobocodersAPI new async chat provider * refactor(g4f/client/__init__.py): Improve provider handling in async_generate method * refactor(g4f/models.py): Update provider configurations for multiple models * refactor(g4f/Provider/Blackbox.py): Streamline model configuration and improve response handling * feat(g4f/Provider/DDG.py): Enhance model support and improve conversation handling * refactor(g4f/Provider/Copilot.py): Enhance Copilot provider with model support * refactor(g4f/Provider/AmigoChat.py): update models and improve code structure * chore(g4f/Provider/not_working/AIUncensored.): move AIUncensored to not_working directory * chore(g4f/Provider/not_working/Allyfy.py): remove Allyfy provider * Update (g4f/Provider/not_working/AIUncensored.py g4f/Provider/not_working/__init__.py) * refactor(g4f/Provider/ChatGptEs.py): Implement format_prompt for message handling * refactor(g4f/Provider/Blackbox.py): Update message formatting and improve code structure * refactor(g4f/Provider/LLMPlayground.py): Enhance text generation and error handling * refactor(g4f/Provider/needs_auth/PollinationsAI.py): move PollinationsAI to needs_auth directory * refactor(g4f/Provider/Liaobots.py): Update Liaobots provider models and aliases * feat(g4f/Provider/DeepInfraChat.py): Add new DeepInfra models and aliases * Update (g4f/Provider/__init__.py) * Update (g4f/models.py) * g4f/models.py * Update g4f/models.py * Update g4f/Provider/LLMPlayground.py * Update (g4f/models.py g4f/Provider/Airforce.py g4f/Provider/__init__.py g4f/Provider/LLMPlayground.py) * Update g4f/Provider/__init__.py * Update (g4f/Provider/Airforce.py) --------- Co-authored-by: kqlio67 <kqlio67@users.noreply.github.com>

8d5d522c
kqlio67 <166700875+kqlio67@users.noreply.github.com>
提交于

代码差异

15 个文件 +462 -282
Modified g4f/Provider/Airforce.py +60 -29
@@ -14,6 +14,19 @@ from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
14 14 from ..image import ImageResponse
15 15 from ..requests import StreamSession, raise_for_status
16 16
17 def split_message(message: str, max_length: int = 1000) -> list[str]:
18 """Splits the message into parts up to (max_length)."""
19 chunks = []
20 while len(message) > max_length:
21 split_point = message.rfind(' ', 0, max_length)
22 if split_point == -1:
23 split_point = max_length
24 chunks.append(message[:split_point])
25 message = message[split_point:].strip()
26 if message:
27 chunks.append(message)
28 return chunks
29
17 30 class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
18 31 url = "https://llmplayground.net"
19 32 api_endpoint_completions = "https://api.airforce/chat/completions"
@@ -84,6 +97,7 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
84 97 # HuggingFaceH4
85 98 "zephyr-7b": "zephyr-7b-beta",
86 99
100
87 101 ### imagine ###
88 102 "sdxl": "stable-diffusion-xl-base",
89 103 "sdxl": "stable-diffusion-xl-lightning",
@@ -125,7 +139,6 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
125 139 "accept": "*/*",
126 140 "accept-language": "en-US,en;q=0.9",
127 141 "cache-control": "no-cache",
128 "origin": "https://llmplayground.net",
129 142 "user-agent": "Mozilla/5.0"
130 143 }
131 144 if seed is None:
@@ -167,35 +180,47 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
167 180 "content-type": "application/json",
168 181 "user-agent": "Mozilla/5.0"
169 182 }
183
184 full_message = "\n".join(
185 [f"{msg['role'].capitalize()}: {msg['content']}" for msg in messages]
186 )
187
188 message_chunks = split_message(full_message, max_length=1000)
189
170 190 async with StreamSession(headers=headers, proxy=proxy) as session:
171 data = {
172 "messages": messages,
173 "model": model,
174 "max_tokens": max_tokens,
175 "temperature": temperature,
176 "top_p": top_p,
177 "stream": stream
178 }
179 async with session.post(cls.api_endpoint_completions, json=data) as response:
180 await raise_for_status(response)
181 content_type = response.headers.get('Content-Type', '').lower()
182 if 'application/json' in content_type:
183 json_data = await response.json()
184 if json_data.get("model") == "error":
185 raise RuntimeError(json_data['choices'][0]['message'].get('content', ''))
186 if stream:
187 async for line in response.iter_lines():
188 if line:
189 line = line.decode('utf-8').strip()
190 if line.startswith("data: ") and line != "data: [DONE]":
191 json_data = json.loads(line[6:])
192 content = json_data['choices'][0]['delta'].get('content', '')
193 if content:
194 yield cls._filter_content(content)
195 else:
196 json_data = await response.json()
197 content = json_data['choices'][0]['message']['content']
198 yield cls._filter_content(content)
191 full_response = ""
192 for chunk in message_chunks:
193 data = {
194 "messages": [{"role": "user", "content": chunk}],
195 "model": model,
196 "max_tokens": max_tokens,
197 "temperature": temperature,
198 "top_p": top_p,
199 "stream": stream
200 }
201
202 async with session.post(cls.api_endpoint_completions, json=data) as response:
203 await raise_for_status(response)
204 content_type = response.headers.get('Content-Type', '').lower()
205
206 if 'application/json' in content_type:
207 json_data = await response.json()
208 if json_data.get("model") == "error":
209 raise RuntimeError(json_data['choices'][0]['message'].get('content', ''))
210 if stream:
211 async for line in response.iter_lines():
212 if line:
213 line = line.decode('utf-8').strip()
214 if line.startswith("data: ") and line != "data: [DONE]":
215 json_data = json.loads(line[6:])
216 content = json_data['choices'][0]['delta'].get('content', '')
217 if content:
218 yield cls._filter_content(content)
219 else:
220 content = json_data['choices'][0]['message']['content']
221 full_response += cls._filter_content(content)
222
223 yield full_response
199 224
200 225 @classmethod
201 226 def _filter_content(cls, part_response: str) -> str:
@@ -210,4 +235,10 @@ class Airforce(AsyncGeneratorProvider, ProviderModelMixin):
210 235 '',
211 236 part_response
212 237 )
238
239 part_response = re.sub(
240 r"\[ERROR\] '\w{8}-\w{4}-\w{4}-\w{4}-\w{12}'", # any-uncensored
241 '',
242 part_response
243 )
213 244 return part_response
Modified g4f/Provider/AmigoChat.py +114 -42
@@ -9,6 +9,69 @@ from ..image import ImageResponse
9 9 from ..requests import StreamSession, raise_for_status
10 10 from ..errors import ResponseStatusError
11 11
12 MODELS = {
13 'chat': {
14 'gpt-4o-2024-11-20': {'persona_id': "gpt"},
15 'gpt-4o': {'persona_id': "summarizer"},
16 'gpt-4o-mini': {'persona_id': "gemini-1-5-flash"},
17
18 'o1-preview-': {'persona_id': "openai-o-one"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
19 'o1-preview-2024-09-12-': {'persona_id': "orion"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
20 'o1-mini-': {'persona_id': "openai-o-one-mini"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
21
22 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo': {'persona_id': "llama-three-point-one"},
23 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo': {'persona_id': "llama-3-2"},
24 'codellama/CodeLlama-34b-Instruct-hf': {'persona_id': "codellama-CodeLlama-34b-Instruct-hf"},
25
26 'gemini-1.5-pro': {'persona_id': "gemini-1-5-pro"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
27 'gemini-1.5-flash': {'persona_id': "amigo"},
28
29 'claude-3-5-sonnet-20240620': {'persona_id': "claude"},
30 'claude-3-5-sonnet-20241022': {'persona_id': "clude-claude-3-5-sonnet-20241022"},
31 'claude-3-5-haiku-latest': {'persona_id': "3-5-haiku"},
32
33 'Qwen/Qwen2.5-72B-Instruct-Turbo': {'persona_id': "qwen-2-5"},
34
35 'google/gemma-2b-it': {'persona_id': "google-gemma-2b-it"},
36 'google/gemma-7b': {'persona_id': "google-gemma-7b"}, # Error handling AIML chat completion stream
37
38 'Gryphe/MythoMax-L2-13b': {'persona_id': "Gryphe-MythoMax-L2-13b"},
39
40 'mistralai/Mistral-7B-Instruct-v0.3': {'persona_id': "mistralai-Mistral-7B-Instruct-v0.1"},
41 'mistralai/mistral-tiny': {'persona_id': "mistralai-mistral-tiny"},
42 'mistralai/mistral-nemo': {'persona_id': "mistralai-mistral-nemo"},
43
44 'deepseek-ai/deepseek-llm-67b-chat': {'persona_id': "deepseek-ai-deepseek-llm-67b-chat"},
45
46 'databricks/dbrx-instruct': {'persona_id': "databricks-dbrx-instruct"},
47
48 'NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO': {'persona_id': "NousResearch-Nous-Hermes-2-Mixtral-8x7B-DPO"},
49
50 'x-ai/grok-beta': {'persona_id': "x-ai-grok-beta"},
51
52 'anthracite-org/magnum-v4-72b': {'persona_id': "anthracite-org-magnum-v4-72b"},
53
54 'cohere/command-r-plus': {'persona_id': "cohere-command-r-plus"},
55
56 'ai21/jamba-1-5-mini': {'persona_id': "ai21-jamba-1-5-mini"},
57
58 'zero-one-ai/Yi-34B': {'persona_id': "zero-one-ai-Yi-34B"} # Error handling AIML chat completion stream
59 },
60
61 'image': {
62 'flux-pro/v1.1': {'persona_id': "flux-1-1-pro"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
63 'flux-realism': {'persona_id': "flux-realism"},
64 'flux-pro': {'persona_id': "flux-pro"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
65 'flux-pro/v1.1-ultra': {'persona_id': "flux-pro-v1.1-ultra"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
66 'flux-pro/v1.1-ultra-raw': {'persona_id': "flux-pro-v1.1-ultra-raw"}, # Amigo, your balance is not enough to make the request, wait until 12 UTC or upgrade your plan
67 'flux/dev': {'persona_id': "flux-dev"},
68
69 'dalle-e-3': {'persona_id': "dalle-three"},
70
71 'recraft-v3': {'persona_id': "recraft"}
72 }
73 }
74
12 75 class AmigoChat(AsyncGeneratorProvider, ProviderModelMixin):
13 76 url = "https://amigochat.io/chat/"
14 77 chat_api_endpoint = "https://api.amigochat.io/v1/chat/completions"
@@ -17,58 +80,67 @@ class AmigoChat(AsyncGeneratorProvider, ProviderModelMixin):
17 80 supports_stream = True
18 81 supports_system_message = True
19 82 supports_message_history = True
20
83
21 84 default_model = 'gpt-4o-mini'
22
23 chat_models = [
24 'gpt-4o',
25 default_model,
26 'o1-preview',
27 'o1-mini',
28 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo',
29 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo',
30 'claude-3-sonnet-20240229',
31 'gemini-1.5-pro',
32 ]
33
34 image_models = [
35 'flux-pro/v1.1',
36 'flux-realism',
37 'flux-pro',
38 'dalle-e-3',
39 ]
40
41 models = [*chat_models, *image_models]
85
86 chat_models = list(MODELS['chat'].keys())
87 image_models = list(MODELS['image'].keys())
88 models = chat_models + image_models
42 89
43 90 model_aliases = {
44 "o1": "o1-preview",
91 ### chat ###
92 "gpt-4o": "gpt-4o-2024-11-20",
93 "gpt-4o-mini": "gpt-4o-mini",
94
45 95 "llama-3.1-405b": "meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo",
46 96 "llama-3.2-90b": "meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
47 "claude-3.5-sonnet": "claude-3-sonnet-20240229",
48 "gemini-pro": "gemini-1.5-pro",
97 "codellama-34b": "codellama/CodeLlama-34b-Instruct-hf",
98
99 "gemini-flash": "gemini-1.5-flash",
100
101 "claude-3.5-sonnet": "claude-3-5-sonnet-20240620",
102 "claude-3.5-sonnet": "claude-3-5-sonnet-20241022",
103 "claude-3.5-haiku": "claude-3-5-haiku-latest",
104
105 "qwen-2.5-72b": "Qwen/Qwen2.5-72B-Instruct-Turbo",
106 "gemma-2b": "google/gemma-2b-it",
107
108 "mythomax-13b": "Gryphe/MythoMax-L2-13b",
109
110 "mixtral-7b": "mistralai/Mistral-7B-Instruct-v0.3",
111 "mistral-tiny": "mistralai/mistral-tiny",
112 "mistral-nemo": "mistralai/mistral-nemo",
113
114 "deepseek-chat": "deepseek-ai/deepseek-llm-67b-chat",
115
116 "dbrx-instruct": "databricks/dbrx-instruct",
117
118 "mixtral-8x7b-dpo": "NousResearch/Nous-Hermes-2-Mixtral-8x7B-DPO",
119
120 "grok-beta": "x-ai/grok-beta",
121
122 "magnum-72b": "anthracite-org/magnum-v4-72b",
123
124 "command-r-plus": "cohere/command-r-plus",
125
126 "jamba-mini": "ai21/jamba-1-5-mini",
127
128
129 ### image ###
130 "flux-realism": "flux-realism",
131 "flux-dev": "flux/dev",
49 132
50 "flux-pro": "flux-pro/v1.1",
51 133 "dalle-3": "dalle-e-3",
52 134 }
53 135
54 persona_ids = {
55 'gpt-4o': "gpt",
56 'gpt-4o-mini': "amigo",
57 'o1-preview': "openai-o-one",
58 'o1-mini': "openai-o-one-mini",
59 'meta-llama/Meta-Llama-3.1-405B-Instruct-Turbo': "llama-three-point-one",
60 'meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo': "llama-3-2",
61 'claude-3-sonnet-20240229': "claude",
62 'gemini-1.5-pro': "gemini-1-5-pro",
63 'flux-pro/v1.1': "flux-1-1-pro",
64 'flux-realism': "flux-realism",
65 'flux-pro': "flux-pro",
66 'dalle-e-3': "dalle-three",
67 }
68
69 136 @classmethod
70 137 def get_personaId(cls, model: str) -> str:
71 return cls.persona_ids[model]
138 if model in cls.chat_models:
139 return MODELS['chat'][model]['persona_id']
140 elif model in cls.image_models:
141 return MODELS['image'][model]['persona_id']
142 else:
143 raise ValueError(f"Unknown model: {model}")
72 144
73 145 @classmethod
74 146 async def create_async_generator(
@@ -110,7 +182,7 @@ class AmigoChat(AsyncGeneratorProvider, ProviderModelMixin):
110 182 "x-device-language": "en-US",
111 183 "x-device-platform": "web",
112 184 "x-device-uuid": device_uuid,
113 "x-device-version": "1.0.41"
185 "x-device-version": "1.0.42"
114 186 }
115 187
116 188 async with StreamSession(headers=headers, proxy=proxy) as session:
Modified g4f/Provider/Blackbox.py +7 -2
@@ -11,6 +11,8 @@ from ..typing import AsyncResult, Messages, ImageType
11 11 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
12 12 from ..image import ImageResponse, to_data_uri
13 13
14 from .helper import format_prompt
15
14 16 class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
15 17 label = "Blackbox AI"
16 18 url = "https://www.blackbox.ai"
@@ -37,7 +39,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
37 39 "gemini-1.5-flash": {'mode': True, 'id': 'Gemini'},
38 40 "llama-3.1-8b": {'mode': True, 'id': "llama-3.1-8b"},
39 41 'llama-3.1-70b': {'mode': True, 'id': "llama-3.1-70b"},
40 'llama-3.1-405b': {'mode': True, 'id': "llama-3.1-405"},
42 'llama-3.1-405b': {'mode': True, 'id': "llama-3.1-405"},
41 43 #
42 44 'Python Agent': {'mode': True, 'id': "Python Agent"},
43 45 'Java Agent': {'mode': True, 'id': "Java Agent"},
@@ -62,7 +64,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
62 64 'Go Agent': {'mode': True, 'id': "Go Agent"},
63 65 'Gitlab Agent': {'mode': True, 'id': "Gitlab Agent"},
64 66 'Git Agent': {'mode': True, 'id': "Git Agent"},
65 'Flask Agent': {'mode': True, 'id': "Flask Agent"},
67 'Flask Agent': {'mode': True, 'id': "Flask Agent"},
66 68 'Firebase Agent': {'mode': True, 'id': "Firebase Agent"},
67 69 'FastAPI Agent': {'mode': True, 'id': "FastAPI Agent"},
68 70 'Erlang Agent': {'mode': True, 'id': "Erlang Agent"},
@@ -165,6 +167,9 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
165 167 message_id = cls.generate_id()
166 168 messages = cls.add_prefix_to_messages(messages, model)
167 169 validated_value = await cls.fetch_validated()
170 formatted_message = format_prompt(messages)
171
172 messages = [{"id": message_id, "content": formatted_message, "role": "user"}]
168 173
169 174 if image is not None:
170 175 messages[-1]['data'] = {
Modified g4f/Provider/ChatGptEs.py +3 -1
@@ -56,6 +56,8 @@ class ChatGptEs(AsyncGeneratorProvider, ProviderModelMixin):
56 56 nonce_ = re.findall(r'data-nonce="(.+?)"', await initial_response.text())[0]
57 57 post_id = re.findall(r'data-post-id="(.+?)"', await initial_response.text())[0]
58 58
59 formatted_prompt = format_prompt(messages)
60
59 61 conversation_history = [
60 62 "Human: You are a helpful AI assistant. Please respond in the same language that the user uses in their message. Provide accurate, relevant and helpful information while maintaining a friendly and professional tone. If you're not sure about something, please acknowledge that and provide the best information you can while noting any uncertainties. Focus on being helpful while respecting the user's choice of language."
61 63 ]
@@ -71,7 +73,7 @@ class ChatGptEs(AsyncGeneratorProvider, ProviderModelMixin):
71 73 'post_id': post_id,
72 74 'url': cls.url,
73 75 'action': 'wpaicg_chat_shortcode_message',
74 'message': messages[-1]['content'],
76 'message': formatted_prompt,
75 77 'bot_id': '0',
76 78 'chatbot_identity': 'shortcode',
77 79 'wpaicg_chat_client_id': os.urandom(5).hex(),
Modified g4f/Provider/Copilot.py +8 -4
@@ -17,13 +17,13 @@ try:
17 17 except ImportError:
18 18 has_nodriver = False
19 19
20 from .base_provider import AbstractProvider, BaseConversation
20 from .base_provider import AbstractProvider, ProviderModelMixin, BaseConversation
21 21 from .helper import format_prompt
22 22 from ..typing import CreateResult, Messages, ImageType
23 23 from ..errors import MissingRequirementsError
24 24 from ..requests.raise_for_status import raise_for_status
25 25 from ..providers.asyncio import get_running_loop
26 from ..Provider.openai.har_file import NoValidHarFileError, get_headers, get_har_files
26 from .openai.har_file import NoValidHarFileError, get_headers
27 27 from ..requests import get_nodriver
28 28 from ..image import ImageResponse, to_bytes, is_accepted_format
29 29 from .. import debug
@@ -38,12 +38,16 @@ class Conversation(BaseConversation):
38 38 self.cookie_jar = cookie_jar
39 39 self.access_token = access_token
40 40
41 class Copilot(AbstractProvider):
41 class Copilot(AbstractProvider, ProviderModelMixin):
42 42 label = "Microsoft Copilot"
43 43 url = "https://copilot.microsoft.com"
44 44 working = True
45 45 supports_stream = True
46 46 default_model = "Copilot"
47 models = [default_model]
48 model_aliases = {
49 "gpt-4": "Copilot",
50 }
47 51
48 52 websocket_url = "wss://copilot.microsoft.com/c/api/chat?api-version=2"
49 53 conversation_url = f"{url}/c/api/conversations"
@@ -209,4 +213,4 @@ def readHAR():
209 213 if api_key is None:
210 214 raise NoValidHarFileError("No access token found in .har files")
211 215
212 return api_key, cookies
216 return api_key, cookies
Modified g4f/Provider/DDG.py +23 -9
@@ -18,7 +18,8 @@ MODELS = [
18 18 {"model":"claude-3-opus-20240229","modelName":"Claude 3","modelVariant":"Opus","modelStyleId":"claude-3-haiku","createdBy":"Anthropic","moderationLevel":"HIGH","isAvailable":1,"inputCharLimit":16e3,"settingId":"2"},
19 19 {"model":"claude-3-haiku-20240307","modelName":"Claude 3","modelVariant":"Haiku","modelStyleId":"claude-3-haiku","createdBy":"Anthropic","moderationLevel":"HIGH","isAvailable":0,"inputCharLimit":16e3,"settingId":"1"},
20 20 {"model":"meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo","modelName":"Llama 3.1","modelVariant":"70B","modelStyleId":"llama-3","createdBy":"Meta","moderationLevel":"MEDIUM","isAvailable":0,"isOpenSource":0,"inputCharLimit":16e3,"settingId":"5"},
21 {"model":"mistralai/Mixtral-8x7B-Instruct-v0.1","modelName":"Mixtral","modelVariant":"8x7B","modelStyleId":"mixtral","createdBy":"Mistral AI","moderationLevel":"LOW","isAvailable":0,"isOpenSource":0,"inputCharLimit":16e3,"settingId":"6"}
21 {"model":"mistralai/Mixtral-8x7B-Instruct-v0.1","modelName":"Mixtral","modelVariant":"8x7B","modelStyleId":"mixtral","createdBy":"Mistral AI","moderationLevel":"LOW","isAvailable":0,"isOpenSource":0,"inputCharLimit":16e3,"settingId":"6"},
22 {"model":"Qwen/Qwen2.5-Coder-32B-Instruct","modelName":"Qwen 2.5 Coder","modelVariant":"32B","modelStyleId":"qwen","createdBy":"Alibaba Cloud","moderationLevel":"LOW","isAvailable":0,"isOpenSource":1,"inputCharLimit":16e3,"settingId":"90"}
22 23 ]
23 24
24 25 class Conversation(BaseConversation):
@@ -29,7 +30,7 @@ class Conversation(BaseConversation):
29 30 self.model = model
30 31
31 32 class DDG(AsyncGeneratorProvider, ProviderModelMixin):
32 url = "https://duckduckgo.com"
33 url = "https://duckduckgo.com/aichat"
33 34 api_endpoint = "https://duckduckgo.com/duckchat/v1/chat"
34 35 working = True
35 36 supports_stream = True
@@ -42,7 +43,7 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
42 43 "claude-3-haiku": "claude-3-haiku-20240307",
43 44 "llama-3.1-70b": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
44 45 "mixtral-8x7b": "mistralai/Mixtral-8x7B-Instruct-v0.1",
45 "gpt-4": "gpt-4o-mini"
46 "gpt-4": "gpt-4o-mini",
46 47 }
47 48
48 49 @classmethod
@@ -75,7 +76,9 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
75 76 if conversation is None:
76 77 conversation = Conversation(model)
77 78 is_new_conversation = True
79
78 80 debug.last_model = model
81
79 82 if conversation.vqd is None:
80 83 conversation.vqd = await cls.get_vqd(proxy, connector)
81 84 if not conversation.vqd:
@@ -87,24 +90,35 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
87 90 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36',
88 91 'x-vqd-4': conversation.vqd,
89 92 }
93
90 94 async with ClientSession(headers=headers, connector=get_connector(connector, proxy)) as session:
91 95 if is_new_conversation:
92 96 conversation.message_history = [{"role": "user", "content": format_prompt(messages)}]
93 97 else:
94 conversation.message_history = [
95 *conversation.message_history,
96 messages[-2],
97 messages[-1]
98 ]
98 if len(messages) >= 2:
99 conversation.message_history = [
100 *conversation.message_history,
101 messages[-2],
102 messages[-1]
103 ]
104 elif len(messages) == 1:
105 conversation.message_history = [
106 *conversation.message_history,
107 messages[-1]
108 ]
109
99 110 if return_conversation:
100 111 yield conversation
112
101 113 data = {
102 114 "model": conversation.model,
103 115 "messages": conversation.message_history
104 116 }
117
105 118 async with session.post(cls.api_endpoint, json=data) as response:
106 119 conversation.vqd = response.headers.get("x-vqd-4")
107 120 await raise_for_status(response)
121
108 122 async for line in response.content:
109 123 if line:
110 124 decoded_line = line.decode('utf-8')
@@ -117,4 +131,4 @@ class DDG(AsyncGeneratorProvider, ProviderModelMixin):
117 131 if 'message' in json_data:
118 132 yield json_data['message']
119 133 except json.JSONDecodeError:
120 pass
134 pass
Modified g4f/Provider/DeepInfraChat.py +4 -0
@@ -20,12 +20,16 @@ class DeepInfraChat(AsyncGeneratorProvider, ProviderModelMixin):
20 20 default_model,
21 21 'microsoft/WizardLM-2-8x22B',
22 22 'Qwen/Qwen2.5-72B-Instruct',
23 'Qwen/Qwen2.5-Coder-32B-Instruct',
24 'nvidia/Llama-3.1-Nemotron-70B-Instruct',
23 25 ]
24 26 model_aliases = {
25 27 "llama-3.1-8b": "meta-llama/Meta-Llama-3.1-8B-Instruct",
26 28 "llama-3.1-70b": "meta-llama/Meta-Llama-3.1-70B-Instruct-Turbo",
27 29 "wizardlm-2-8x22b": "microsoft/WizardLM-2-8x22B",
28 30 "qwen-2-72b": "Qwen/Qwen2.5-72B-Instruct",
31 "qwen-2.5-coder-32b": "Qwen2.5-Coder-32B-Instruct",
32 "nemotron-70b": "nvidia/Llama-3.1-Nemotron-70B-Instruct",
29 33 }
30 34
31 35
Modified g4f/Provider/Liaobots.py +32 -62
@@ -18,24 +18,6 @@ models = {
18 18 "tokenLimit": 7800,
19 19 "context": "8K",
20 20 },
21 "gpt-4o-mini": {
22 "id": "gpt-4o-mini",
23 "name": "GPT-4o-Mini",
24 "model": "ChatGPT",
25 "provider": "OpenAI",
26 "maxLength": 260000,
27 "tokenLimit": 126000,
28 "context": "128K",
29 },
30 "gpt-4o-free": {
31 "id": "gpt-4o-free",
32 "name": "GPT-4o-free",
33 "model": "ChatGPT",
34 "provider": "OpenAI",
35 "maxLength": 31200,
36 "tokenLimit": 7800,
37 "context": "8K",
38 },
39 21 "gpt-4o-2024-08-06": {
40 22 "id": "gpt-4o-2024-08-06",
41 23 "name": "GPT-4o",
@@ -45,36 +27,36 @@ models = {
45 27 "tokenLimit": 126000,
46 28 "context": "128K",
47 29 },
48 "gpt-4-turbo-2024-04-09": {
49 "id": "gpt-4-turbo-2024-04-09",
50 "name": "GPT-4-Turbo",
30 "gpt-4o-mini-2024-07-18": {
31 "id": "gpt-4o-mini-2024-07-18",
32 "name": "GPT-4o-Mini",
51 33 "model": "ChatGPT",
52 34 "provider": "OpenAI",
53 35 "maxLength": 260000,
54 36 "tokenLimit": 126000,
55 37 "context": "128K",
56 38 },
57 "grok-beta": {
58 "id": "grok-beta",
59 "name": "Grok-Beta",
60 "model": "Grok",
61 "provider": "x.ai",
39 "o1-preview": {
40 "id": "o1-preview",
41 "name": "o1-preview",
42 "model": "o1",
43 "provider": "OpenAI",
62 44 "maxLength": 400000,
63 45 "tokenLimit": 100000,
64 "context": "100K",
46 "context": "128K",
65 47 },
66 "grok-2": {
67 "id": "grok-2",
68 "name": "Grok-2",
69 "model": "Grok",
70 "provider": "x.ai",
48 "o1-mini": {
49 "id": "o1-mini",
50 "name": "o1-mini",
51 "model": "o1",
52 "provider": "OpenAI",
71 53 "maxLength": 400000,
72 54 "tokenLimit": 100000,
73 "context": "100K",
55 "context": "128K",
74 56 },
75 "grok-2-mini": {
76 "id": "grok-2-mini",
77 "name": "Grok-2-mini",
57 "grok-beta": {
58 "id": "grok-beta",
59 "name": "Grok-Beta",
78 60 "model": "Grok",
79 61 "provider": "x.ai",
80 62 "maxLength": 400000,
@@ -90,15 +72,6 @@ models = {
90 72 "tokenLimit": 200000,
91 73 "context": "200K",
92 74 },
93 "claude-3-opus-20240229-aws": {
94 "id": "claude-3-opus-20240229-aws",
95 "name": "Claude-3-Opus-Aws",
96 "model": "Claude",
97 "provider": "Anthropic",
98 "maxLength": 800000,
99 "tokenLimit": 200000,
100 "context": "200K",
101 },
102 75 "claude-3-5-sonnet-20240620": {
103 76 "id": "claude-3-5-sonnet-20240620",
104 77 "name": "Claude-3.5-Sonnet",
@@ -126,18 +99,18 @@ models = {
126 99 "tokenLimit": 200000,
127 100 "context": "200K",
128 101 },
129 "claude-3-haiku-20240307": {
130 "id": "claude-3-haiku-20240307",
131 "name": "Claude-3-Haiku",
102 "claude-3-opus-20240229-t": {
103 "id": "claude-3-opus-20240229-t",
104 "name": "Claude-3-Opus-T",
132 105 "model": "Claude",
133 106 "provider": "Anthropic",
134 107 "maxLength": 800000,
135 108 "tokenLimit": 200000,
136 109 "context": "200K",
137 110 },
138 "claude-2.1": {
139 "id": "claude-2.1",
140 "name": "Claude-2.1-200k",
111 "claude-3-5-sonnet-20241022-t": {
112 "id": "claude-3-5-sonnet-20241022-t",
113 "name": "Claude-3.5-Sonnet-V2-T",
141 114 "model": "Claude",
142 115 "provider": "Anthropic",
143 116 "maxLength": 800000,
@@ -155,13 +128,13 @@ models = {
155 128 },
156 129 "gemini-1.5-pro-002": {
157 130 "id": "gemini-1.5-pro-002",
158 "name": "Gemini-1.5-Pro-1M",
131 "name": "Gemini-1.5-Pro-1M",
159 132 "model": "Gemini",
160 133 "provider": "Google",
161 134 "maxLength": 4000000,
162 135 "tokenLimit": 1000000,
163 136 "context": "1024K",
164 },
137 }
165 138 }
166 139
167 140
@@ -175,22 +148,19 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
175 148
176 149 model_aliases = {
177 150 "gpt-4o-mini": "gpt-4o-mini-free",
178 "gpt-4o": "gpt-4o-free",
179 151 "gpt-4o": "gpt-4o-2024-08-06",
180
181 "gpt-4-turbo": "gpt-4-turbo-2024-04-09",
182 "gpt-4": "gpt-4o-mini-free",
152 "gpt-4o-mini": "gpt-4o-mini-2024-07-18",
153 "gpt-4": "gpt-4o-2024-08-06",
183 154
184 155 "claude-3-opus": "claude-3-opus-20240229",
185 "claude-3-opus": "claude-3-opus-20240229-aws",
186 "claude-3-sonnet": "claude-3-sonnet-20240229",
187 156 "claude-3.5-sonnet": "claude-3-5-sonnet-20240620",
188 157 "claude-3.5-sonnet": "claude-3-5-sonnet-20241022",
189 "claude-3-haiku": "claude-3-haiku-20240307",
190 "claude-2.1": "claude-2.1",
158 "claude-3-sonnet": "claude-3-sonnet-20240229",
159 "claude-3-opus": "claude-3-opus-20240229-t",
160 "claude-3.5-sonnet": "claude-3-5-sonnet-20241022-t",
191 161
192 162 "gemini-flash": "gemini-1.5-flash-002",
193 "gemini-pro": "gemini-1.5-pro-002",
163 "gemini-pro": "gemini-1.5-pro-002"
194 164 }
195 165
196 166 _auth_code = ""
Modified g4f/Provider/__init__.py +0 -2
@@ -11,7 +11,6 @@ from .needs_auth import *
11 11 from .not_working import *
12 12 from .local import *
13 13
14 from .AIUncensored import AIUncensored
15 14 from .Airforce import Airforce
16 15 from .AmigoChat import AmigoChat
17 16 from .Blackbox import Blackbox
@@ -31,7 +30,6 @@ from .MagickPen import MagickPen
31 30 from .PerplexityLabs import PerplexityLabs
32 31 from .Pi import Pi
33 32 from .Pizzagpt import Pizzagpt
34 from .PollinationsAI import PollinationsAI
35 33 from .Prodia import Prodia
36 34 from .Reka import Reka
37 35 from .ReplicateHome import ReplicateHome
Renamed g4f/Provider/needs_auth/PollinationsAI.py +7 -7
@@ -5,12 +5,12 @@ import random
5 5 import requests
6 6 from aiohttp import ClientSession
7 7
8 from ..typing import AsyncResult, Messages
9 from ..image import ImageResponse
10 from ..requests.raise_for_status import raise_for_status
11 from ..requests.aiohttp import get_connector
12 from .needs_auth.OpenaiAPI import OpenaiAPI
13 from .helper import format_prompt
8 from ...typing import AsyncResult, Messages
9 from ...image import ImageResponse
10 from ...requests.raise_for_status import raise_for_status
11 from ...requests.aiohttp import get_connector
12 from .OpenaiAPI import OpenaiAPI
13 from ..helper import format_prompt
14 14
15 15 class PollinationsAI(OpenaiAPI):
16 16 label = "Pollinations.AI"
@@ -66,4 +66,4 @@ class PollinationsAI(OpenaiAPI):
66 66 async for chunk in super().create_async_generator(
67 67 model, messages, api_base=api_base, proxy=proxy, **kwargs
68 68 ):
69 yield chunk
69 yield chunk
Modified g4f/Provider/needs_auth/__init__.py +1 -0
@@ -17,6 +17,7 @@ from .OpenaiAPI import OpenaiAPI
17 17 from .OpenaiChat import OpenaiChat
18 18 from .PerplexityApi import PerplexityApi
19 19 from .Poe import Poe
20 from .PollinationsAI import PollinationsAI
20 21 from .Raycast import Raycast
21 22 from .Replicate import Replicate
22 23 from .Theb import Theb
Renamed g4f/Provider/not_working/AIUncensored.py +4 -4
@@ -6,9 +6,9 @@ from aiohttp import ClientSession, ClientError
6 6 import asyncio
7 7 from itertools import cycle
8 8
9 from ..typing import AsyncResult, Messages
10 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
11 from ..image import ImageResponse
9 from ...typing import AsyncResult, Messages
10 from ..base_provider import AsyncGeneratorProvider, ProviderModelMixin
11 from ...image import ImageResponse
12 12
13 13 class AIUncensored(AsyncGeneratorProvider, ProviderModelMixin):
14 14 url = "https://www.aiuncensored.info/ai_uncensored"
@@ -22,7 +22,7 @@ class AIUncensored(AsyncGeneratorProvider, ProviderModelMixin):
22 22 "https://twitterclone-i0wr.onrender.com/api/image",
23 23 "https://twitterclone-8wd1.onrender.com/api/image",
24 24 ]
25 working = True
25 working = False
26 26 supports_stream = True
27 27 supports_system_message = True
28 28 supports_message_history = True
Deleted g4f/Provider/not_working/Allyfy.py +0 -87
Modified g4f/Provider/not_working/__init__.py +1 -0
Modified g4f/models.py +198 -33