g4f 6.9.2__py3-none-any.whl → 6.9.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,18 +31,20 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
31
31
  label = "Pollinations AI 🌸"
32
32
  url = "https://pollinations.ai"
33
33
  login_url = "https://enter.pollinations.ai"
34
+ api_key = "pk", "_B9YJX5SBohhm2ePq"
34
35
  active_by_default = True
35
36
  working = True
36
37
  supports_system_message = True
37
38
  supports_message_history = True
38
39
 
39
40
  # API endpoints
40
- text_api_endpoint = "https://g4f.dev/api/pollinations/chat/completions"
41
+ text_api_endpoint = "https://text.pollinations.ai/openai"
41
42
  image_api_endpoint = "https://image.pollinations.ai/prompt/{}"
42
43
  gen_image_api_endpoint = "https://gen.pollinations.ai/image/{}"
43
44
  gen_text_api_endpoint = "https://gen.pollinations.ai/v1/chat/completions"
44
45
  image_models_endpoint = "https://gen.pollinations.ai/image/models"
45
46
  text_models_endpoint = "https://gen.pollinations.ai/text/models"
47
+ BALANCE_ENDPOINT = "https://gen.pollinations.ai/account/balance"
46
48
 
47
49
  # Models configuration
48
50
  default_model = "openai"
@@ -71,6 +73,21 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
71
73
  "flux-kontext": "kontext",
72
74
  }
73
75
  swap_model_aliases = {v: k for k, v in model_aliases.items()}
76
+ balance: Optional[float] = None
77
+
78
+ @classmethod
79
+ def get_balance(cls, api_key: str, timeout: Optional[float] = None) -> Optional[float]:
80
+ try:
81
+ headers = {"authorization": f"Bearer {api_key}"}
82
+ response = requests.get(cls.BALANCE_ENDPOINT, headers=headers, timeout=timeout)
83
+ response.raise_for_status()
84
+ data = response.json()
85
+ cls.balance = float(data.get("balance", 0.0))
86
+ debug.log(f"Pollinations AI balance: {cls.balance:.2f} Pollen")
87
+ return cls.balance
88
+ except Exception as e:
89
+ debug.error(f"Failed to get balance:", e)
90
+ return None
74
91
 
75
92
  @classmethod
76
93
  def get_models(cls, api_key: Optional[str] = None, timeout: Optional[float] = None, **kwargs):
@@ -86,6 +103,14 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
86
103
 
87
104
  if not api_key:
88
105
  api_key = AuthManager.load_api_key(cls)
106
+ if not api_key or api_key.startswith("g4f_") or api_key.startswith("gfs_"):
107
+ api_key = "".join(cls.api_key)
108
+
109
+ if cls.balance or cls.balance is None and cls.get_balance(api_key, timeout) and cls.balance > 0:
110
+ debug.log(f"Authenticated with Pollinations AI using API key.")
111
+ else:
112
+ debug.log(f"Using Pollinations AI without authentication.")
113
+ api_key = None
89
114
 
90
115
  if not cls._free_models_loaded or api_key and not cls._gen_models_loaded:
91
116
  path = Path(get_cookies_dir()) / "models" / datetime.today().strftime('%Y-%m-%d') / f"{cls.__name__}{'-auth' if api_key else ''}.json"
@@ -194,36 +219,36 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
194
219
 
195
220
  @classmethod
196
221
  async def create_async_generator(
197
- cls,
198
- model: str,
199
- messages: Messages,
200
- stream: bool = True,
201
- proxy: str = None,
202
- cache: bool = None,
203
- api_key: str = None,
204
- extra_body: dict = None,
205
- # Image generation parameters
206
- prompt: str = None,
207
- aspect_ratio: str = None,
208
- width: int = None,
209
- height: int = None,
210
- seed: Optional[int] = None,
211
- nologo: bool = True,
212
- private: bool = False,
213
- enhance: bool = None,
214
- safe: bool = False,
215
- transparent: bool = False,
216
- n: int = 1,
217
- # Text generation parameters
218
- media: MediaListType = None,
219
- temperature: float = None,
220
- presence_penalty: float = None,
221
- top_p: float = None,
222
- frequency_penalty: float = None,
223
- response_format: Optional[dict] = None,
224
- extra_parameters: list[str] = ["tools", "parallel_tool_calls", "tool_choice", "reasoning_effort",
225
- "logit_bias", "voice", "modalities", "audio"],
226
- **kwargs
222
+ cls,
223
+ model: str,
224
+ messages: Messages,
225
+ stream: bool = True,
226
+ proxy: str = None,
227
+ cache: bool = None,
228
+ api_key: str = None,
229
+ extra_body: dict = None,
230
+ # Image generation parameters
231
+ prompt: str = None,
232
+ aspect_ratio: str = None,
233
+ width: int = None,
234
+ height: int = None,
235
+ seed: Optional[int] = None,
236
+ nologo: bool = True,
237
+ private: bool = False,
238
+ enhance: bool = None,
239
+ safe: bool = False,
240
+ transparent: bool = False,
241
+ n: int = 1,
242
+ # Text generation parameters
243
+ media: MediaListType = None,
244
+ temperature: float = None,
245
+ presence_penalty: float = None,
246
+ top_p: float = None,
247
+ frequency_penalty: float = None,
248
+ response_format: Optional[dict] = None,
249
+ extra_parameters: list[str] = ["tools", "parallel_tool_calls", "tool_choice", "reasoning_effort",
250
+ "logit_bias", "voice", "modalities", "audio"],
251
+ **kwargs
227
252
  ) -> AsyncResult:
228
253
  if cache is None:
229
254
  cache = kwargs.get("action") != "variant"
@@ -237,7 +262,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
237
262
  has_audio = True
238
263
  break
239
264
  model = "openai-audio" if has_audio else cls.default_model
240
- elif (cls._gen_models_loaded if api_key else cls._free_models_loaded) or cls.get_models(api_key=api_key, timeout=kwargs.get("timeout")):
265
+ if cls.get_models(api_key=api_key, timeout=kwargs.get("timeout")):
241
266
  if model in cls.model_aliases:
242
267
  model = cls.model_aliases[model]
243
268
  debug.log(f"Using model: {model}")
@@ -353,7 +378,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
353
378
  return f"{url}&seed={seed}" if seed else url
354
379
 
355
380
  headers = None
356
- if api_key:
381
+ if api_key and api_key.startswith("g4f_") or api_key.startswith("gfs_"):
357
382
  headers = {"authorization": f"Bearer {api_key}"}
358
383
  async with ClientSession(
359
384
  headers=DEFAULT_HEADERS,
@@ -456,10 +481,12 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
456
481
  **extra_body
457
482
  )
458
483
  headers = None
459
- if api_key:
484
+ if api_key and not api_key.startswith("g4f_") and not api_key.startswith("gfs_"):
460
485
  headers = {"authorization": f"Bearer {api_key}"}
486
+ elif cls.balance > 0:
487
+ headers = {"authorization": f"Bearer {"".join(cls.api_key)}"}
461
488
  yield JsonRequest.from_dict(data)
462
- if api_key and not api_key.startswith("g4f_") and not api_key.startswith("gfs_"):
489
+ if headers:
463
490
  url = cls.gen_text_api_endpoint
464
491
  else:
465
492
  url = cls.text_api_endpoint
g4f/Provider/Qwen.py CHANGED
@@ -336,7 +336,7 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
336
336
  prompt = get_last_user_message(messages)
337
337
  timeout = kwargs.get("timeout") or 5 * 60
338
338
  # for _ in range(2):
339
- # data = generate_cookies()
339
+ data = generate_cookies()
340
340
  # args,ua = await cls.get_args(proxy, **kwargs)
341
341
  headers = {
342
342
  'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36',
@@ -349,10 +349,12 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
349
349
  'Sec-Fetch-Mode': 'cors',
350
350
  'Sec-Fetch-Site': 'same-origin',
351
351
  'Connection': 'keep-alive',
352
- # 'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
353
- 'Authorization': f'Bearer {token}' if token else "Bearer",
354
- 'Source': 'web'
352
+ 'X-Requested-With': 'XMLHttpRequest',
353
+ 'Cookie': f'ssxmod_itna={data["ssxmod_itna"]};ssxmod_itna2={data["ssxmod_itna2"]}',
354
+ 'X-Source': 'web'
355
355
  }
356
+ if token:
357
+ headers['Authorization'] = f'Bearer {token}'
356
358
 
357
359
  # try:
358
360
  async with StreamSession(headers=headers) as session:
@@ -435,16 +437,16 @@ class Qwen(AsyncGeneratorProvider, ProviderModelMixin):
435
437
  "output_schema": "phase",
436
438
  "thinking_budget": 81920
437
439
  },
438
- "extra": {
439
- "meta": {
440
- "subChatType": chat_type
441
- }
442
- },
443
- "sub_chat_type": chat_type,
444
- "parent_id": None
440
+ "sub_chat_type": chat_type
445
441
  }
446
442
  ]
447
443
  }
444
+ if enable_thinking:
445
+ msg_payload["messages"][0]["feature_config"] = {
446
+ "thinking_enabled": True,
447
+ "output_schema": "phase",
448
+ "thinking_budget": 81920
449
+ }
448
450
  if aspect_ratio:
449
451
  msg_payload["size"] = aspect_ratio
450
452
 
@@ -14,7 +14,6 @@ class Ollama(OpenaiTemplate):
14
14
  label = "Ollama 🦙"
15
15
  url = "https://ollama.com"
16
16
  login_url = "https://ollama.com/settings/keys"
17
- backup_url = "https://g4f.dev/api/ollama"
18
17
  needs_auth = False
19
18
  working = True
20
19
  active_by_default = True
@@ -15,7 +15,6 @@ class Azure(OpenaiTemplate):
15
15
  label = "Azure ☁️"
16
16
  url = "https://ai.azure.com"
17
17
  base_url = "https://g4f.dev/api/azure"
18
- backup_url = "https://g4f.dev/api/azure"
19
18
  working = True
20
19
  active_by_default = False
21
20
  login_url = "https://discord.gg/qXA4Wf4Fsm"
@@ -7,7 +7,6 @@ class Groq(OpenaiTemplate):
7
7
  url = "https://console.groq.com/playground"
8
8
  login_url = "https://console.groq.com/keys"
9
9
  base_url = "https://api.groq.com/openai/v1"
10
- backup_url = "https://g4f.dev/api/groq"
11
10
  working = True
12
11
  active_by_default = True
13
12
  default_model = DEFAULT_MODEL
@@ -6,7 +6,6 @@ from ...config import DEFAULT_MODEL
6
6
  class Nvidia(OpenaiTemplate):
7
7
  label = "Nvidia"
8
8
  base_url = "https://integrate.api.nvidia.com/v1"
9
- backup_url = "https://g4f.dev/api/nvidia"
10
9
  login_url = "https://google.com"
11
10
  url = "https://build.nvidia.com"
12
11
  working = True
@@ -13,7 +13,6 @@ class OpenRouter(OpenaiTemplate):
13
13
 
14
14
  class OpenRouterFree(OpenRouter):
15
15
  label = "OpenRouter (free)"
16
- backup_url = "https://g4f.dev/api/openrouter"
17
16
  max_tokens = 4096
18
17
  active_by_default = True
19
18
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: g4f
3
- Version: 6.9.2
3
+ Version: 6.9.4
4
4
  Summary: The official gpt4free repository | various collection of powerful language models
5
5
  Home-page: https://github.com/xtekky/gpt4free
6
6
  Author: Tekky
@@ -23,9 +23,9 @@ g4f/Provider/Mintlify.py,sha256=3Bvy1oh6scg4xs9pw5RY4mmi8XEvQDelnNp664TefbU,7937
23
23
  g4f/Provider/OIVSCodeSer.py,sha256=clebON7Ssd9syewh3BWT59XOeB-WORXF6FPOwbzfRmo,1366
24
24
  g4f/Provider/OperaAria.py,sha256=sLnTOKzbW9BxTxNmHXJ-YDnhPU6Dj6MBdDfqDh-Zz-c,14662
25
25
  g4f/Provider/Perplexity.py,sha256=GUebbVin9hCg4FDei9RX2N6WboFcDDPm061WnnpPRaI,13236
26
- g4f/Provider/PollinationsAI.py,sha256=zM3ZPs_hMqnDejPXwSYdo0vEwrjkYKj5wYtCgKY-PIs,20288
26
+ g4f/Provider/PollinationsAI.py,sha256=nsC2VntGavZJDiaAX0HhbWk6uWwYPTDCFGlnQCEyA4I,21458
27
27
  g4f/Provider/PollinationsImage.py,sha256=wdGY9kbPGlqAkyeJcjXgWOG3HLVPU4QK-JENwg3gmwk,2297
28
- g4f/Provider/Qwen.py,sha256=IPZqfyb4wKYRzOQSTomNGKKtjHdo5oAmqfsy_jkRKGQ,23800
28
+ g4f/Provider/Qwen.py,sha256=XPJHRlobijqjdDGVqA-aVyRx2SeM28zSWf-NmzxJtgE,23876
29
29
  g4f/Provider/Startnest.py,sha256=OocXEAK3pKG-tC_D_chGE7GD22dZr67J1m7JBhLxniM,9526
30
30
  g4f/Provider/StringableInference.py,sha256=ZohMZrVAn6G82zrYpLTvELkzfds4nxu09lx7wizFnbk,999
31
31
  g4f/Provider/TeachAnything.py,sha256=ST87YdOdxtIc5JMaKzGdVy9J9wlhdhYIchRtXBljIBU,2843
@@ -55,11 +55,11 @@ g4f/Provider/hf_space/StabilityAI_SD35Large.py,sha256=-VT4qa_K6MshG2TX6y7k01NMGH
55
55
  g4f/Provider/hf_space/__init__.py,sha256=licdlcuTs0yPwADmjBUA5uoN4ao-FnCUmlKiMWoHJ2g,3602
56
56
  g4f/Provider/hf_space/raise_for_status.py,sha256=xoVwrZSwJUvqQkSfeUAMUst8SyobpSKPux1iYu4SNH0,935
57
57
  g4f/Provider/local/Local.py,sha256=b6vSZcr5CfEXD5GMqNtwCfXNJtKyWKPg3jqBWJEZEwQ,1251
58
- g4f/Provider/local/Ollama.py,sha256=uefFwppGhqkC4WdbbaxktatJKkHaY7_OEkwBY_VSnSU,3816
58
+ g4f/Provider/local/Ollama.py,sha256=ukgvoCSDiXEqhPc6i-awylqiuSnFLpau0uMX9YfsJuA,3770
59
59
  g4f/Provider/local/__init__.py,sha256=cEFsdfkq0bgVAIM__Sxc6WfIoGa3_Ymol26kQb6x14k,73
60
60
  g4f/Provider/needs_auth/AIBadgr.py,sha256=Oc05Cs-x40sF7tcrAyUqyoZ-TbtmV4wnMIm5aEjQ0xw,420
61
61
  g4f/Provider/needs_auth/Anthropic.py,sha256=-8hRSpSGaC3-AzhkuIsf1K1w8ZVKKb_T6Pwy3N8JPak,10200
62
- g4f/Provider/needs_auth/Azure.py,sha256=NMQyNvPN4qwP6bDFDGfXTaW0pvUCQUJGT7M6Yv25miQ,6152
62
+ g4f/Provider/needs_auth/Azure.py,sha256=XPgC4ffl8AitnzQB4K77v2eyXm_rLznz1VUiHIeRqaA,6107
63
63
  g4f/Provider/needs_auth/BingCreateImages.py,sha256=_GrPx7KuttKrQ4IKX0fFwDPVsiCW9xTLycULNClZ6KQ,2066
64
64
  g4f/Provider/needs_auth/BlackboxPro.py,sha256=BA-eiaVGczyB7BHQ47jehq6dTkEslithw1nN2whceZo,270382
65
65
  g4f/Provider/needs_auth/CablyAI.py,sha256=113DsXPXAq3DO2QPHPJ0UJwMpXxomb7BM07RrcV6YQk,1253
@@ -79,13 +79,13 @@ g4f/Provider/needs_auth/GithubCopilot.py,sha256=AUoapqX6lwgC5WPIpKdKdhXcuXo4Stq7
79
79
  g4f/Provider/needs_auth/GithubCopilotAPI.py,sha256=O-8Bq6eWrVZTYFS5QufMDJ9SiSFsd0Pz91yejb6spOI,353
80
80
  g4f/Provider/needs_auth/GlhfChat.py,sha256=qSPKXnQ7igjF6_kiBnFhwq-YAqGmpZg_yu4OMRliSP4,1189
81
81
  g4f/Provider/needs_auth/Grok.py,sha256=3uwt0vjsSNHLZKS2DcUHTztiNqPIemwW82E2x0AQRTw,12884
82
- g4f/Provider/needs_auth/Groq.py,sha256=orlC4C7LDEVA6LU2TsqFw_eDU6XRfUn9080SxLtzhh0,592
82
+ g4f/Provider/needs_auth/Groq.py,sha256=30XyhPJYnZG-_t_gZx8vkLmJK-sYyvUE03edEJjbPbE,548
83
83
  g4f/Provider/needs_auth/LMArena.py,sha256=Jchyimr78hUaHd9ntsdWX76_1uRGfNJJ4RFDcCBdlos,121389
84
84
  g4f/Provider/needs_auth/MetaAI.py,sha256=Bz9pvJUVH7RtCAP1Huvay-EgO057fL362mhx3GtVAqM,10653
85
85
  g4f/Provider/needs_auth/MetaAIAccount.py,sha256=D4LnhAt2MuKx1a4uSgX2lUbQrzAkeIYm8JCnZieZiak,672
86
86
  g4f/Provider/needs_auth/MicrosoftDesigner.py,sha256=4sJdjBPgiW9TEh4CeplCTNPXv6ZtZtFh0SYAiVfnrqk,7178
87
- g4f/Provider/needs_auth/Nvidia.py,sha256=BSIUff39KMC-XyZqwFCrhuH-GMx7lLQEbbH8Ka0J-0Q,437
88
- g4f/Provider/needs_auth/OpenRouter.py,sha256=p64f0aHT52z6y1xaUTIyzfpQ3tDj3WJZpya8816xX7k,900
87
+ g4f/Provider/needs_auth/Nvidia.py,sha256=URMUSrLxUAA9YpI_DsdgQ3QlaOJ0JYRSClmYbTwXWM4,391
88
+ g4f/Provider/needs_auth/OpenRouter.py,sha256=KxALUf-mdoHHdYxEU53Rviyw7DRooFz39UMupDl-9V8,850
89
89
  g4f/Provider/needs_auth/OpenaiAPI.py,sha256=KpJ6qvUlFsFqpQbcwikNYLVsFx6K9h393Pu-yf_uS3g,362
90
90
  g4f/Provider/needs_auth/OpenaiAccount.py,sha256=vSe6Je-DoNbdGGEE-gNaW0Sa81rL8FPMaNyYr1U4PcI,209
91
91
  g4f/Provider/needs_auth/OpenaiChat.py,sha256=dVSm-HAzlvb3KZqZNf0XYFxvIBTfXajKQfe8-JuO-vM,67285
@@ -210,9 +210,9 @@ g4f/tools/files.py,sha256=bUTbeNp8ujTZQiW3GLTtFcgl3-1AnH3cDyIKHfh6Mjc,23397
210
210
  g4f/tools/media.py,sha256=AE9hGVRxQBVZzQ_Ylzeoo2TJUGXSBXO5RbLwj1I2ZTE,4701
211
211
  g4f/tools/run_tools.py,sha256=Yb0osWdDt4wUnkvwln4R6qcLapdddC3n2giZMPXWkzM,16662
212
212
  g4f/tools/web_search.py,sha256=vAZJD-qy15llsgAbkXzoEltqdFB6TlKLbqDJ1DS-6vs,2086
213
- g4f-6.9.2.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
214
- g4f-6.9.2.dist-info/METADATA,sha256=euo_Y837qOz3LcXy0lVO9dfl1_2jtun_nUCIaurAk_I,23255
215
- g4f-6.9.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
216
- g4f-6.9.2.dist-info/entry_points.txt,sha256=J7Usl6dNjXJlvuzGAUEm6cuDXWpVdGq7SfK-tPoiZSI,67
217
- g4f-6.9.2.dist-info/top_level.txt,sha256=bMRlTupWYCcLWy80AnnKZkhpBsXsF8gI3BaMhSZSgRo,4
218
- g4f-6.9.2.dist-info/RECORD,,
213
+ g4f-6.9.4.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
214
+ g4f-6.9.4.dist-info/METADATA,sha256=9L5vKFSberfEmFZECH8m8I9gB6t0Y2jpQvEbFg7qwK0,23255
215
+ g4f-6.9.4.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
216
+ g4f-6.9.4.dist-info/entry_points.txt,sha256=J7Usl6dNjXJlvuzGAUEm6cuDXWpVdGq7SfK-tPoiZSI,67
217
+ g4f-6.9.4.dist-info/top_level.txt,sha256=bMRlTupWYCcLWy80AnnKZkhpBsXsF8gI3BaMhSZSgRo,4
218
+ g4f-6.9.4.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.9.0)
2
+ Generator: setuptools (80.10.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5