Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
f650935
1
Parent(s):
214f3ef
支持使用OPENAI_API_BASE环境变量自定义API URL
Browse files- modules/shared.py +13 -7
modules/shared.py
CHANGED
@@ -15,11 +15,15 @@ class State:
|
|
15 |
def recover(self):
|
16 |
self.interrupted = False
|
17 |
|
18 |
-
def set_api_host(self, api_host):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
23 |
|
24 |
def reset_api_host(self):
|
25 |
self.completion_url = COMPLETION_URL
|
@@ -31,7 +35,7 @@ class State:
|
|
31 |
def reset_all(self):
|
32 |
self.interrupted = False
|
33 |
self.completion_url = COMPLETION_URL
|
34 |
-
|
35 |
def set_api_key_queue(self, api_key_list):
|
36 |
self.multi_api_key = True
|
37 |
self.api_key_queue = queue.Queue()
|
@@ -50,6 +54,8 @@ class State:
|
|
50 |
return ret
|
51 |
|
52 |
return wrapped
|
53 |
-
|
54 |
|
55 |
state = State()
|
|
|
|
|
|
15 |
def recover(self):
|
16 |
self.interrupted = False
|
17 |
|
18 |
+
def set_api_host(self, api_host: str):
|
19 |
+
if not api_host.startswith("http"):
|
20 |
+
api_host = f"https://{api_host}"
|
21 |
+
if api_host.endswith("/v1"):
|
22 |
+
api_host = api_host[:-3]
|
23 |
+
self.completion_url = f"{api_host}/v1/chat/completions"
|
24 |
+
self.balance_api_url = f"{api_host}/dashboard/billing/credit_grants"
|
25 |
+
self.usage_api_url = f"{api_host}/dashboard/billing/usage"
|
26 |
+
os.environ["OPENAI_API_BASE"] = f"{api_host}/v1"
|
27 |
|
28 |
def reset_api_host(self):
|
29 |
self.completion_url = COMPLETION_URL
|
|
|
35 |
def reset_all(self):
|
36 |
self.interrupted = False
|
37 |
self.completion_url = COMPLETION_URL
|
38 |
+
|
39 |
def set_api_key_queue(self, api_key_list):
|
40 |
self.multi_api_key = True
|
41 |
self.api_key_queue = queue.Queue()
|
|
|
54 |
return ret
|
55 |
|
56 |
return wrapped
|
57 |
+
|
58 |
|
59 |
state = State()
|
60 |
+
if (host:=os.environ.get("OPENAI_API_BASE", None)) is not None:
|
61 |
+
state.set_api_host(host)
|