AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

STEP 2 ⚓ pyupgrade+ruff check --fix

Open LIghtJUNction opened this issue 1 year ago • 4 comments

修复了 #XYZ

Motivation

Modifications

pyupgrade + ruff check --fix 安全的修改

Check

  • [ y] 我的 Commit Message 符合良好的规范
  • [y ] 我新增/修复/优化的功能经过良好的测试

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

使用 pyupgrade 将 Python 类型注解和代码风格升级到 Python 3.10+

增强功能:

  • 通过将 List 和 Dict 替换为 list 和 dict 来实现类型注解的现代化
  • 更新类型提示以使用新的 Python 3.10+ 联合类型语法
  • 通过删除冗余的编码参数来简化文件打开操作

日常维护:

  • 添加一个脚本来自动在整个项目中运行 pyupgrade
  • 通过标准化类型注解来提高代码一致性
Original summary in English

Summary by Sourcery

Upgrade Python type annotations and code style to Python 3.10+ using pyupgrade

Enhancements:

  • Modernize type annotations by replacing List and Dict with list and dict
  • Update type hints to use the new Python 3.10+ syntax for union types
  • Simplify file opening by removing redundant encoding parameters

Chores:

  • Add a script to automatically run pyupgrade across the project
  • Improve code consistency by standardizing type annotations

LIghtJUNction avatar Apr 19 '25 13:04 LIghtJUNction

## Sourcery 审查者指南

此 Pull Request 应用了 pyupgrade 和 ruff,以自动更新代码库,使其与 Python 3.10+ 兼容。它将 `List`、`Dict`、`Tuple` 和 `Union` 等类型提示替换为它们的现代等价物(`list`、`dict`、`tuple` 和 `|`),并删除了文件打开操作中多余的编码规范。

#### ProviderMetaData 的更新类图

```mermaid
classDiagram
  class ProviderMetaData {
    desc: str
    provider_type: ProviderType
    cls_type: type
    default_config_tmpl: dict
  }

AssistantMessageSegment 的更新类图

classDiagram
  class AssistantMessageSegment {
    content: str
    tool_calls: list[ChatCompletionMessageToolCall | dict]
    role: str
    to_dict()
  }

ToolCallsResult 的更新类图

classDiagram
  class ToolCallsResult {
    tool_calls_info: AssistantMessageSegment
    tool_calls_result: list[ToolCallMessageSegment]
    to_openai_messages() list[dict]
  }

ProviderRequest 的更新类图

classDiagram
  class ProviderRequest {
    prompt: str
    session_id: str
    image_urls: list[str]
    func_tool: FuncCall
    contexts: list
    assemble_context() dict
    _print_friendly_context()
  }

LLMResponse 的更新类图

classDiagram
  class LLMResponse {
    role: str
    result_chain: MessageChain
    tools_call_args: list[dict[str, any]]
    tools_call_name: list[str]
    tools_call_ids: list[str]
    raw_completion: ChatCompletion
    _new_record: dict[str, any]
    _completion_text: str
    completion_text(value)
    to_openai_tool_calls() list[dict]
  }

FuncCall 的更新类图

classDiagram
  class FuncCall {
    func_list: list[FuncTool]
    mcp_client_dict: dict[str, MCPClient]
    mcp_client_event: dict[str, asyncio.Event]
    empty() bool
    register_tool(func_tool: FuncTool)
    get_func_desc_anthropic_style() list
    get_func_desc_google_genai_style() dict
  }

Personality 的更新类图

classDiagram
  class Personality {
    prompt: str
    name: str
    begin_dialogs: list[str]
    mood_imitation_dialogs: list[str]
    _begin_dialogs_processed: list[dict]
    _mood_imitation_dialogs_processed: str
  }

BaseDatabase 的更新类图

classDiagram
  class BaseDatabase {
    update_llm_history(session_id: str, content: str, provider_type: str)
    get_llm_history(session_id: str, provider_type: str) list[LLMHistory]
    get_atri_vision_data() list[ATRIVision]
    get_conversations(user_id: str) list[Conversation]
    get_all_conversations(page: int, page_size: int) tuple[list[dict[str, Any]], int]
    get_filtered_conversations(page: int, page_size: int, platforms: list[str], message_types: list[str], search_query: str, exclude_ids: list[str], exclude_platforms: list[str]) tuple[list[dict[str, Any]], int]
  }

AstrMessageEvent 的更新类图

classDiagram
  class AstrMessageEvent {
    _outline_chain(chain: list[BaseMessageComponent]) str
    get_messages() list[BaseMessageComponent]
    chain_result(chain: list[BaseMessageComponent]) MessageEventResult
    request_llm(prompt: str, func_tool_manager, session_id: str, image_urls: list[str], contexts: list, system_prompt: str, conversation: Conversation) ProviderRequest
    get_group(group_id: str, **kwargs) Group | None
  }

Context 的更新类图

classDiagram
  class Context {
    _register_tasks: list[Awaitable]
    get_all_stars() list[StarMetadata]
    get_all_providers() list[Provider]
    get_all_tts_providers() list[TTSProvider]
    get_all_stt_providers() list[STTProvider]
    get_platform(platform_type: PlatformAdapterType | str) Platform
    send_message(session: str | MessageSesion, message_chain: MessageChain) bool
  }

MessageChain 的更新类图

classDiagram
  class MessageChain {
    chain: list[BaseMessageComponent]
    use_t2i_: bool | None
  }

KnowledgeDBManager 的更新类图

classDiagram
  class KnowledgeDBManager {
    store_insts: dict[str, Store]
    list_knowledge_db() list[str]
    create_knowledge_db(name: str, config: dict)
    retrive_records(name: str, query: str, top_n: int) list[str]
    _fixed_chunk(text: str, chunk_size: int, chunk_overlap: int) list[str]
  }

CommandFilter 的更新类图

classDiagram
  class CommandFilter {
    parent_command_names: list[str]
    custom_filter_list: list[CustomFilter]
    validate_and_convert_params(params: list[Any], param_type: dict[str, type]) dict[str, Any]
  }

StarManager 的更新类图

classDiagram
  class StarManager {
    _get_plugin_modules() list[dict]
  }

TextMeasurer 的更新类图

classDiagram
  class TextMeasurer {
    get_text_size(text: str, font: ImageFont.FreeTypeFont) tuple[int, int]
    split_text_to_fit_width(text: str, font: ImageFont.FreeTypeFont, max_width: int) list[str]
  }

CodeBlockElement 的更新类图

classDiagram
  class CodeBlockElement {
    content: list[str]
  }

registered_stages 的更新类图

classDiagram
  class Stage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }
  class registered_stages {
    List[Stage]
  }

ChromaVectorStore 的更新类图

classDiagram
  class ChromaVectorStore {
    query(query: str, top_n=3, metadata_filter: dict) list[str]
  }

Stats 的更新类图

classDiagram
  class Stats {
    platform: list[Platform]
    command: list[Command]
    llm: list[Provider]
  }

StarTools 的更新类图

classDiagram
  class StarTools {
    send_message(session: str | MessageSesion, message_chain: MessageChain) bool
    create_message(session_id: str, message_id: str, sender: MessageMember, message: list[BaseMessageComponent], message_str: str, raw_message: object, group_id: str) AstrBotMessage
    get_data_dir(plugin_name: str | None) Path
  }

CoreLifecycle 的更新类图

classDiagram
  class CoreLifecycle {
    curr_tasks: list[asyncio.Task]
    load_platform() list[asyncio.Task]
  }

ProcessStage 的更新类图

classDiagram
  class ProcessStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

RespondStage 的更新类图

classDiagram
  class RespondStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

OpenAIEmbedding 的更新类图

classDiagram
  class OpenAIEmbedding {
    get_embedding(text) list[float]
  }

LogBroker 的更新类图

classDiagram
  class LogBroker {
    subscribers: list[Queue]
  }

PlatformAdapterTypeFilter 的更新类图

classDiagram
  class PlatformAdapterTypeFilter {
    __init__(platform_adapter_type_or_str: PlatformAdapterType | str)
  }

ConfigRoute 的更新类图

classDiagram
  class ConfigRoute {
    validate_config(data, schema: dict, is_core: bool) tuple[list[str], dict]
  }

SQLitePluginStorage 的更新类图

classDiagram
  class SQLitePluginStorage {
    __new__(cls)
  }

ContentSafetyStage 的更新类图

classDiagram
  class ContentSafetyStage {
    process(event: AstrMessageEvent, check_text: str) None | AsyncGenerator[None, None]
  }

ContentSafetyStrategy 的更新类图

classDiagram
  class ContentSafetyStrategy {
    check(content: str) tuple[bool, str]
  }

PlatformCompatibilityStage 的更新类图

classDiagram
  class PlatformCompatibilityStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

PreprocessStage 的更新类图

classDiagram
  class PreprocessStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

RateLimitCheckStage 的更新类图

classDiagram
  class RateLimitCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

ResultDecorateStage 的更新类图

classDiagram
  class ResultDecorateStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

WakingCheckStage 的更新类图

classDiagram
  class WakingCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

WhitelistCheckStage 的更新类图

classDiagram
  class WhitelistCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

LarkEvent 的更新类图

classDiagram
  class LarkEvent {
    _convert_to_lark(message: MessageChain, lark_client: lark.Client) list
  }

文件级别变更

变更 详情 文件
将 Type 替换为 type 以进行类型提示。
  • 在 ProviderMetaData 中将 Type 替换为 type。
astrbot/core/provider/entities.py
将 List 替换为 list 以进行类型提示。
  • 在 AssistantMessageSegment 中将 List 替换为 list。
  • 在 ToolCallsResult 中将 List 替换为 list。
  • 在 ProviderRequest 中将 List 替换为 list。
  • 在 LLMResponse 中将 List 替换为 list。
  • 在 GeminiSource.__init__ 中将 List 替换为 list。
  • 在 GeminiSource._handle_api_error 中将 List 替换为 list。
  • 在 GeminiSource._prepare_conversation 中将 List 替换为 list。
  • 在 GeminiSource.text_chat 中将 List 替换为 list。
  • 在 GeminiSource.text_chat_stream 中将 List 替换为 list。
  • 在 GeminiSource.get_keys 中将 List 替换为 list。
  • 在 OpenAISource.__init__ 中将 List 替换为 list。
  • 在 OpenAISource._handle_api_error 中将 List 替换为 list。
  • 在 OpenAISource.text_chat 中将 List 替换为 list。
  • 在 OpenAISource.text_chat_stream 中将 List 替换为 list。
  • 在 OpenAISource.get_keys 中将 List 替换为 list。
  • 在 AnthropicSource.__init__ 中将 List 替换为 list。
  • 在 AnthropicSource.text_chat 中将 List 替换为 list。
  • 在 Personality 中将 List 替换为 list。
  • 在 Provider.get_keys 中将 List 替换为 list。
  • 在 Provider.text_chat 中将 List 替换为 list。
  • 在 Provider.text_chat_stream 中将 List 替换为 list。
  • 在 BaseDatabase.get_llm_history 中将 List 替换为 list。
  • 在 BaseDatabase.get_conversations 中将 List 替换为 list。
  • 在 FuncCall.__init__ 中将 List 替换为 list。
  • 在 MCPClient.__init__ 中将 List 替换为 list。
  • 在 CommandFilter.__init__ 中将 List 替换为 list。
  • 在 CommandGroupFilter.__init__ 中将 List 替换为 list。
  • 在 StarHandlerRegistry.get_handlers_by_event_type 中将 List 替换为 list。
  • 在 StarHandlerRegistry.get_handlers_by_module_name 中将 List 替换为 list。
  • 在 StarHandlerMetadata.__init__ 中将 List 替换为 list。
  • 在 MessageChain.__init__ 中将 List 替换为 list。
  • 在 SessionWaiter.__init__ 中将 List 替换为 list。
  • 在 LogBroker.__init__ 中将 List 替换为 list。
  • 在 StrategySelector.__init__ 中将 List 替换为 list。
  • 在 ChromaVectorStore.query 中将 List 替换为 list。
  • 在 SQLiteDatabase.get_llm_history 中将 List 替换为 list。
  • 在 SQLiteDatabase.get_conversations 中将 List 替换为 list。
  • 在 ATRIVision.__init__ 中将 List 替换为 list。
  • 在 Stats.__init__ 中将 List 替换为 list。
  • 在 QQOfficialPlatformAdapter._parse_from_qqofficial 中将 List 替换为 list。
  • 在 LarkEvent._convert_to_lark 中将 List 替换为 list。
  • 在 MarkdownParser.parse 中将 List 替换为 list。
  • 在 TextMeasurer.split_text_to_fit_width 中将 List 替换为 list。
  • 在 CodeBlockElement.__init__ 中将 List 替换为 list。
  • 在 StarMetadata.__init__ 中将 List 替换为 list。
  • 在 CoreLifecycle.load_platform 中将 List 替换为 list。
astrbot/core/provider/entities.py
astrbot/core/provider/sources/gemini_source.py
astrbot/core/provider/sources/openai_source.py
astrbot/core/provider/sources/anthropic_source.py
astrbot/core/provider/provider.py
astrbot/core/db/__init__.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/filter/command.py
astrbot/core/star/filter/command_group.py
astrbot/core/star/star_handler.py
astrbot/core/message/message_event_result.py
astrbot/core/utils/session_waiter.py
astrbot/core/log.py
astrbot/core/pipeline/content_safety_check/strategies/strategy.py
astrbot/core/rag/store/chroma_db.py
astrbot/core/db/sqlite.py
astrbot/core/db/po.py
astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py
astrbot/core/platform/sources/lark/lark_event.py
astrbot/core/utils/t2i/local_strategy.py
astrbot/core/star/star.py
astrbot/core/core_lifecycle.py
将 Dict 替换为 dict 以进行类型提示。
  • 在 ProviderMetaData 中将 Dict 替换为 dict。
  • 在 FuncTool.__init__ 中将 Dict 替换为 dict。
  • 在 FuncCall.__init__ 中将 Dict 替换为 dict。
  • 在 CommandFilter.validate_and_convert_params 中将 Dict 替换为 dict。
  • 在 StarHandlerRegistry.star_handlers_map 中将 Dict 替换为 dict。
  • 在 ChromaVectorStore.__init__ 中将 Dict 替换为 dict。
  • 在 KnowledgeDBManager.__init__ 中将 Dict 替换为 dict。
  • 在 KnowledgeDBManager.create_knowledge_db 中将 Dict 替换为 dict。
  • 在 DifyAPIClient.chat_messages 中将 Dict 替换为 dict。
  • 在 DifyAPIClient.file_upload 中将 Dict 替换为 dict。
  • 在 StarMetadata.__init__ 中将 Dict 替换为 dict。
  • 在 AstrBotConfig.check_config_integrity 中将 Dict 替换为 dict。
  • 在 ConfigRoute.validate_config 中将 Dict 替换为 dict。
astrbot/core/provider/entities.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/filter/command.py
astrbot/core/star/star_handler.py
astrbot/core/rag/store/chroma_db.py
astrbot/core/rag/knowledge_db_mgr.py
astrbot/core/utils/dify_api_client.py
astrbot/core/star/star.py
astrbot/core/config/astrbot_config.py
astrbot/dashboard/routes/config.py
将 Tuple 替换为 tuple 以进行类型提示。
  • 在 SQLiteDatabase._exec_sql 中将 Tuple 替换为 tuple。
  • 在 SQLiteDatabase.get_llm_history 中将 Tuple 替换为 tuple。
  • 在 SQLiteDatabase.get_conversations 中将 Tuple 替换为 tuple。
  • 在 SQLiteDatabase.get_all_conversations 中将 Tuple 替换为 tuple。
  • 在 SQLiteDatabase.get_filtered_conversations 中将 Tuple 替换为 tuple。
  • 在 TextMeasurer.get_text_size 中将 Tuple 替换为 tuple。
  • 在 MarkdownRenderer.__init__ 中将 Tuple 替换为 tuple。
  • 在 StrategySelector.check 中将 Tuple 替换为 tuple。
  • 在 ConfigRoute.validate_config 中将 Tuple 替换为 tuple。
astrbot/core/db/sqlite.py
astrbot/core/utils/t2i/local_strategy.py
astrbot/core/pipeline/content_safety_check/strategies/strategy.py
astrbot/dashboard/routes/config.py
将 Optional[str] 替换为 `str None` 以进行类型提示。
  • 在 GeminiSource.__init__ 中将 Optional[str] 替换为 `str
将 Union 替换为 ` ` 以进行类型提示。
  • 在 AstrMessageEvent.set_result 中将 Union 替换为 `
将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 Stage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 Stage._call_handler 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 LLMRequestStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 StarRequestStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 ProcessStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 RespondStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 ContentSafetyCheckStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 PlatformCompatibilityStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 PreProcessStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 RateLimitCheckStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 ResultDecorateStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 WakingCheckStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
  • 在 WhitelistCheckStage.process 中将 AsyncGenerator[None, None] 替换为 AsyncGenerator[None]。
astrbot/core/pipeline/stage.py
astrbot/core/pipeline/process_stage/method/llm_request.py
astrbot/core/pipeline/process_stage/method/star_request.py
astrbot/core/pipeline/process_stage/stage.py
astrbot/core/pipeline/respond/stage.py
astrbot/core/pipeline/content_safety_check/stage.py
astrbot/core/pipeline/platform_compatibility/stage.py
astrbot/core/pipeline/preprocess_stage/stage.py
astrbot/core/pipeline/rate_limit_check/stage.py
astrbot/core/pipeline/result_decorate/stage.py
astrbot/core/pipeline/waking_check/stage.py
astrbot/core/pipeline/whitelist_check/stage.py
将 Optional 替换为 ` None` 以进行类型提示。
  • 在 MessageChain.__init__ 中将 Optional 替换为 `
在 open 调用中删除了多余或不必要的编码规范。
  • 从 SQLiteDatabase.__init__ 中删除 encoding="utf-8"。
  • 从 FuncCall._init_mcp_clients 中删除 encoding="utf-8"。
  • 从 StarManager._load_plugin_metadata 中删除 encoding="utf-8"。
  • 从 StarManager.install_plugin 中删除 encoding="utf-8"。
  • 从 StarManager.install_plugin_from_file 中删除 encoding="utf-8"。
  • 从 NetworkTextToImageRender.render 中删除 encoding="utf-8"。
astrbot/core/db/sqlite.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/star_manager.py
astrbot/core/utils/t2i/network_strategy.py
更改了 load_config 函数的返回类型注解。
  • 在 load_config 函数中将 Union[dict, bool] 更改为 `dict
bool`。

提示和命令

与 Sourcery 互动

  • 触发新的审查: 在 Pull Request 上评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub Issue: 通过回复审查评论,要求 Sourcery 从该评论创建一个 Issue。您也可以回复评论并使用 @sourcery-ai issue 来创建 Issue。
  • 生成 Pull Request 标题: 在 Pull Request 标题中的任何位置写入 @sourcery-ai,以随时生成标题。您也可以在 Pull Request 上评论 @sourcery-ai title 以随时(重新)生成标题。
  • 生成 Pull Request 摘要: 在 Pull Request 正文中的任何位置写入 @sourcery-ai summary,以在您想要的任何位置随时生成 PR 摘要。您也可以在 Pull Request 上评论 @sourcery-ai summary 以随时(重新)生成摘要。
  • 生成审查者指南: 在 Pull Request 上评论 @sourcery-ai guide 以随时(重新)生成审查者指南。
  • 解决所有 Sourcery 评论: 在 Pull Request 上评论 @sourcery-ai resolve 以解决所有 Sourcery 评论。如果您已经处理了所有评论并且不想再看到它们,这将非常有用。
  • 驳回所有 Sourcery 审查: 在 Pull Request 上评论 @sourcery-ai dismiss 以驳回所有现有的 Sourcery 审查。如果您想重新开始新的审查,这将特别有用 - 不要忘记评论 @sourcery-ai review 以触发新的审查!
  • 为 Issue 生成行动计划: 在 Issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

  • 启用或禁用审查功能,例如 Sourcery 生成的 Pull Request 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

  • 联系我们的支持团队 提出问题或反馈。
  • 访问我们的 文档 获取详细指南和信息。
  • 通过在 X/Twitter、LinkedIn 或 GitHub 上关注我们,与 Sourcery 团队保持联系。
```
Original review guide in English

Reviewer's Guide by Sourcery

This pull request applies pyupgrade and ruff to automatically modernize the codebase to be compatible with Python 3.10+. It replaces type hints like List, Dict, Tuple, and Union with their modern equivalents (list, dict, tuple, and |), and removes redundant encoding specifications in file opening operations.

Updated class diagram for ProviderMetaData

classDiagram
  class ProviderMetaData {
    desc: str
    provider_type: ProviderType
    cls_type: type
    default_config_tmpl: dict
  }

Updated class diagram for AssistantMessageSegment

classDiagram
  class AssistantMessageSegment {
    content: str
    tool_calls: list[ChatCompletionMessageToolCall | dict]
    role: str
    to_dict()
  }

Updated class diagram for ToolCallsResult

classDiagram
  class ToolCallsResult {
    tool_calls_info: AssistantMessageSegment
    tool_calls_result: list[ToolCallMessageSegment]
    to_openai_messages() list[dict]
  }

Updated class diagram for ProviderRequest

classDiagram
  class ProviderRequest {
    prompt: str
    session_id: str
    image_urls: list[str]
    func_tool: FuncCall
    contexts: list
    assemble_context() dict
    _print_friendly_context()
  }

Updated class diagram for LLMResponse

classDiagram
  class LLMResponse {
    role: str
    result_chain: MessageChain
    tools_call_args: list[dict[str, any]]
    tools_call_name: list[str]
    tools_call_ids: list[str]
    raw_completion: ChatCompletion
    _new_record: dict[str, any]
    _completion_text: str
    completion_text(value)
    to_openai_tool_calls() list[dict]
  }

Updated class diagram for FuncCall

classDiagram
  class FuncCall {
    func_list: list[FuncTool]
    mcp_client_dict: dict[str, MCPClient]
    mcp_client_event: dict[str, asyncio.Event]
    empty() bool
    register_tool(func_tool: FuncTool)
    get_func_desc_anthropic_style() list
    get_func_desc_google_genai_style() dict
  }

Updated class diagram for Personality

classDiagram
  class Personality {
    prompt: str
    name: str
    begin_dialogs: list[str]
    mood_imitation_dialogs: list[str]
    _begin_dialogs_processed: list[dict]
    _mood_imitation_dialogs_processed: str
  }

Updated class diagram for BaseDatabase

classDiagram
  class BaseDatabase {
    update_llm_history(session_id: str, content: str, provider_type: str)
    get_llm_history(session_id: str, provider_type: str) list[LLMHistory]
    get_atri_vision_data() list[ATRIVision]
    get_conversations(user_id: str) list[Conversation]
    get_all_conversations(page: int, page_size: int) tuple[list[dict[str, Any]], int]
    get_filtered_conversations(page: int, page_size: int, platforms: list[str], message_types: list[str], search_query: str, exclude_ids: list[str], exclude_platforms: list[str]) tuple[list[dict[str, Any]], int]
  }

Updated class diagram for AstrMessageEvent

classDiagram
  class AstrMessageEvent {
    _outline_chain(chain: list[BaseMessageComponent]) str
    get_messages() list[BaseMessageComponent]
    chain_result(chain: list[BaseMessageComponent]) MessageEventResult
    request_llm(prompt: str, func_tool_manager, session_id: str, image_urls: list[str], contexts: list, system_prompt: str, conversation: Conversation) ProviderRequest
    get_group(group_id: str, **kwargs) Group | None
  }

Updated class diagram for Context

classDiagram
  class Context {
    _register_tasks: list[Awaitable]
    get_all_stars() list[StarMetadata]
    get_all_providers() list[Provider]
    get_all_tts_providers() list[TTSProvider]
    get_all_stt_providers() list[STTProvider]
    get_platform(platform_type: PlatformAdapterType | str) Platform
    send_message(session: str | MessageSesion, message_chain: MessageChain) bool
  }

Updated class diagram for MessageChain

classDiagram
  class MessageChain {
    chain: list[BaseMessageComponent]
    use_t2i_: bool | None
  }

Updated class diagram for KnowledgeDBManager

classDiagram
  class KnowledgeDBManager {
    store_insts: dict[str, Store]
    list_knowledge_db() list[str]
    create_knowledge_db(name: str, config: dict)
    retrive_records(name: str, query: str, top_n: int) list[str]
    _fixed_chunk(text: str, chunk_size: int, chunk_overlap: int) list[str]
  }

Updated class diagram for CommandFilter

classDiagram
  class CommandFilter {
    parent_command_names: list[str]
    custom_filter_list: list[CustomFilter]
    validate_and_convert_params(params: list[Any], param_type: dict[str, type]) dict[str, Any]
  }

Updated class diagram for StarManager

classDiagram
  class StarManager {
    _get_plugin_modules() list[dict]
  }

Updated class diagram for TextMeasurer

classDiagram
  class TextMeasurer {
    get_text_size(text: str, font: ImageFont.FreeTypeFont) tuple[int, int]
    split_text_to_fit_width(text: str, font: ImageFont.FreeTypeFont, max_width: int) list[str]
  }

Updated class diagram for CodeBlockElement

classDiagram
  class CodeBlockElement {
    content: list[str]
  }

Updated class diagram for registered_stages

classDiagram
  class Stage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }
  class registered_stages {
    List[Stage]
  }

Updated class diagram for ChromaVectorStore

classDiagram
  class ChromaVectorStore {
    query(query: str, top_n=3, metadata_filter: dict) list[str]
  }

Updated class diagram for Stats

classDiagram
  class Stats {
    platform: list[Platform]
    command: list[Command]
    llm: list[Provider]
  }

Updated class diagram for StarTools

classDiagram
  class StarTools {
    send_message(session: str | MessageSesion, message_chain: MessageChain) bool
    create_message(session_id: str, message_id: str, sender: MessageMember, message: list[BaseMessageComponent], message_str: str, raw_message: object, group_id: str) AstrBotMessage
    get_data_dir(plugin_name: str | None) Path
  }

Updated class diagram for CoreLifecycle

classDiagram
  class CoreLifecycle {
    curr_tasks: list[asyncio.Task]
    load_platform() list[asyncio.Task]
  }

Updated class diagram for ProcessStage

classDiagram
  class ProcessStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for RespondStage

classDiagram
  class RespondStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for OpenAIEmbedding

classDiagram
  class OpenAIEmbedding {
    get_embedding(text) list[float]
  }

Updated class diagram for LogBroker

classDiagram
  class LogBroker {
    subscribers: list[Queue]
  }

Updated class diagram for PlatformAdapterTypeFilter

classDiagram
  class PlatformAdapterTypeFilter {
    __init__(platform_adapter_type_or_str: PlatformAdapterType | str)
  }

Updated class diagram for ConfigRoute

classDiagram
  class ConfigRoute {
    validate_config(data, schema: dict, is_core: bool) tuple[list[str], dict]
  }

Updated class diagram for SQLitePluginStorage

classDiagram
  class SQLitePluginStorage {
    __new__(cls)
  }

Updated class diagram for ContentSafetyStage

classDiagram
  class ContentSafetyStage {
    process(event: AstrMessageEvent, check_text: str) None | AsyncGenerator[None, None]
  }

Updated class diagram for ContentSafetyStrategy

classDiagram
  class ContentSafetyStrategy {
    check(content: str) tuple[bool, str]
  }

Updated class diagram for PlatformCompatibilityStage

classDiagram
  class PlatformCompatibilityStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for PreprocessStage

classDiagram
  class PreprocessStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for RateLimitCheckStage

classDiagram
  class RateLimitCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for ResultDecorateStage

classDiagram
  class ResultDecorateStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for WakingCheckStage

classDiagram
  class WakingCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for WhitelistCheckStage

classDiagram
  class WhitelistCheckStage {
    process(event: AstrMessageEvent) None | AsyncGenerator[None, None]
  }

Updated class diagram for LarkEvent

classDiagram
  class LarkEvent {
    _convert_to_lark(message: MessageChain, lark_client: lark.Client) list
  }

File-Level Changes

Change Details Files
Replaced Type with type for type hinting.
  • Replaced Type with type in ProviderMetaData.
astrbot/core/provider/entities.py
Replaced List with list for type hinting.
  • Replaced List with list in AssistantMessageSegment.
  • Replaced List with list in ToolCallsResult.
  • Replaced List with list in ProviderRequest.
  • Replaced List with list in LLMResponse.
  • Replaced List with list in GeminiSource.__init__.
  • Replaced List with list in GeminiSource._handle_api_error.
  • Replaced List with list in GeminiSource._prepare_conversation.
  • Replaced List with list in GeminiSource.text_chat.
  • Replaced List with list in GeminiSource.text_chat_stream.
  • Replaced List with list in GeminiSource.get_keys.
  • Replaced List with list in OpenAISource.__init__.
  • Replaced List with list in OpenAISource._handle_api_error.
  • Replaced List with list in OpenAISource.text_chat.
  • Replaced List with list in OpenAISource.text_chat_stream.
  • Replaced List with list in OpenAISource.get_keys.
  • Replaced List with list in AnthropicSource.__init__.
  • Replaced List with list in AnthropicSource.text_chat.
  • Replaced List with list in Personality.
  • Replaced List with list in Provider.get_keys.
  • Replaced List with list in Provider.text_chat.
  • Replaced List with list in Provider.text_chat_stream.
  • Replaced List with list in BaseDatabase.get_llm_history.
  • Replaced List with list in BaseDatabase.get_conversations.
  • Replaced List with list in FuncCall.__init__.
  • Replaced List with list in MCPClient.__init__.
  • Replaced List with list in CommandFilter.__init__.
  • Replaced List with list in CommandGroupFilter.__init__.
  • Replaced List with list in StarHandlerRegistry.get_handlers_by_event_type.
  • Replaced List with list in StarHandlerRegistry.get_handlers_by_module_name.
  • Replaced List with list in StarHandlerMetadata.__init__.
  • Replaced List with list in MessageChain.__init__.
  • Replaced List with list in SessionWaiter.__init__.
  • Replaced List with list in LogBroker.__init__.
  • Replaced List with list in StrategySelector.__init__.
  • Replaced List with list in ChromaVectorStore.query.
  • Replaced List with list in SQLiteDatabase.get_llm_history.
  • Replaced List with list in SQLiteDatabase.get_conversations.
  • Replaced List with list in ATRIVision.__init__.
  • Replaced List with list in Stats.__init__.
  • Replaced List with list in QQOfficialPlatformAdapter._parse_from_qqofficial.
  • Replaced List with list in LarkEvent._convert_to_lark.
  • Replaced List with list in MarkdownParser.parse.
  • Replaced List with list in TextMeasurer.split_text_to_fit_width.
  • Replaced List with list in CodeBlockElement.__init__.
  • Replaced List with list in StarMetadata.__init__.
  • Replaced List with list in CoreLifecycle.load_platform.
astrbot/core/provider/entities.py
astrbot/core/provider/sources/gemini_source.py
astrbot/core/provider/sources/openai_source.py
astrbot/core/provider/sources/anthropic_source.py
astrbot/core/provider/provider.py
astrbot/core/db/__init__.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/filter/command.py
astrbot/core/star/filter/command_group.py
astrbot/core/star/star_handler.py
astrbot/core/message/message_event_result.py
astrbot/core/utils/session_waiter.py
astrbot/core/log.py
astrbot/core/pipeline/content_safety_check/strategies/strategy.py
astrbot/core/rag/store/chroma_db.py
astrbot/core/db/sqlite.py
astrbot/core/db/po.py
astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py
astrbot/core/platform/sources/lark/lark_event.py
astrbot/core/utils/t2i/local_strategy.py
astrbot/core/star/star.py
astrbot/core/core_lifecycle.py
Replaced Dict with dict for type hinting.
  • Replaced Dict with dict in ProviderMetaData.
  • Replaced Dict with dict in FuncTool.__init__.
  • Replaced Dict with dict in FuncCall.__init__.
  • Replaced Dict with dict in CommandFilter.validate_and_convert_params.
  • Replaced Dict with dict in StarHandlerRegistry.star_handlers_map.
  • Replaced Dict with dict in ChromaVectorStore.__init__.
  • Replaced Dict with dict in KnowledgeDBManager.__init__.
  • Replaced Dict with dict in KnowledgeDBManager.create_knowledge_db.
  • Replaced Dict with dict in DifyAPIClient.chat_messages.
  • Replaced Dict with dict in DifyAPIClient.file_upload.
  • Replaced Dict with dict in StarMetadata.__init__.
  • Replaced Dict with dict in AstrBotConfig.check_config_integrity.
  • Replaced Dict with dict in ConfigRoute.validate_config.
astrbot/core/provider/entities.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/filter/command.py
astrbot/core/star/star_handler.py
astrbot/core/rag/store/chroma_db.py
astrbot/core/rag/knowledge_db_mgr.py
astrbot/core/utils/dify_api_client.py
astrbot/core/star/star.py
astrbot/core/config/astrbot_config.py
astrbot/dashboard/routes/config.py
Replaced Tuple with tuple for type hinting.
  • Replaced Tuple with tuple in SQLiteDatabase._exec_sql.
  • Replaced Tuple with tuple in SQLiteDatabase.get_llm_history.
  • Replaced Tuple with tuple in SQLiteDatabase.get_conversations.
  • Replaced Tuple with tuple in SQLiteDatabase.get_all_conversations.
  • Replaced Tuple with tuple in SQLiteDatabase.get_filtered_conversations.
  • Replaced Tuple with tuple in TextMeasurer.get_text_size.
  • Replaced Tuple with tuple in MarkdownRenderer.__init__.
  • Replaced Tuple with tuple in StrategySelector.check.
  • Replaced Tuple with tuple in ConfigRoute.validate_config.
astrbot/core/db/sqlite.py
astrbot/core/utils/t2i/local_strategy.py
astrbot/core/pipeline/content_safety_check/strategies/strategy.py
astrbot/dashboard/routes/config.py
Replaced Optional[str] with `str None` for type hinting.
  • Replaced Optional[str] with `str
Replaced Union with ` ` for type hinting.
  • Replaced Union with `
Replaced AsyncGenerator[None, None] with AsyncGenerator[None].
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in Stage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in Stage._call_handler.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in LLMRequestStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in StarRequestStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in ProcessStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in RespondStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in ContentSafetyCheckStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in PlatformCompatibilityStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in PreProcessStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in RateLimitCheckStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in ResultDecorateStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in WakingCheckStage.process.
  • Replaced AsyncGenerator[None, None] with AsyncGenerator[None] in WhitelistCheckStage.process.
astrbot/core/pipeline/stage.py
astrbot/core/pipeline/process_stage/method/llm_request.py
astrbot/core/pipeline/process_stage/method/star_request.py
astrbot/core/pipeline/process_stage/stage.py
astrbot/core/pipeline/respond/stage.py
astrbot/core/pipeline/content_safety_check/stage.py
astrbot/core/pipeline/platform_compatibility/stage.py
astrbot/core/pipeline/preprocess_stage/stage.py
astrbot/core/pipeline/rate_limit_check/stage.py
astrbot/core/pipeline/result_decorate/stage.py
astrbot/core/pipeline/waking_check/stage.py
astrbot/core/pipeline/whitelist_check/stage.py
Replaced Optional with ` None` for type hinting.
  • Replaced Optional with `
Removed encoding specification in open calls where it was redundant or unnecessary.
  • Removed encoding="utf-8" from SQLiteDatabase.__init__.
  • Removed encoding="utf-8" from FuncCall._init_mcp_clients.
  • Removed encoding="utf-8" from StarManager._load_plugin_metadata.
  • Removed encoding="utf-8" from StarManager.install_plugin.
  • Removed encoding="utf-8" from StarManager.install_plugin_from_file.
  • Removed encoding="utf-8" from NetworkTextToImageRender.render.
astrbot/core/db/sqlite.py
astrbot/core/provider/func_tool_manager.py
astrbot/core/star/star_manager.py
astrbot/core/utils/t2i/network_strategy.py
Changed the return type annotation for load_config function.
  • Changed Union[dict, bool] to `dict
boolinload_config` function.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an issue from a review comment by replying to it. You can also reply to a review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull request title to generate a title at any time. You can also comment @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in the pull request body to generate a PR summary at any time exactly where you want it. You can also comment @sourcery-ai summary on the pull request to (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the pull request to resolve all Sourcery comments. Useful if you've already addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull request to dismiss all existing Sourcery reviews. Especially useful if you want to start fresh with a new review - don't forget to comment @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

  • Contact our support team for questions or feedback.
  • Visit our documentation for detailed guides and information.
  • Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.

sourcery-ai[bot] avatar Apr 19 '25 13:04 sourcery-ai[bot]

不推荐通过新增脚本实现自动更新。更优的做法是将更新逻辑集成到 pre-commit hook 中,以确保代码提交前自动执行相关检查。

例:

- repo: https://github.com/asottile/pyupgrade
    rev: v3.19.1
    hooks:
    - id: pyupgrade
      args: [--py310-plus]

Raven95676 avatar Apr 19 '25 14:04 Raven95676

不推荐通过新增脚本实现自动更新。更优的做法是将更新逻辑集成到 pre-commit hook 中,以确保代码提交前自动执行相关检查。

例:

- repo: https://github.com/asottile/pyupgrade
    rev: v3.19.1
    hooks:
    - id: pyupgrade
      args: [--py310-plus]

对,这个脚本文件取消上传了 按你这个来

LIghtJUNction avatar Apr 19 '25 14:04 LIghtJUNction

等合并后,我再进一步修改

LIghtJUNction avatar Apr 19 '25 14:04 LIghtJUNction