返回提交历史
Modified
g4f/Provider/Pi.py
+13
-15
XFEstudio/gpt4free
Add proxy support / fix streaming
cd6ccdd0
代码差异
1 个文件
+13
-15
@@ -23,32 +23,30 @@ class Pi(BaseProvider):
23
23
**kwargs
24
24
) -> CreateResult:
25
25
if not scraper:
26
scraper = cls.get_scraper()
26
scraper = cls.get_scraper(proxy)
27
27
if not conversation:
28
28
conversation = cls.start_conversation(scraper)
29
29
answer = cls.ask(scraper, messages, conversation)
30
31
last_answer = 0
32
30
for line in answer:
33
31
if "text" in line:
34
yield line["text"][last_answer:]
35
last_answer = len(line["text"])
36
37
def get_scraper():
38
scraper = create_scraper(
32
yield line["text"]
33
34
def get_scraper(proxy: str):
35
return create_scraper(
39
36
browser={
40
37
'browser': 'chrome',
41
38
'platform': 'windows',
42
39
'desktop': True
43
40
},
44
sess=session()
41
headers={
42
'Accept': '*/*',
43
'Accept-Encoding': 'deflate,gzip,br',
44
},
45
proxies={
46
"https": proxy
47
}
45
48
)
46
scraper.headers = {
47
'Accept': '*/*',
48
'Accept-Encoding': 'deflate,gzip,br',
49
}
50
return scraper
51
49
52
50
def start_conversation(scraper: CloudScraper):
53
51
response = scraper.post('https://pi.ai/api/chat/start', data="{}", headers={
54
52
'accept': 'application/json',