mirror of
https://github.com/Nezumi-2711/astrbot_plugin_qq_group_daily_analysis.git
synced 2026-09-22 13:38:43 +00:00
fix(cr): pre-commit
This commit is contained in:
@@ -337,11 +337,19 @@ class QQGroupDailyAnalysis(Star):
|
|||||||
current_template = config_manager.get_report_template()
|
current_template = config_manager.get_report_template()
|
||||||
# 列出可用的模板
|
# 列出可用的模板
|
||||||
import os
|
import os
|
||||||
template_dir = os.path.join(os.path.dirname(__file__), "src", "reports", "templates")
|
|
||||||
|
template_dir = os.path.join(
|
||||||
|
os.path.dirname(__file__), "src", "reports", "templates"
|
||||||
|
)
|
||||||
available_templates = []
|
available_templates = []
|
||||||
if os.path.exists(template_dir):
|
if os.path.exists(template_dir):
|
||||||
available_templates = [d for d in os.listdir(template_dir) if os.path.isdir(os.path.join(template_dir, d)) and not d.startswith("__")]
|
available_templates = [
|
||||||
|
d
|
||||||
|
for d in os.listdir(template_dir)
|
||||||
|
if os.path.isdir(os.path.join(template_dir, d))
|
||||||
|
and not d.startswith("__")
|
||||||
|
]
|
||||||
|
|
||||||
template_list_str = "\n".join([f"• {t}" for t in available_templates])
|
template_list_str = "\n".join([f"• {t}" for t in available_templates])
|
||||||
yield event.plain_result(f"""🎨 当前报告模板: {current_template}
|
yield event.plain_result(f"""🎨 当前报告模板: {current_template}
|
||||||
|
|
||||||
@@ -353,10 +361,13 @@ class QQGroupDailyAnalysis(Star):
|
|||||||
|
|
||||||
# 检查模板是否存在
|
# 检查模板是否存在
|
||||||
import os
|
import os
|
||||||
template_dir = os.path.join(os.path.dirname(__file__), "src", "reports", "templates", template_name)
|
|
||||||
|
template_dir = os.path.join(
|
||||||
|
os.path.dirname(__file__), "src", "reports", "templates", template_name
|
||||||
|
)
|
||||||
if not os.path.exists(template_dir):
|
if not os.path.exists(template_dir):
|
||||||
yield event.plain_result(f"❌ 模板 '{template_name}' 不存在")
|
yield event.plain_result(f"❌ 模板 '{template_name}' 不存在")
|
||||||
return
|
return
|
||||||
|
|
||||||
config_manager.set_report_template(template_name)
|
config_manager.set_report_template(template_name)
|
||||||
yield event.plain_result(f"✅ 报告模板已设置为: {template_name}")
|
yield event.plain_result(f"✅ 报告模板已设置为: {template_name}")
|
||||||
|
|||||||
@@ -8,10 +8,12 @@ from typing import Any
|
|||||||
from astrbot.api import logger
|
from astrbot.api import logger
|
||||||
|
|
||||||
|
|
||||||
async def _try_get_provider_id_by_id(context, provider_id: str, description: str) -> str | None:
|
async def _try_get_provider_id_by_id(
|
||||||
|
context, provider_id: str, description: str
|
||||||
|
) -> str | None:
|
||||||
"""
|
"""
|
||||||
尝试通过 ID 获取 Provider ID 的辅助函数
|
尝试通过 ID 获取 Provider ID 的辅助函数
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
context: AstrBot上下文对象
|
context: AstrBot上下文对象
|
||||||
provider_id: Provider ID
|
provider_id: Provider ID
|
||||||
@@ -226,13 +228,17 @@ async def call_provider_with_retry(
|
|||||||
# 注意:llm_generate 可能不直接支持 max_tokens 和 temperature 参数,
|
# 注意:llm_generate 可能不直接支持 max_tokens 和 temperature 参数,
|
||||||
# 取决于 AstrBot 版本和具体实现。如果支持 kwargs,可以传递。
|
# 取决于 AstrBot 版本和具体实现。如果支持 kwargs,可以传递。
|
||||||
# 这里假设支持 kwargs 传递给底层 provider。
|
# 这里假设支持 kwargs 传递给底层 provider。
|
||||||
llm_resp = await context.llm_generate(
|
# 使用 asyncio.wait_for 包裹,继续遵守 timeout 参数并在超时时抛出 TimeoutError。
|
||||||
chat_provider_id=provider_id,
|
llm_resp = await asyncio.wait_for(
|
||||||
prompt=prompt,
|
context.llm_generate(
|
||||||
max_tokens=max_tokens,
|
chat_provider_id=provider_id,
|
||||||
temperature=temperature
|
prompt=prompt,
|
||||||
|
max_tokens=max_tokens,
|
||||||
|
temperature=temperature,
|
||||||
|
),
|
||||||
|
timeout=timeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
return llm_resp
|
return llm_resp
|
||||||
|
|
||||||
except asyncio.TimeoutError as e:
|
except asyncio.TimeoutError as e:
|
||||||
@@ -266,11 +272,13 @@ def extract_token_usage(response) -> dict | None:
|
|||||||
# 尝试从 LLMResponse 中提取 usage
|
# 尝试从 LLMResponse 中提取 usage
|
||||||
# 假设 LLMResponse 有 usage 属性或 raw_completion 属性
|
# 假设 LLMResponse 有 usage 属性或 raw_completion 属性
|
||||||
if hasattr(response, "usage") and response.usage:
|
if hasattr(response, "usage") and response.usage:
|
||||||
usage = response.usage
|
usage = response.usage
|
||||||
token_usage["prompt_tokens"] = getattr(usage, "prompt_tokens", 0) or 0
|
token_usage["prompt_tokens"] = getattr(usage, "prompt_tokens", 0) or 0
|
||||||
token_usage["completion_tokens"] = getattr(usage, "completion_tokens", 0) or 0
|
token_usage["completion_tokens"] = (
|
||||||
token_usage["total_tokens"] = getattr(usage, "total_tokens", 0) or 0
|
getattr(usage, "completion_tokens", 0) or 0
|
||||||
return token_usage
|
)
|
||||||
|
token_usage["total_tokens"] = getattr(usage, "total_tokens", 0) or 0
|
||||||
|
return token_usage
|
||||||
|
|
||||||
# 兼容旧的提取方式 (如果 response 是旧的 ProviderResponse)
|
# 兼容旧的提取方式 (如果 response 是旧的 ProviderResponse)
|
||||||
if getattr(response, "raw_completion", None) is not None:
|
if getattr(response, "raw_completion", None) is not None:
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ class HTMLTemplates:
|
|||||||
def _get_env(self) -> Environment:
|
def _get_env(self) -> Environment:
|
||||||
"""获取当前配置的模板环境"""
|
"""获取当前配置的模板环境"""
|
||||||
template_name = self.config_manager.get_report_template()
|
template_name = self.config_manager.get_report_template()
|
||||||
|
|
||||||
# 如果环境已缓存且配置未变(这里简单假设配置变了会重新获取,或者我们可以每次都检查)
|
# 如果环境已缓存且配置未变(这里简单假设配置变了会重新获取,或者我们可以每次都检查)
|
||||||
# 为了响应配置热更,我们每次都检查一下或者简单地按需创建
|
# 为了响应配置热更,我们每次都检查一下或者简单地按需创建
|
||||||
if template_name in self._envs:
|
if template_name in self._envs:
|
||||||
|
|||||||
@@ -132,11 +132,9 @@ class ActivityVisualizer:
|
|||||||
for hour in range(24):
|
for hour in range(24):
|
||||||
count = hourly_activity.get(hour, 0)
|
count = hourly_activity.get(hour, 0)
|
||||||
percentage = (count / max_activity) * 100 if max_activity > 0 else 0
|
percentage = (count / max_activity) * 100 if max_activity > 0 else 0
|
||||||
|
|
||||||
chart_data.append({
|
chart_data.append(
|
||||||
"hour": hour,
|
{"hour": hour, "count": count, "percentage": round(percentage, 1)}
|
||||||
"count": count,
|
)
|
||||||
"percentage": round(percentage, 1)
|
|
||||||
})
|
|
||||||
|
|
||||||
return chart_data
|
return chart_data
|
||||||
|
|||||||
Reference in New Issue
Block a user