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

XFEstudio/gpt4free

Add Reasoning in PerplexityLabs, update model list

9bec1102
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +36 -35
Modified g4f/Provider/PerplexityLabs.py +27 -18
@@ -5,6 +5,7 @@ import json
5 5
6 6 from ..typing import AsyncResult, Messages
7 7 from ..requests import StreamSession, raise_for_status
8 from ..providers.response import Reasoning, FinishReason
8 9 from .base_provider import AsyncGeneratorProvider, ProviderModelMixin
9 10
10 11 API_URL = "https://www.perplexity.ai/socket.io/"
@@ -13,25 +14,16 @@ WS_URL = "wss://www.perplexity.ai/socket.io/"
13 14 class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
14 15 url = "https://labs.perplexity.ai"
15 16 working = True
16 default_model = "llama-3.1-70b-instruct"
17
18 default_model = "sonar-pro"
17 19 models = [
18 "llama-3.1-sonar-large-128k-online",
19 "llama-3.1-sonar-small-128k-online",
20 "llama-3.1-sonar-large-128k-chat",
21 "llama-3.1-sonar-small-128k-chat",
22 "llama-3.1-8b-instruct",
23 "llama-3.1-70b-instruct",
24 "llama-3.3-70b-instruct",
25 "/models/LiquidCloud",
20 default_model,
21 "sonar",
22 "sonar-reasoning",
26 23 ]
27
28 24 model_aliases = {
29 "sonar-online": "llama-3.1-sonar-large-128k-online",
30 "sonar-chat": "llama-3.1-sonar-large-128k-chat",
31 "llama-3.3-70b": "llama-3.3-70b-instruct",
32 "llama-3.1-8b": "llama-3.1-8b-instruct",
33 "llama-3.1-70b": "llama-3.1-70b-instruct",
34 "lfm-40b": "/models/LiquidCloud",
25 "sonar-online": default_model,
26 "sonar-chat": default_model,
35 27 }
36 28
37 29 @classmethod
@@ -78,13 +70,14 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
78 70 assert(await ws.receive_str())
79 71 assert(await ws.receive_str() == "6")
80 72 message_data = {
81 "version": "2.13",
73 "version": "2.16",
82 74 "source": "default",
83 75 "model": model,
84 76 "messages": messages
85 77 }
86 78 await ws.send_str("42" + json.dumps(["perplexity_labs", message_data]))
87 79 last_message = 0
80 is_thinking = False
88 81 while True:
89 82 message = await ws.receive_str()
90 83 if message == "2":
@@ -94,9 +87,25 @@ class PerplexityLabs(AsyncGeneratorProvider, ProviderModelMixin):
94 87 continue
95 88 try:
96 89 data = json.loads(message[2:])[1]
97 yield data["output"][last_message:]
90 new_content = data["output"][last_message:]
91
92 if "<think>" in new_content:
93 yield Reasoning(None, "thinking")
94 is_thinking = True
95 if "</think>" in new_content:
96 new_content = new_content.split("</think>", 1)
97 yield Reasoning(f"{new_content[0]}</think>")
98 yield Reasoning(None, "finished")
99 yield new_content[1]
100 is_thinking = False
101 elif is_thinking:
102 yield Reasoning(new_content)
103 else:
104 yield new_content
105
98 106 last_message = len(data["output"])
99 107 if data["final"]:
108 yield FinishReason("stop")
100 109 break
101 110 except:
102 111 raise RuntimeError(f"Message: {message}")
Modified g4f/models.py +9 -17
@@ -198,13 +198,13 @@ llama_3_70b = Model(
198 198 llama_3_1_8b = Model(
199 199 name = "llama-3.1-8b",
200 200 base_provider = "Meta Llama",
201 best_provider = IterListProvider([Blackbox, DeepInfraChat, Jmuz, PollinationsAI, Cloudflare, PerplexityLabs])
201 best_provider = IterListProvider([Blackbox, DeepInfraChat, Jmuz, PollinationsAI, Cloudflare])
202 202 )
203 203
204 204 llama_3_1_70b = Model(
205 205 name = "llama-3.1-70b",
206 206 base_provider = "Meta Llama",
207 best_provider = IterListProvider([DDG, Jmuz, Blackbox, TeachAnything, DarkAI, PerplexityLabs])
207 best_provider = IterListProvider([DDG, Jmuz, Blackbox, TeachAnything, DarkAI])
208 208 )
209 209
210 210 llama_3_1_405b = Model(
@@ -242,7 +242,7 @@ llama_3_2_90b = Model(
242 242 llama_3_3_70b = Model(
243 243 name = "llama-3.3-70b",
244 244 base_provider = "Meta Llama",
245 best_provider = IterListProvider([Blackbox, DeepInfraChat, PollinationsAI, AutonomousAI, Jmuz, HuggingChat, HuggingFace, PerplexityLabs])
245 best_provider = IterListProvider([Blackbox, DeepInfraChat, PollinationsAI, AutonomousAI, Jmuz, HuggingChat, HuggingFace])
246 246 )
247 247
248 248 ### Mistral ###
@@ -484,14 +484,14 @@ grok_2 = Model(
484 484 )
485 485
486 486 ### Perplexity AI ###
487 sonar_online = Model(
488 name = 'sonar-online',
487 sonar = Model(
488 name = 'sonar',
489 489 base_provider = 'Perplexity AI',
490 490 best_provider = PerplexityLabs
491 491 )
492 492
493 sonar_chat = Model(
494 name = 'sonar-chat',
493 sonar_pro = Model(
494 name = 'sonar-pro',
495 495 base_provider = 'Perplexity AI',
496 496 best_provider = PerplexityLabs
497 497 )
@@ -503,13 +503,6 @@ nemotron_70b = Model(
503 503 best_provider = IterListProvider([DeepInfraChat, HuggingChat, HuggingFace])
504 504 )
505 505
506 ### Liquid ###
507 lfm_40b = Model(
508 name = 'lfm-40b',
509 base_provider = 'Liquid',
510 best_provider = PerplexityLabs
511 )
512
513 506 ### Databricks ###
514 507 dbrx_instruct = Model(
515 508 name = 'dbrx-instruct',
@@ -736,15 +729,14 @@ class ModelUtils:
736 729 grok_2.name: grok_2,
737 730
738 731 ### Perplexity AI ###
739 sonar_online.name: sonar_online,
740 sonar_chat.name: sonar_chat,
732 sonar.name: sonar,
733 sonar_pro.name: sonar_pro,
741 734
742 735 ### DeepSeek ###
743 736 deepseek_chat.name: deepseek_chat,
744 737 deepseek_r1.name: deepseek_r1,
745 738
746 739 nemotron_70b.name: nemotron_70b, ### Nvidia ###
747 lfm_40b.name: lfm_40b, ### Liquid ###
748 740 dbrx_instruct.name: dbrx_instruct, ### Databricks ###
749 741 p1.name: p1, ### PollinationsAI ###
750 742 cably_80b.name: cably_80b, ### CablyAI ###