✨ Feature: Add feature: Support Gemini custom base URL
Browse files💰 Sponsors: Thanks to
@ioi
for the ¥50 sponsorship, sponsorship information has been added to the README.
- README.md +1 -0
- README_CN.md +1 -0
- main.py +1 -1
- request.py +4 -4
README.md
CHANGED
@@ -378,6 +378,7 @@ pex -r requirements.txt \
|
|
378 |
We thank the following sponsors for their support:
|
379 |
<!-- ¥1000 -->
|
380 |
- @PowerHunter: ¥1800
|
|
|
381 |
|
382 |
## How to sponsor us
|
383 |
|
|
|
378 |
We thank the following sponsors for their support:
|
379 |
<!-- ¥1000 -->
|
380 |
- @PowerHunter: ¥1800
|
381 |
+
- @ioi:¥50
|
382 |
|
383 |
## How to sponsor us
|
384 |
|
README_CN.md
CHANGED
@@ -367,6 +367,7 @@ pex -r requirements.txt \
|
|
367 |
我们感谢以下赞助商的支持:
|
368 |
<!-- ¥1000 -->
|
369 |
- @PowerHunter:¥1800
|
|
|
370 |
|
371 |
## 如何赞助我们
|
372 |
|
|
|
367 |
我们感谢以下赞助商的支持:
|
368 |
<!-- ¥1000 -->
|
369 |
- @PowerHunter:¥1800
|
370 |
+
- @ioi:¥50
|
371 |
|
372 |
## 如何赞助我们
|
373 |
|
main.py
CHANGED
@@ -749,7 +749,7 @@ async def process_request(request: Union[RequestModel, ImageGenerationRequest, A
|
|
749 |
parsed_url = urlparse(url)
|
750 |
# print("parsed_url", parsed_url)
|
751 |
engine = None
|
752 |
-
if parsed_url.
|
753 |
engine = "gemini"
|
754 |
elif parsed_url.netloc == 'aiplatform.googleapis.com':
|
755 |
engine = "vertex"
|
|
|
749 |
parsed_url = urlparse(url)
|
750 |
# print("parsed_url", parsed_url)
|
751 |
engine = None
|
752 |
+
if parsed_url.path.startswith("/v1beta") or parsed_url.path.startswith("/v1"):
|
753 |
engine = "gemini"
|
754 |
elif parsed_url.netloc == 'aiplatform.googleapis.com':
|
755 |
engine = "vertex"
|
request.py
CHANGED
@@ -124,10 +124,10 @@ async def get_gemini_payload(request, engine, provider):
|
|
124 |
model = model_dict[request.model]
|
125 |
gemini_stream = "streamGenerateContent"
|
126 |
url = provider['base_url']
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
|
132 |
messages = []
|
133 |
systemInstruction = None
|
|
|
124 |
model = model_dict[request.model]
|
125 |
gemini_stream = "streamGenerateContent"
|
126 |
url = provider['base_url']
|
127 |
+
parsed_url = urllib.parse.urlparse(url)
|
128 |
+
api_version = parsed_url.path.split('/')[-1] # 获取 v1 或 v1beta
|
129 |
+
# https://generativelanguage.googleapis.com/v1beta/models/
|
130 |
+
url = f"https://{parsed_url.netloc}/{api_version}/models/{model}:{gemini_stream}?key={await provider_api_circular_list[provider['provider']].next(model)}"
|
131 |
|
132 |
messages = []
|
133 |
systemInstruction = None
|