返回提交历史
Modified
g4f/Provider/needs_auth/DeepSeekAPI.py
+1
-1
Modified
g4f/gui/server/backend_api.py
+9
-16
Modified
g4f/gui/server/website.py
+1
-1
XFEstudio/gpt4free
refactor: adjust model check, tool calls, and response handling logic
- Updated `thinking_enabled` condition in `DeepSeekAPI.py` to ensure `model` is not None before checking substring - Removed default `tool_calls` value in `/backend-api/v2/create` route in `backend_api.py` - Simplified response caching logic by consolidating `cast_str` handling and ensuring `response` is a string before writing - Adjusted response filtering logic to handle string vs iterable cases more consistently - Refined safe search tag check in file matching loop to only test the first tag against MIME type in `backend_api.py` - Changed default filename from "index" to "home" in `_index` method of `website.py
c3aca896
代码差异
3 个文件
+11
-18
@@ -67,7 +67,7 @@ class DeepSeekAPI(AsyncAuthedProvider, ProviderModelMixin):
67
67
for chunk in api.chat_completion(
68
68
conversation.chat_id,
69
69
get_last_user_message(messages),
70
thinking_enabled="deepseek-r1" in model,
70
thinking_enabled=bool(model) and "deepseek-r1" in model,
71
71
search_enabled=web_search
72
72
):
73
73
if chunk['type'] == 'thinking':
@@ -210,12 +210,7 @@ class Backend_Api(Api):
210
210
@app.route('/backend-api/v2/create', methods=['GET', 'POST'])
211
211
def create():
212
212
try:
213
tool_calls = [{
214
"function": {
215
"name": "bucket_tool"
216
},
217
"type": "function"
218
}]
213
tool_calls = []
219
214
web_search = request.args.get("web_search")
220
215
if web_search:
221
216
is_true_web_search = web_search.lower() in ["true", "1"]
@@ -277,12 +272,11 @@ class Backend_Api(Api):
277
272
if not response:
278
273
response = iter_run_tools(ChatCompletion.create, **parameters)
279
274
cache_dir.mkdir(parents=True, exist_ok=True)
280
copy_response = cast_str(response)
281
if copy_response:
275
response = cast_str(response)
276
response = response if isinstance(response, str) else "".join(response)
277
if response:
282
278
with cache_file.open("w") as f:
283
for chunk in [copy_response] if isinstance(copy_response, str) else copy_response:
284
f.write(chunk)
285
response = copy_response
279
f.write(response)
286
280
else:
287
281
response = cast_str(iter_run_tools(ChatCompletion.create, **parameters))
288
282
if isinstance(response, str):
@@ -298,7 +292,7 @@ class Backend_Api(Api):
298
292
return redirect(response)
299
293
if do_filter:
300
294
is_true_filter = do_filter.lower() in ["true", "1"]
301
response = "".join(response)
295
response = response if isinstance(response, str) else "".join(response)
302
296
return Response(filter_markdown(response, None if is_true_filter else do_filter, response if is_true_filter else ""), mimetype='text/plain')
303
297
return Response(response, mimetype='text/plain')
304
298
except Exception as e:
@@ -412,10 +406,9 @@ class Backend_Api(Api):
412
406
mime_type = is_allowed_extension(file)
413
407
if mime_type is not None:
414
408
mime_type = secure_filename(mime_type)
415
for tag in safe_search:
416
if tag in mime_type:
417
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
418
break
409
if safe_search[0] in mime_type:
410
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
411
break
419
412
for tag in safe_search:
420
413
if tag in file.lower():
421
414
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
@@ -67,7 +67,7 @@ class Website:
67
67
},
68
68
}
69
69
70
def _index(self, filename = "index"):
70
def _index(self, filename = "home"):
71
71
return render(filename)
72
72
73
73
def _qrcode(self, filename = "qrcode"):