summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-26 02:31:14 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-26 02:31:14 +0100
commitb80ca3b7c968cc82af1a1f22815442174771446f (patch)
tree4bbaa3047be0a4e6ddbcc809672506bdbe72f5e3 /g4f
parentImprove mobile css styles (diff)
downloadgpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar.gz
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar.bz2
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar.lz
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar.xz
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.tar.zst
gpt4free-b80ca3b7c968cc82af1a1f22815442174771446f.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/GeminiPro.py18
1 files changed, 10 insertions, 8 deletions
diff --git a/g4f/Provider/GeminiPro.py b/g4f/Provider/GeminiPro.py
index 87ded3ac..972855ce 100644
--- a/g4f/Provider/GeminiPro.py
+++ b/g4f/Provider/GeminiPro.py
@@ -34,17 +34,18 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
if not api_key:
raise MissingAuthError('Missing "api_key"')
+
+ headers = params = None
+ if api_base:
+ headers = {"Authorization": f"Bearer {api_key}"}
+ else:
+ params = {"key": api_key}
+
if not api_base:
api_base = f"https://generativelanguage.googleapis.com/v1beta"
method = "streamGenerateContent" if stream else "generateContent"
url = f"{api_base.rstrip('/')}/models/{model}:{method}"
- headers = None
- if api_base:
- headers = {f"Authorization": "Bearer {api_key}"}
- else:
- url += f"?key={api_key}"
-
async with ClientSession(headers=headers) as session:
contents = [
{
@@ -71,10 +72,11 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
"topK": kwargs.get("top_k"),
}
}
- async with session.post(url, json=data, proxy=proxy) as response:
+ async with session.post(url, params=params, json=data, proxy=proxy) as response:
if not response.ok:
data = await response.json()
- raise RuntimeError(data[0]["error"]["message"])
+ data = data[0] if isinstance(data, list) else data
+ raise RuntimeError(data["error"]["message"])
if stream:
lines = []
async for chunk in response.content: