From 6c03fe678a467aea94e5555663c9f45dc179ba5c Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 12 Jan 2024 17:20:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?feat:=20=E5=85=81=E8=AE=B8=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=85=B3=E9=97=AD=E6=95=B0=E6=8D=AE=E4=B8=8A=E6=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config-template.py | 4 ++-- pkg/utils/center/groups/main.py | 7 +++++++ pkg/utils/center/groups/plugin.py | 7 +++++++ pkg/utils/center/groups/usage.py | 7 +++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config-template.py b/config-template.py index fe85766a..fb60ff1e 100644 --- a/config-template.py +++ b/config-template.py @@ -362,8 +362,8 @@ upgrade_dependencies = False # 是否上报统计信息 -# 用于统计机器人的使用情况,不会收集任何用户信息 -# 仅上报时间、字数使用量、绘图使用量,其他信息不会上报 +# 用于统计机器人的使用情况,数据不公开,不会收集任何敏感信息。 +# 仅实例识别UUID、上报时间、字数使用量、绘图使用量、插件使用情况、用户信息,其他信息不会上报 report_usage = True # 日志级别 diff --git a/pkg/utils/center/groups/main.py b/pkg/utils/center/groups/main.py index f158cd79..a4e5414a 100644 --- a/pkg/utils/center/groups/main.py +++ b/pkg/utils/center/groups/main.py @@ -1,6 +1,7 @@ from __future__ import annotations from .. import apigroup +from ... import context class V2MainDataAPI(apigroup.APIGroup): @@ -9,6 +10,12 @@ class V2MainDataAPI(apigroup.APIGroup): def __init__(self, prefix: str): super().__init__(prefix+"/main") + def do(self, *args, **kwargs): + config = context.get_config_manager().data + if not config['report_usage']: + return None + return super().do(*args, **kwargs) + def post_update_record( self, spent_seconds: int, diff --git a/pkg/utils/center/groups/plugin.py b/pkg/utils/center/groups/plugin.py index b3ac423c..c7881b9d 100644 --- a/pkg/utils/center/groups/plugin.py +++ b/pkg/utils/center/groups/plugin.py @@ -1,6 +1,7 @@ from __future__ import annotations from .. import apigroup +from ... import context class V2PluginDataAPI(apigroup.APIGroup): @@ -9,6 +10,12 @@ class V2PluginDataAPI(apigroup.APIGroup): def __init__(self, prefix: str): super().__init__(prefix+"/plugin") + def do(self, *args, **kwargs): + config = context.get_config_manager().data + if not config['report_usage']: + return None + return super().do(*args, **kwargs) + def post_install_record( self, plugin: dict diff --git a/pkg/utils/center/groups/usage.py b/pkg/utils/center/groups/usage.py index 6e383a35..f966add4 100644 --- a/pkg/utils/center/groups/usage.py +++ b/pkg/utils/center/groups/usage.py @@ -1,6 +1,7 @@ from __future__ import annotations from .. import apigroup +from ... import context class V2UsageDataAPI(apigroup.APIGroup): @@ -8,6 +9,12 @@ class V2UsageDataAPI(apigroup.APIGroup): def __init__(self, prefix: str): super().__init__(prefix+"/usage") + + def do(self, *args, **kwargs): + config = context.get_config_manager().data + if not config['report_usage']: + return None + return super().do(*args, **kwargs) def post_query_record( self, From ab8d77c968f5398f6f357207915a64ae7a613c08 Mon Sep 17 00:00:00 2001 From: RockChinQ <1010553892@qq.com> Date: Fri, 12 Jan 2024 20:06:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?feat:=20=E5=88=A0=E9=99=A4=20v1=20=E5=AE=A1?= =?UTF-8?q?=E8=AE=A1=20API=20=E8=B0=83=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/audit/gatherer.py | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/pkg/audit/gatherer.py b/pkg/audit/gatherer.py index b3233f10..01bb7f2d 100644 --- a/pkg/audit/gatherer.py +++ b/pkg/audit/gatherer.py @@ -37,27 +37,6 @@ def __init__(self): except: pass - def report_to_server(self, subservice_name: str, count: int): - """向中央服务器报告使用量 - - 只会报告此次请求的使用量,不会报告总量。 - 不包含除版本号、使用类型、使用量以外的任何信息,仅供开发者分析使用情况。 - """ - - def thread_func(): - - try: - config = context.get_config_manager().data - 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 - - threading.Thread(target=thread_func).start() - def get_usage(self, key_md5): return self.usage[key_md5] if key_md5 in self.usage else {} @@ -79,8 +58,6 @@ def report_text_model_usage(self, model, total_tokens): self.usage[key_md5]["text"][model] += length self.dump_to_db() - self.report_to_server("text", length) - def report_image_model_usage(self, size): """调用方报告图片模型请求图片使用量""" @@ -98,8 +75,6 @@ def report_image_model_usage(self, size): self.usage[key_md5]["image"][size] += 1 self.dump_to_db() - self.report_to_server("image", 1) - def get_text_length_of_key(self, key): """获取指定api-key (明文) 的文字总使用量(本地记录)""" key_md5 = hashlib.md5(key.encode('utf-8')).hexdigest()