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

XFEstudio/gpt4free

Fix GeminiPro auth for normal user

b80ca3b7
Heiner Lohaus <hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +10 -8
Modified g4f/Provider/GeminiPro.py +10 -8
@@ -34,17 +34,18 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
34 34
35 35 if not api_key:
36 36 raise MissingAuthError('Missing "api_key"')
37
38 headers = params = None
39 if api_base:
40 headers = {"Authorization": f"Bearer {api_key}"}
41 else:
42 params = {"key": api_key}
43
37 44 if not api_base:
38 45 api_base = f"https://generativelanguage.googleapis.com/v1beta"
39 46
40 47 method = "streamGenerateContent" if stream else "generateContent"
41 48 url = f"{api_base.rstrip('/')}/models/{model}:{method}"
42 headers = None
43 if api_base:
44 headers = {f"Authorization": "Bearer {api_key}"}
45 else:
46 url += f"?key={api_key}"
47
48 49 async with ClientSession(headers=headers) as session:
49 50 contents = [
50 51 {
@@ -71,10 +72,11 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
71 72 "topK": kwargs.get("top_k"),
72 73 }
73 74 }
74 async with session.post(url, json=data, proxy=proxy) as response:
75 async with session.post(url, params=params, json=data, proxy=proxy) as response:
75 76 if not response.ok:
76 77 data = await response.json()
77 raise RuntimeError(data[0]["error"]["message"])
78 data = data[0] if isinstance(data, list) else data
79 raise RuntimeError(data["error"]["message"])
78 80 if stream:
79 81 lines = []
80 82 async for chunk in response.content: