🐛 Bug: Fix the bug where the embedding URL for GLM and GitHub models is incorrect.
Browse files- test/test_baseurl.py +22 -0
- utils.py +10 -12
test/test_baseurl.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import sys
|
3 |
+
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
4 |
+
|
5 |
+
from utils import BaseAPI
|
6 |
+
|
7 |
+
def print_base_api(url):
|
8 |
+
base_api = BaseAPI(url)
|
9 |
+
print("base_url ", base_api.base_url)
|
10 |
+
print("v1_url ", base_api.v1_url)
|
11 |
+
print("chat_url ", base_api.chat_url)
|
12 |
+
print("image_url ", base_api.image_url)
|
13 |
+
print("audio_transcriptions", base_api.audio_transcriptions)
|
14 |
+
print("moderations ", base_api.moderations)
|
15 |
+
print("embeddings ", base_api.embeddings)
|
16 |
+
print("-"*50)
|
17 |
+
|
18 |
+
|
19 |
+
print_base_api("https://api.openai.com/v1/chat/completions")
|
20 |
+
print_base_api("https://api.deepseek.com/chat/completions")
|
21 |
+
print_base_api("https://models.inference.ai.azure.com/chat/completions")
|
22 |
+
print_base_api("https://open.bigmodel.cn/api/paas/v4/chat/completions")
|
utils.py
CHANGED
@@ -573,23 +573,21 @@ class BaseAPI:
|
|
573 |
self.source_api_url: str = api_url
|
574 |
from urllib.parse import urlparse, urlunparse
|
575 |
parsed_url = urlparse(self.source_api_url)
|
|
|
576 |
if parsed_url.scheme == "":
|
577 |
raise Exception("Error: API_URL is not set")
|
578 |
if parsed_url.path != '/':
|
579 |
-
before_v1 = parsed_url.path.split("/
|
580 |
else:
|
581 |
before_v1 = ""
|
582 |
-
self.base_url: str = urlunparse(parsed_url[:2] + (
|
583 |
-
self.v1_url: str = urlunparse(parsed_url[:2]+ (before_v1
|
584 |
-
self.v1_models: str = urlunparse(parsed_url[:2] + (before_v1 + "
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
self.
|
590 |
-
self.audio_transcriptions: str = urlunparse(parsed_url[:2] + (before_v1 + "/v1/audio/transcriptions",) + ("",) * 3)
|
591 |
-
self.moderations: str = urlunparse(parsed_url[:2] + (before_v1 + "/v1/moderations",) + ("",) * 3)
|
592 |
-
self.embeddings: str = urlunparse(parsed_url[:2] + (before_v1 + "/v1/embeddings",) + ("",) * 3)
|
593 |
|
594 |
def safe_get(data, *keys, default=None):
|
595 |
for key in keys:
|
|
|
573 |
self.source_api_url: str = api_url
|
574 |
from urllib.parse import urlparse, urlunparse
|
575 |
parsed_url = urlparse(self.source_api_url)
|
576 |
+
# print("parsed_url", parsed_url)
|
577 |
if parsed_url.scheme == "":
|
578 |
raise Exception("Error: API_URL is not set")
|
579 |
if parsed_url.path != '/':
|
580 |
+
before_v1 = parsed_url.path.split("chat/completions")[0]
|
581 |
else:
|
582 |
before_v1 = ""
|
583 |
+
self.base_url: str = urlunparse(parsed_url[:2] + ("",) + ("",) * 3)
|
584 |
+
self.v1_url: str = urlunparse(parsed_url[:2]+ (before_v1,) + ("",) * 3)
|
585 |
+
self.v1_models: str = urlunparse(parsed_url[:2] + (before_v1 + "models",) + ("",) * 3)
|
586 |
+
self.chat_url: str = urlunparse(parsed_url[:2] + (before_v1 + "chat/completions",) + ("",) * 3)
|
587 |
+
self.image_url: str = urlunparse(parsed_url[:2] + (before_v1 + "images/generations",) + ("",) * 3)
|
588 |
+
self.audio_transcriptions: str = urlunparse(parsed_url[:2] + (before_v1 + "audio/transcriptions",) + ("",) * 3)
|
589 |
+
self.moderations: str = urlunparse(parsed_url[:2] + (before_v1 + "moderations",) + ("",) * 3)
|
590 |
+
self.embeddings: str = urlunparse(parsed_url[:2] + (before_v1 + "embeddings",) + ("",) * 3)
|
|
|
|
|
|
|
591 |
|
592 |
def safe_get(data, *keys, default=None):
|
593 |
for key in keys:
|