From 1015c6fa1fe6bdefd7d22cb40918210206ec3271 Mon Sep 17 00:00:00 2001 From: Rock Chin <1010553892@qq.com> Date: Wed, 4 Jan 2023 18:10:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8A=E6=8A=A5=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E9=87=8F=E4=BF=A1=E6=81=AF=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/audit/gatherer.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/audit/gatherer.py b/pkg/audit/gatherer.py index 2eaaad76..e562b232 100644 --- a/pkg/audit/gatherer.py +++ b/pkg/audit/gatherer.py @@ -25,12 +25,15 @@ class DataGatherer: self.load_from_db() def report_to_server(self, subservice_name: str, count: int): - config = pkg.utils.context.get_config() - if hasattr(config, "report_usage") and not config.report_usage: + try: + config = pkg.utils.context.get_config() + if hasattr(config, "report_usage") and not config.report_usage: + return + res = requests.get("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, version, count)) + if res.status_code != 200 or res.text != "ok": + logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text)) + except: return - res = requests.get("http://rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}".format(subservice_name, version, count)) - if res.status_code != 200 or res.text != "ok": - logging.warning("report to server failed, status_code: {}, text: {}".format(res.status_code, res.text)) def report_text_model_usage(self, model, text): key_md5 = pkg.utils.context.get_openai_manager().key_mgr.get_using_key_md5()