返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+22
-7
Modified
g4f/Provider/hf_space/Phi_4.py
+1
-1
XFEstudio/gpt4free
Update PollinationsAI provider
6f07ce45
代码差异
2 个文件
+23
-8
@@ -17,9 +17,18 @@ from ..providers.response import ImageResponse, ImagePreview, FinishReason, Usag
17
17
from .. import debug
18
18
19
19
DEFAULT_HEADERS = {
20
'Accept': '*/*',
21
'Accept-Language': 'en-US,en;q=0.9',
22
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36',
20
"accept": "*/*",
21
'accept-language': 'en-US,en;q=0.9',
22
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
23
"priority": "u=1, i",
24
"sec-ch-ua": "\"Not(A:Brand\";v=\"99\", \"Google Chrome\";v=\"133\", \"Chromium\";v=\"133\"",
25
"sec-ch-ua-mobile": "?0",
26
"sec-ch-ua-platform": "\"Linux\"",
27
"sec-fetch-dest": "empty",
28
"sec-fetch-mode": "cors",
29
"sec-fetch-site": "same-site",
30
"referer": "https://pollinations.ai/",
31
"origin": "https://pollinations.ai",
23
32
}
24
33
25
34
class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
@@ -273,7 +282,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
273
282
if "gemini" in model:
274
283
data.pop("seed")
275
284
if model in cls.audio_models:
276
data["voice"] = random.choice(cls.audio_models[model])
285
#data["voice"] = random.choice(cls.audio_models[model])
277
286
url = cls.text_api_endpoint
278
287
else:
279
288
url = cls.openai_endpoint
@@ -282,17 +291,23 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
282
291
if response.headers["content-type"] == "audio/mpeg":
283
292
yield Audio(await response.read())
284
293
return
294
elif response.headers["content-type"].startswith("text/plain"):
295
yield await response.text()
296
return
285
297
result = await response.json()
286
298
choice = result["choices"][0]
287
299
message = choice.get("message", {})
288
300
content = message.get("content", "")
289
301
302
if "</think>" in content and "<think>" not in content:
303
yield "<think>"
304
290
305
if content:
291
306
yield content.replace("\\(", "(").replace("\\)", ")")
292
307
293
308
if "usage" in result:
294
309
yield Usage(**result["usage"])
295
310
296
311
finish_reason = choice.get("finish_reason")
297
312
if finish_reason:
298
313
yield FinishReason(finish_reason)
@@ -152,7 +152,7 @@ class Phi_4(AsyncGeneratorProvider, ProviderModelMixin):
152
152
json_data = json.loads(line[6:])
153
153
if json_data.get('msg') == 'process_completed':
154
154
if 'output' in json_data and 'error' in json_data['output']:
155
raise ResponseError("Missing images input" if json_data['output']['error'] and "AttributeError" in json_data['output']['error'] else json_data['output']['error'])
155
raise ResponseError(json_data['output']['error'])
156
156
if 'output' in json_data and 'data' in json_data['output']:
157
157
yield json_data['output']['data'][0][-1]["content"]
158
158
break