Spaces:
Runtime error
Runtime error
:zap: [Enhance] Handle if http_proxy is None, and prettify logs
Browse files- tests/openai.py +14 -9
tests/openai.py
CHANGED
@@ -20,7 +20,7 @@ class OpenaiAPI:
|
|
20 |
self.api_chat_requirements = f"{self.api_base}/sentinel/chat-requirements"
|
21 |
self.uuid = str(uuid.uuid4())
|
22 |
self.requests_headers = {
|
23 |
-
"Accept": "*/*",
|
24 |
"Accept-Encoding": "gzip, deflate, br, zstd",
|
25 |
"Accept-Language": "en-US,en;q=0.9",
|
26 |
"Cache-Control": "no-cache",
|
@@ -38,15 +38,20 @@ class OpenaiAPI:
|
|
38 |
}
|
39 |
|
40 |
http_proxy = ENVER["http_proxy"]
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
|
46 |
def log_request(self, url, method="GET"):
|
47 |
if ENVER["http_proxy"]:
|
48 |
-
logger.note(f"> Using Proxy:
|
49 |
-
|
|
|
|
|
50 |
|
51 |
def log_response(self, res: requests.Response):
|
52 |
status_code = res.status_code
|
@@ -54,10 +59,10 @@ class OpenaiAPI:
|
|
54 |
if status_code == 200:
|
55 |
logger.success(status_code_str)
|
56 |
else:
|
57 |
-
logger.warn(f"uuid: {self.uuid}")
|
58 |
logger.warn(status_code_str)
|
|
|
59 |
|
60 |
-
logger.
|
61 |
|
62 |
def get_models(self):
|
63 |
self.log_request(self.api_models)
|
|
|
20 |
self.api_chat_requirements = f"{self.api_base}/sentinel/chat-requirements"
|
21 |
self.uuid = str(uuid.uuid4())
|
22 |
self.requests_headers = {
|
23 |
+
# "Accept": "*/*",
|
24 |
"Accept-Encoding": "gzip, deflate, br, zstd",
|
25 |
"Accept-Language": "en-US,en;q=0.9",
|
26 |
"Cache-Control": "no-cache",
|
|
|
38 |
}
|
39 |
|
40 |
http_proxy = ENVER["http_proxy"]
|
41 |
+
if http_proxy:
|
42 |
+
self.requests_proxies = {
|
43 |
+
"http": http_proxy,
|
44 |
+
"https": http_proxy,
|
45 |
+
}
|
46 |
+
else:
|
47 |
+
self.requests_proxies = None
|
48 |
|
49 |
def log_request(self, url, method="GET"):
|
50 |
if ENVER["http_proxy"]:
|
51 |
+
logger.note(f"> Using Proxy:", end=" ")
|
52 |
+
logger.mesg(f"{ENVER['http_proxy']}")
|
53 |
+
logger.note(f"> {method}:", end=" ")
|
54 |
+
logger.mesg(f"{url}", end=" ")
|
55 |
|
56 |
def log_response(self, res: requests.Response):
|
57 |
status_code = res.status_code
|
|
|
59 |
if status_code == 200:
|
60 |
logger.success(status_code_str)
|
61 |
else:
|
|
|
62 |
logger.warn(status_code_str)
|
63 |
+
logger.warn(f"uuid: {self.uuid}")
|
64 |
|
65 |
+
logger.line(res.json())
|
66 |
|
67 |
def get_models(self):
|
68 |
self.log_request(self.api_models)
|