返回提交历史
Modified
g4f/Provider/ChatGpt.py
+1
-0
Modified
g4f/Provider/Copilot.py
+2
-9
Modified
g4f/Provider/needs_auth/OpenaiChat.py
+3
-3
Modified
g4f/Provider/openai/har_file.py
+6
-2
Modified
g4f/client/__init__.py
+2
-2
Modified
g4f/client/service.py
+3
-3
Modified
g4f/gui/client/static/css/style.css
+1
-0
XFEstudio/gpt4free
Sort .har files by date, filter None from result
4ae3d98d
代码差异
7 个文件
+18
-19
@@ -205,6 +205,7 @@ class ChatGpt(AbstractProvider, ProviderModelMixin):
205
205
206
206
response = session.post('https://chatgpt.com/backend-anon/conversation',
207
207
headers=headers, json=json_data, stream=True)
208
response.raise_for_status()
208
209
209
210
replace = ''
210
211
for line in response.iter_lines():
@@ -23,7 +23,7 @@ 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
26
from ..Provider.openai.har_file import NoValidHarFileError, get_headers, get_har_files
27
27
from ..requests import get_nodriver
28
28
from ..image import ImageResponse, to_bytes, is_accepted_format
29
29
from ..cookies import get_cookies_dir
@@ -188,16 +188,9 @@ class Copilot(AbstractProvider):
188
188
return access_token, cookies
189
189
190
190
def readHAR():
191
harPath = []
192
for root, _, files in os.walk(get_cookies_dir()):
193
for file in files:
194
if file.endswith(".har"):
195
harPath.append(os.path.join(root, file))
196
if not harPath:
197
raise NoValidHarFileError("No .har file found")
198
191
api_key = None
199
192
cookies = None
200
for path in harPath:
193
for path in get_har_files():
201
194
with open(path, 'rb') as file:
202
195
try:
203
196
harFile = json.loads(file.read())
@@ -424,10 +424,10 @@ class OpenaiChat(AsyncGeneratorProvider, ProviderModelMixin):
424
424
for element in c.get("parts"):
425
425
if isinstance(element, dict) and element.get("content_type") == "image_asset_pointer":
426
426
image = cls.get_generated_image(session, cls._headers, element)
427
if image is not None:
428
generated_images.append(image)
427
generated_images.append(image)
429
428
for image_response in await asyncio.gather(*generated_images):
430
yield image_response
429
if image_response is not None:
430
yield image_response
431
431
if m.get("author", {}).get("role") == "assistant":
432
432
fields.message_id = v.get("message", {}).get("id")
433
433
return
@@ -45,7 +45,7 @@ class arkReq:
45
45
self.arkCookies = arkCookies
46
46
self.userAgent = userAgent
47
47
48
def readHAR():
48
def get_har_files():
49
49
harPath = []
50
50
for root, _, files in os.walk(get_cookies_dir()):
51
51
for file in files:
@@ -53,7 +53,11 @@ def readHAR():
53
53
harPath.append(os.path.join(root, file))
54
54
if not harPath:
55
55
raise NoValidHarFileError("No .har file found")
56
for path in harPath:
56
harPath.sort(key=lambda x: os.path.getmtime(x))
57
return harPath
58
59
def readHAR():
60
for path in get_har_files():
57
61
with open(path, 'rb') as file:
58
62
try:
59
63
harFile = json.loads(file.read())
@@ -58,7 +58,7 @@ def iter_response(
58
58
elif isinstance(chunk, BaseConversation):
59
59
yield chunk
60
60
continue
61
elif isinstance(chunk, SynthesizeData):
61
elif isinstance(chunk, SynthesizeData) or chunk is None:
62
62
continue
63
63
64
64
chunk = str(chunk)
@@ -121,7 +121,7 @@ async def async_iter_response(
121
121
elif isinstance(chunk, BaseConversation):
122
122
yield chunk
123
123
continue
124
elif isinstance(chunk, SynthesizeData):
124
elif isinstance(chunk, SynthesizeData) or chunk is None:
125
125
continue
126
126
127
127
chunk = str(chunk)
@@ -90,9 +90,9 @@ def get_model_and_provider(model : Union[Model, str],
90
90
raise StreamNotSupportedError(f'{provider.__name__} does not support "stream" argument')
91
91
92
92
if model:
93
debug.log(f'Using {provider.__name__} provider and {model} model')
93
debug.log(f'Using {type(provider).__name__} provider and {model} model')
94
94
else:
95
debug.log(f'Using {provider.__name__} provider')
95
debug.log(f'Using {type(provider).__name__} provider')
96
96
97
97
debug.last_provider = provider
98
98
debug.last_model = model
@@ -115,7 +115,7 @@ def get_last_provider(as_dict: bool = False) -> Union[ProviderType, dict[str, st
115
115
if as_dict:
116
116
if last:
117
117
return {
118
"name": last.__name__,
118
"name": type(last).__name__,
119
119
"url": last.url,
120
120
"model": debug.last_model,
121
121
"label": getattr(last, "label", None) if hasattr(last, "label") else None
@@ -477,6 +477,7 @@ body.white .gradient{
477
477
right: 8px;
478
478
top: 8px;
479
479
z-index: 1000;
480
cursor: pointer;
480
481
}
481
482
482
483
.count_total {