feat remove:删除数值化关系,更新默认模型,删除旧脚本,新增一栏统计项

This commit is contained in:
SengokuCola
2025-08-24 14:42:21 +08:00
parent d2f98145da
commit 69edf60c3b
15 changed files with 253 additions and 2174 deletions

View File

@@ -21,7 +21,6 @@ from src.chat.heart_flow.hfc_utils import send_typing, stop_typing
from src.chat.frequency_control.talk_frequency_control import talk_frequency_control
from src.chat.frequency_control.focus_value_control import focus_value_control
from src.chat.express.expression_learner import expression_learner_manager
from src.person_info.relationship_builder_manager import relationship_builder_manager
from src.person_info.person_info import Person
from src.plugin_system.base.component_types import ChatMode, EventType, ActionInfo
from src.plugin_system.core import events_manager
@@ -84,7 +83,6 @@ class HeartFChatting:
raise ValueError(f"无法找到聊天流: {self.stream_id}")
self.log_prefix = f"[{get_chat_manager().get_stream_name(self.stream_id) or self.stream_id}]"
self.relationship_builder = relationship_builder_manager.get_or_create_builder(self.stream_id)
self.expression_learner = expression_learner_manager.get_expression_learner(self.stream_id)
self.talk_frequency_control = talk_frequency_control.get_talk_frequency_control(self.stream_id)
@@ -385,7 +383,6 @@ class HeartFChatting:
await send_typing()
async with global_prompt_manager.async_message_scope(self.chat_stream.context.get_template_name()):
await self.relationship_builder.build_relation()
await self.expression_learner.trigger_learning_for_chat()
# # 记忆构建为当前chat_id构建记忆

View File

@@ -96,7 +96,10 @@ def init_prompt():
- {mentioned_bonus}
- 如果你刚刚进行了回复,不要对同一个话题重复回应
请你选中一条需要回复的消息并输出其id,输出格式如下
你之前的动作记录
{actions_before_now_block}
请你从新消息中选出一条需要回复的消息并输出其id,输出格式如下:
{{
"action": "reply",
"target_message_id":"想要回复的消息id消息id格式:m+数字",
@@ -845,6 +848,7 @@ class ActionPlanner:
mentioned_bonus=mentioned_bonus,
moderation_prompt=moderation_prompt_block,
name_block=name_block,
actions_before_now_block=actions_before_now_block,
)
return prompt, message_id_list
except Exception as e:

View File

@@ -166,6 +166,7 @@ class StatisticOutputTask(AsyncTask):
self.stat_period: List[Tuple[str, timedelta, str]] = [
("all_time", now - deploy_time, "自部署以来"), # 必须保留"all_time"
("last_7_days", timedelta(days=7), "最近7天"),
("last_3_days", timedelta(days=3), "最近3天"),
("last_24_hours", timedelta(days=1), "最近24小时"),
("last_3_hours", timedelta(hours=3), "最近3小时"),
("last_hour", timedelta(hours=1), "最近1小时"),
@@ -781,45 +782,216 @@ class StatisticOutputTask(AsyncTask):
<p class=\"info-item\"><strong>总请求数: </strong>{stat_data[TOTAL_REQ_CNT]}</p>
<p class=\"info-item\"><strong>总花费: </strong>{stat_data[TOTAL_COST]:.4f} ¥</p>
<h2>按模型分类统计</h2>
<table>
<thead><tr><th>模型名称</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr></thead>
<tbody>
{model_rows}
</tbody>
</table>
<div style="display: flex; flex-wrap: wrap; gap: 20px; margin: 20px 0;">
<div style="flex: 1; min-width: 300px;">
<h2>按模型分类统计</h2>
<table>
<thead><tr><th>模型名称</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr></thead>
<tbody>
{model_rows}
</tbody>
</table>
</div>
<div style="flex: 1; min-width: 300px;">
<h3>模型调用次数分布</h3>
<canvas id="modelPieChart_{div_id}" width="300" height="300"></canvas>
</div>
</div>
<h2>按模块分类统计</h2>
<table>
<thead>
<tr><th>模块名称</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr>
</thead>
<tbody>
{module_rows}
</tbody>
</table>
<div style="display: flex; flex-wrap: wrap; gap: 20px; margin: 20px 0;">
<div style="flex: 1; min-width: 300px;">
<h2>按模块分类统计</h2>
<table>
<thead>
<tr><th>模块名称</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr>
</thead>
<tbody>
{module_rows}
</tbody>
</table>
</div>
<div style="flex: 1; min-width: 300px;">
<h3>模块调用次数分布</h3>
<canvas id="modulePieChart_{div_id}" width="300" height="300"></canvas>
</div>
</div>
<h2>按请求类型分类统计</h2>
<table>
<thead>
<tr><th>请求类型</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr>
</thead>
<tbody>
{type_rows}
</tbody>
</table>
<div style="display: flex; flex-wrap: wrap; gap: 20px; margin: 20px 0;">
<div style="flex: 1; min-width: 300px;">
<h2>按请求类型分类统计</h2>
<table>
<thead>
<tr><th>请求类型</th><th>调用次数</th><th>输入Token</th><th>输出Token</th><th>Token总量</th><th>累计花费</th><th>平均耗时(秒)</th><th>标准差(秒)</th></tr>
</thead>
<tbody>
{type_rows}
</tbody>
</table>
</div>
<div style="flex: 1; min-width: 300px;">
<h3>请求类型分布</h3>
<canvas id="typePieChart_{div_id}" width="300" height="300"></canvas>
</div>
</div>
<h2>聊天消息统计</h2>
<table>
<thead>
<tr><th>联系人/群组名称</th><th>消息数量</th></tr>
</thead>
<tbody>
{chat_rows}
</tbody>
</table>
<div style="display: flex; flex-wrap: wrap; gap: 20px; margin: 20px 0;">
<div style="flex: 1; min-width: 300px;">
<h2>聊天消息统计</h2>
<table>
<thead>
<tr><th>联系人/群组名称</th><th>消息数量</th></tr>
</thead>
<tbody>
{chat_rows}
</tbody>
</table>
</div>
<div style="flex: 1; min-width: 300px;">
<h3>消息分布</h3>
<canvas id="chatPieChart_{div_id}" width="300" height="300"></canvas>
</div>
</div>
<script>
// 为当前统计卡片创建饼图
createPieCharts_{div_id}();
function createPieCharts_{div_id}() {{
const colors = ['#3498db', '#e74c3c', '#2ecc71', '#f39c12', '#9b59b6', '#1abc9c', '#34495e', '#e67e22', '#95a5a6', '#f1c40f'];
// 模型调用次数饼图
const modelData = {{
labels: {[f'"{model_name}"' for model_name in sorted(stat_data[REQ_CNT_BY_MODEL].keys())]},
datasets: [{{
data: {[stat_data[REQ_CNT_BY_MODEL][model_name] for model_name in sorted(stat_data[REQ_CNT_BY_MODEL].keys())]},
backgroundColor: colors[:len(stat_data[REQ_CNT_BY_MODEL])],
borderColor: colors[:len(stat_data[REQ_CNT_BY_MODEL])],
borderWidth: 2
}}]
}};
new Chart(document.getElementById('modelPieChart_{div_id}'), {{
type: 'pie',
data: modelData,
options: {{
responsive: true,
plugins: {{
legend: {{
position: 'bottom'
}},
tooltip: {{
callbacks: {{
label: function(context) {{
const total = context.dataset.data.reduce((a, b) => a + b, 0);
const percentage = ((context.parsed / total) * 100).toFixed(1);
return context.label + ': ' + context.parsed + ' (' + percentage + '%)';
}}
}}
}}
}}
}}
}});
// 模块调用次数饼图
const moduleData = {{
labels: {[f'"{module_name}"' for module_name in sorted(stat_data[REQ_CNT_BY_MODULE].keys())]},
datasets: [{{
data: {[stat_data[REQ_CNT_BY_MODULE][module_name] for module_name in sorted(stat_data[REQ_CNT_BY_MODULE].keys())]},
backgroundColor: colors[:len(stat_data[REQ_CNT_BY_MODULE])],
borderColor: colors[:len(stat_data[REQ_CNT_BY_MODULE])],
borderWidth: 2
}}]
}};
new Chart(document.getElementById('modulePieChart_{div_id}'), {{
type: 'pie',
data: moduleData,
options: {{
responsive: true,
plugins: {{
legend: {{
position: 'bottom'
}},
tooltip: {{
callbacks: {{
label: function(context) {{
const total = context.dataset.data.reduce((a, b) => a + b, 0);
const percentage = ((context.parsed / total) * 100).toFixed(1);
return context.label + ': ' + context.parsed + ' (' + percentage + '%)';
}}
}}
}}
}}
}}
}});
// 请求类型分布饼图
const typeData = {{
labels: {[f'"{req_type}"' for req_type in sorted(stat_data[REQ_CNT_BY_TYPE].keys())]},
datasets: [{{
data: {[stat_data[REQ_CNT_BY_TYPE][req_type] for req_type in sorted(stat_data[REQ_CNT_BY_TYPE].keys())]},
backgroundColor: colors[:len(stat_data[REQ_CNT_BY_TYPE])],
borderColor: colors[:len(stat_data[REQ_CNT_BY_TYPE])],
borderWidth: 2
}}]
}};
new Chart(document.getElementById('typePieChart_{div_id}'), {{
type: 'pie',
data: typeData,
options: {{
responsive: true,
plugins: {{
legend: {{
position: 'bottom'
}},
tooltip: {{
callbacks: {{
label: function(context) {{
const total = context.dataset.data.reduce((a, b) => a + b, 0);
const percentage = ((context.parsed / total) * 100).toFixed(1);
return context.label + ': ' + context.parsed + ' (' + percentage + '%)';
}}
}}
}}
}}
}}
}});
// 聊天消息分布饼图
const chatData = {{
labels: {[f'"{self.name_mapping[chat_id][0]}"' for chat_id in sorted(stat_data[MSG_CNT_BY_CHAT].keys())]},
datasets: [{{
data: {[stat_data[MSG_CNT_BY_CHAT][chat_id] for chat_id in sorted(stat_data[MSG_CNT_BY_CHAT].keys())]},
backgroundColor: colors[:len(stat_data[MSG_CNT_BY_CHAT])],
borderColor: colors[:len(stat_data[MSG_CNT_BY_CHAT])],
borderWidth: 2
}}]
}};
new Chart(document.getElementById('chatPieChart_{div_id}'), {{
type: 'pie',
data: chatData,
options: {{
responsive: true,
plugins: {{
legend: {{
position: 'bottom'
}},
tooltip: {{
callbacks: {{
label: function(context) {{
const total = context.dataset.data.reduce((a, b) => a + b, 0);
const percentage = ((context.parsed / total) * 100).toFixed(1);
return context.label + ': ' + context.parsed + ' (' + percentage + '%)';
}}
}}
}}
}}
}}
}});
}}
</script>
</div>
"""