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

XFEstudio/gpt4free

Fix read api_key

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

代码差异

1 个文件 +10 -6
Modified g4f/tools/run_tools.py +10 -6
@@ -136,8 +136,12 @@ class AuthManager:
136 136 if auth_file.exists():
137 137 debug.log(f"Loading API key from {auth_file}")
138 138 with auth_file.open("r") as f:
139 auth_result = json.load(f)
140 return auth_result.get("api_key")
139 try:
140 auth_result = json.load(f)
141 except json.JSONDecodeError as e:
142 return auth_file.read_text()
143 if isinstance(auth_result, dict):
144 return auth_result.get("api_key")
141 145 except (json.JSONDecodeError, PermissionError, FileNotFoundError) as e:
142 146 debug.error(f"Failed to load API key: {e.__class__.__name__}: {e}")
143 147 return None
@@ -168,7 +172,7 @@ class ThinkingProcessor:
168 172 if "</think>" in after[0]:
169 173 after, *after_end = after[0].split("</think>", 1)
170 174 results.append(Reasoning(after))
171 results.append(Reasoning(status="Finished", is_thinking="</think>"))
175 results.append(Reasoning(status="", is_thinking="</think>"))
172 176 if after_end:
173 177 results.append(after_end[0])
174 178 return 0, results
@@ -185,10 +189,10 @@ class ThinkingProcessor:
185 189 results.append(Reasoning(before_end))
186 190
187 191 thinking_duration = time.time() - start_time if start_time > 0 else 0
188
189 status = f"Thought for {thinking_duration:.2f}s" if thinking_duration > 1 else "Finished"
192
193 status = f"Thought for {thinking_duration:.2f}s" if thinking_duration > 1 else ""
190 194 results.append(Reasoning(status=status, is_thinking="</think>"))
191
195
192 196 # Make sure to handle text after the closing tag
193 197 if after and after[0].strip():
194 198 results.append(after[0])