Skip to content

STEP 2 ⚓ pyupgrade+ruff check --fix #1335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

LIghtJUNction
Copy link
Contributor

@LIghtJUNction LIghtJUNction commented Apr 19, 2025

修复了 #XYZ

Motivation

Modifications

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

Check

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

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

Sourcery 总结

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

增强功能:

  • 通过将 ListDict 替换为 listdict 来实现类型注解的现代化
  • 更新类型提示以使用新的 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

Copy link
Contributor

sourcery-ai bot commented Apr 19, 2025

## 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 的更新类图

Loading
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 的更新类图

Loading
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 的更新类图

Loading
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 的更新类图

Loading
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 的更新类图

Loading
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 的更新类图

Loading
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 的更新类图

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

ConfigRoute 的更新类图

Loading
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 的更新类图

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

PlatformCompatibilityStage 的更新类图

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

PreprocessStage 的更新类图

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

RateLimitCheckStage 的更新类图

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

ResultDecorateStage 的更新类图

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

WakingCheckStage 的更新类图

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

WhitelistCheckStage 的更新类图

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

LarkEvent 的更新类图

Loading
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 摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

```
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

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

Updated class diagram for AssistantMessageSegment

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

Updated class diagram for ToolCallsResult

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

Updated class diagram for ProviderRequest

Loading
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

Loading
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

Loading
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

Loading
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

Loading
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

Loading
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

Loading
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

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

Updated class diagram for KnowledgeDBManager

Loading
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

Loading
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

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

Updated class diagram for TextMeasurer

Loading
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

Loading
classDiagram
  class CodeBlockElement {
    content: list[str]
  }

Updated class diagram for registered_stages

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

Updated class diagram for ChromaVectorStore

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

Updated class diagram for Stats

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

Updated class diagram for StarTools

Loading
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

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

Updated class diagram for ProcessStage

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

Updated class diagram for RespondStage

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

Updated class diagram for OpenAIEmbedding

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

Updated class diagram for LogBroker

Loading
classDiagram
  class LogBroker {
    subscribers: list[Queue]
  }

Updated class diagram for PlatformAdapterTypeFilter

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

Updated class diagram for ConfigRoute

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

Updated class diagram for SQLitePluginStorage

Loading
classDiagram
  class SQLitePluginStorage {
    __new__(cls)
  }

Updated class diagram for ContentSafetyStage

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

Updated class diagram for ContentSafetyStrategy

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

Updated class diagram for PlatformCompatibilityStage

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

Updated class diagram for PreprocessStage

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

Updated class diagram for RateLimitCheckStage

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

Updated class diagram for ResultDecorateStage

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

Updated class diagram for WakingCheckStage

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

Updated class diagram for WhitelistCheckStage

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

Updated class diagram for LarkEvent

Loading
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

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LIghtJUNction - 我已经查看了你的更改 - 这里有一些反馈:

总体评论

  • 考虑使用 TypeAlias 来表示复杂的类型提示,以提高可读性。
  • 请注意,如果代码在旧版本的 Python 中使用,将 List 更改为 list 以及将 Dict 更改为 dict 可能会产生兼容性影响。
以下是我在审查期间查看的内容
  • 🟢 一般问题:一切看起来都很好
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

Sourcery 对开源是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我变得更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @LIghtJUNction - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider using TypeAlias for complex type hints to improve readability.
  • Be aware that changing List to list and Dict to dict may have compatibility implications if the code is used in older Python versions.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Raven95676
Copy link
Member

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

例:

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

@LIghtJUNction
Copy link
Contributor Author

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

例:

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

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

@LIghtJUNction
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants