返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+1
-1
Modified
g4f/tools/run_tools.py
+10
-8
XFEstudio/gpt4free
Fix load api_key
d81fa80f
代码差异
2 个文件
+11
-9
@@ -489,7 +489,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
489
489
frequency_penalty=frequency_penalty,
490
490
response_format=response_format,
491
491
stream=stream,
492
seed=seed,
492
seed=None if model =="grok" else seed,
493
493
**extra_body
494
494
)
495
495
headers = {"referer": referrer}
@@ -126,7 +126,7 @@ class AuthManager:
126
126
@staticmethod
127
127
def get_api_key_file(cls) -> Path:
128
128
"""Get the path to the API key file for a provider"""
129
return Path(get_cookies_dir()) / f"api_key_{cls.parent if hasattr(cls, 'parent') else cls.__name__}.json"
129
return Path(get_cookies_dir()) / f"auth_{cls.get_parent()}.json"
130
130
131
131
@staticmethod
132
132
def load_api_key(provider: Any) -> Optional[str]:
@@ -134,6 +134,7 @@ class AuthManager:
134
134
auth_file = AuthManager.get_api_key_file(provider)
135
135
try:
136
136
if auth_file.exists():
137
debug.log(f"Loading API key from {auth_file}")
137
138
with auth_file.open("r") as f:
138
139
auth_result = json.load(f)
139
140
return auth_result.get("api_key")
@@ -231,11 +232,12 @@ async def async_iter_run_tools(
231
232
web_search = kwargs.get('web_search')
232
233
if web_search:
233
234
messages, sources = await perform_web_search(messages, web_search)
234
235
# Get API key if needed
236
api_key = AuthManager.load_api_key(provider)
237
if api_key and "api_key" not in kwargs:
238
kwargs["api_key"] = api_key
235
236
# Get API key
237
if not kwargs.get("api_key"):
238
api_key = AuthManager.load_api_key(provider)
239
if api_key:
240
kwargs["api_key"] = api_key
239
241
240
242
# Process tool calls
241
243
if tool_calls:
@@ -276,11 +278,11 @@ def iter_run_tools(
276
278
debug.error(f"Couldn't do web search: {e.__class__.__name__}: {e}")
277
279
278
280
# Get API key if needed
279
if provider is not None and getattr(provider, "needs_auth", False) and "api_key" not in kwargs:
281
if provider is not None and not kwargs.get("api_key"):
280
282
api_key = AuthManager.load_api_key(provider)
281
283
if api_key:
282
284
kwargs["api_key"] = api_key
283
285
284
286
# Process tool calls
285
287
if tool_calls:
286
288
for tool in tool_calls: