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