mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-10-08 09:40:08 +08:00
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
This commit is contained in:
@@ -210,12 +210,7 @@ class Backend_Api(Api):
|
||||
@app.route('/backend-api/v2/create', methods=['GET', 'POST'])
|
||||
def create():
|
||||
try:
|
||||
tool_calls = [{
|
||||
"function": {
|
||||
"name": "bucket_tool"
|
||||
},
|
||||
"type": "function"
|
||||
}]
|
||||
tool_calls = []
|
||||
web_search = request.args.get("web_search")
|
||||
if web_search:
|
||||
is_true_web_search = web_search.lower() in ["true", "1"]
|
||||
@@ -277,12 +272,11 @@ class Backend_Api(Api):
|
||||
if not response:
|
||||
response = iter_run_tools(ChatCompletion.create, **parameters)
|
||||
cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
copy_response = cast_str(response)
|
||||
if copy_response:
|
||||
response = cast_str(response)
|
||||
response = response if isinstance(response, str) else "".join(response)
|
||||
if response:
|
||||
with cache_file.open("w") as f:
|
||||
for chunk in [copy_response] if isinstance(copy_response, str) else copy_response:
|
||||
f.write(chunk)
|
||||
response = copy_response
|
||||
f.write(response)
|
||||
else:
|
||||
response = cast_str(iter_run_tools(ChatCompletion.create, **parameters))
|
||||
if isinstance(response, str):
|
||||
@@ -298,7 +292,7 @@ class Backend_Api(Api):
|
||||
return redirect(response)
|
||||
if do_filter:
|
||||
is_true_filter = do_filter.lower() in ["true", "1"]
|
||||
response = "".join(response)
|
||||
response = response if isinstance(response, str) else "".join(response)
|
||||
return Response(filter_markdown(response, None if is_true_filter else do_filter, response if is_true_filter else ""), mimetype='text/plain')
|
||||
return Response(response, mimetype='text/plain')
|
||||
except Exception as e:
|
||||
@@ -412,10 +406,9 @@ class Backend_Api(Api):
|
||||
mime_type = is_allowed_extension(file)
|
||||
if mime_type is not None:
|
||||
mime_type = secure_filename(mime_type)
|
||||
for tag in safe_search:
|
||||
if tag in mime_type:
|
||||
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
|
||||
break
|
||||
if safe_search[0] in mime_type:
|
||||
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
|
||||
break
|
||||
for tag in safe_search:
|
||||
if tag in file.lower():
|
||||
self.match_files[search][file] = self.match_files[search].get(file, 0) + 1
|
||||
|
Reference in New Issue
Block a user