diff --git a/pkg/audit/gatherer.py b/pkg/audit/gatherer.py index ceef49e2..699bbaee 100644 --- a/pkg/audit/gatherer.py +++ b/pkg/audit/gatherer.py @@ -5,6 +5,7 @@ import hashlib import json import logging +import threading import requests @@ -42,15 +43,20 @@ def report_to_server(self, subservice_name: str, count: int): 只会报告此次请求的使用量,不会报告总量。 不包含除版本号、使用类型、使用量以外的任何信息,仅供开发者分析使用情况。 """ - try: - config = pkg.utils.context.get_config() - if not config.report_usage: + + def thread_func(): + + try: + config = pkg.utils.context.get_config() + if not config.report_usage: + return + res = requests.get("http://reports.rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}&msg_source={}".format(subservice_name, self.version_str, count, config.msg_source_adapter)) + 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://reports.rockchin.top:18989/usage?service_name=qchatgpt.{}&version={}&count={}&msg_source={}".format(subservice_name, self.version_str, count, config.msg_source_adapter)) - 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 + + threading.Thread(target=thread_func).start() def get_usage(self, key_md5): return self.usage[key_md5] if key_md5 in self.usage else {}