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

XFEstudio/gpt4free

fix: remove unused tool_calls and debug logging, fix file ops

- Removed default `tool_calls` assignment from `Api.__call__` in `api.py` - Removed `debug.error()` logging in two exception blocks in `api.py` - Fixed malformed URL in `CohereForAI_C4AI_Command.url` by removing leading tab in `CohereForAI_C4AI_Command.py` - Replaced incorrect `result.text_content` access with just `result` in `Backend_Api.upload_bucket` in `backend_api.py` - Replaced `shutil.copyfile` with `os.rename`, and added fallback to `shutil.copyfile` on failure in `Backend_Api.upload_bucket` in `backend_api.py

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

代码差异

3 个文件 +7 -12
Modified g4f/Provider/hf_space/CohereForAI_C4AI_Command.py +1 -1
@@ -11,7 +11,7 @@ from ...providers.response import JsonConversation, TitleGeneration
11 11
12 12 class CohereForAI_C4AI_Command(AsyncGeneratorProvider, ProviderModelMixin):
13 13 label = "CohereForAI C4AI Command"
14 url = " https://coherelabs-c4ai-command.hf.space"
14 url = "https://coherelabs-c4ai-command.hf.space"
15 15 conversation_url = f"{url}/conversation"
16 16
17 17 working = True
Modified g4f/gui/server/api.py +0 -8
@@ -107,12 +107,6 @@ class Api:
107 107 model = json_data.get('model')
108 108 provider = json_data.get('provider')
109 109 messages = json_data.get('messages')
110 kwargs["tool_calls"] = [{
111 "function": {
112 "name": "bucket_tool"
113 },
114 "type": "function"
115 }]
116 110 action = json_data.get('action')
117 111 if action == "continue":
118 112 kwargs["tool_calls"].append({
@@ -186,7 +180,6 @@ class Api:
186 180 yield self._format_json("conversation_id", conversation_id)
187 181 elif isinstance(chunk, Exception):
188 182 logger.exception(chunk)
189 debug.error(chunk)
190 183 yield self._format_json('message', get_error_message(chunk), error=type(chunk).__name__)
191 184 elif isinstance(chunk, RequestLogin):
192 185 yield self._format_json("preview", chunk.to_string())
@@ -232,7 +225,6 @@ class Api:
232 225 yield self._format_json('auth', type(e).__name__, message=get_error_message(e))
233 226 except Exception as e:
234 227 logger.exception(e)
235 debug.error(e)
236 228 yield self._format_json('error', type(e).__name__, message=get_error_message(e))
237 229 finally:
238 230 yield from self._yield_logs()
Modified g4f/gui/server/backend_api.py +6 -3
@@ -318,7 +318,7 @@ class Backend_Api(Api):
318 318 md = MarkItDown()
319 319 result = md.convert(copyfile.name).text_content
320 320 with open(os.path.join(bucket_dir, f"{filename}.md"), 'w') as f:
321 f.write(f"{result.text_content}\n")
321 f.write(f"{result}\n")
322 322 filenames.append(f"{filename}.md")
323 323 except Exception as e:
324 324 logger.exception(e)
@@ -333,8 +333,11 @@ class Backend_Api(Api):
333 333 else:
334 334 os.remove(copyfile.name)
335 335 continue
336 shutil.copyfile(copyfile.name, newfile)
337 os.remove(copyfile.name)
336 try:
337 os.rename(copyfile.name, newfile)
338 except OSError:
339 shutil.copyfile(copyfile.name, newfile)
340 os.remove(copyfile.name)
338 341 with open(os.path.join(bucket_dir, "files.txt"), 'w') as f:
339 342 [f.write(f"{filename}\n") for filename in filenames]
340 343 return {"bucket_id": bucket_id, "files": filenames, "media": media}