Spaces:
Sleeping
Sleeping
Tuchuanhuhuhu
commited on
Commit
·
8baca88
1
Parent(s):
ed31090
修复merge导致的bug
Browse files- modules/models.py +16 -6
modules/models.py
CHANGED
|
@@ -43,10 +43,7 @@ class OpenAIClient(BaseLLMModel):
|
|
| 43 |
)
|
| 44 |
self.api_key = api_key
|
| 45 |
self.need_api_key = True
|
| 46 |
-
self.
|
| 47 |
-
"Content-Type": "application/json",
|
| 48 |
-
"Authorization": f"Bearer {self.api_key}",
|
| 49 |
-
}
|
| 50 |
|
| 51 |
def get_answer_stream_iter(self):
|
| 52 |
response = self._get_response(stream=True)
|
|
@@ -103,6 +100,13 @@ class OpenAIClient(BaseLLMModel):
|
|
| 103 |
def set_token_upper_limit(self, new_upper_limit):
|
| 104 |
pass
|
| 105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
@shared.state.switching_api_key # 在不开启多账号模式的时候,这个装饰器不会起作用
|
| 107 |
def _get_response(self, stream=False):
|
| 108 |
openai_api_key = self.api_key
|
|
@@ -159,10 +163,16 @@ class OpenAIClient(BaseLLMModel):
|
|
| 159 |
return None
|
| 160 |
return response
|
| 161 |
|
| 162 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
with retrieve_proxy():
|
| 164 |
response = requests.get(
|
| 165 |
-
|
| 166 |
headers=self.headers,
|
| 167 |
timeout=TIMEOUT_ALL,
|
| 168 |
)
|
|
|
|
| 43 |
)
|
| 44 |
self.api_key = api_key
|
| 45 |
self.need_api_key = True
|
| 46 |
+
self._refresh_header()
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
def get_answer_stream_iter(self):
|
| 49 |
response = self._get_response(stream=True)
|
|
|
|
| 100 |
def set_token_upper_limit(self, new_upper_limit):
|
| 101 |
pass
|
| 102 |
|
| 103 |
+
def set_key(self, new_access_key):
|
| 104 |
+
self.api_key = new_access_key.strip()
|
| 105 |
+
self._refresh_header()
|
| 106 |
+
msg = f"API密钥更改为了{hide_middle_chars(self.api_key)}"
|
| 107 |
+
logging.info(msg)
|
| 108 |
+
return msg
|
| 109 |
+
|
| 110 |
@shared.state.switching_api_key # 在不开启多账号模式的时候,这个装饰器不会起作用
|
| 111 |
def _get_response(self, stream=False):
|
| 112 |
openai_api_key = self.api_key
|
|
|
|
| 163 |
return None
|
| 164 |
return response
|
| 165 |
|
| 166 |
+
def _refresh_header(self):
|
| 167 |
+
self.headers = {
|
| 168 |
+
"Content-Type": "application/json",
|
| 169 |
+
"Authorization": f"Bearer {self.api_key}",
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
def _get_billing_data(self, billing_url):
|
| 173 |
with retrieve_proxy():
|
| 174 |
response = requests.get(
|
| 175 |
+
billing_url,
|
| 176 |
headers=self.headers,
|
| 177 |
timeout=TIMEOUT_ALL,
|
| 178 |
)
|