[Feature] 让模型参与分段:新增 segmented_reply.model_controlled,用标记/换行决定气泡边界

Đang mở
#11,132 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
12/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

Start with ResultDecorateStage in astrbot/core/result_decorate/stage.py (the early return on streaming results and the words_count_threshold skip near line 220), then RespondStage in astrbot/core/respond/stage.py where _calc_comp_interval and the per-segment asyncio.sleep(i) live. The config schema is in astrbot/core/config/default.py. This touches prompt injection and streaming, so it needs maintainer design agreement first. Done would mean the model-controlled markers and the streaming fallback are honored, with the old regex/words behavior unchanged when the option is off.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

现象

分段边界由程序决定,模型无法参与:

  1. 只有程序切分:split_mode 只有 regex / words(astrbot/core/config/default.py:111-129),切分发生在 result_decorate/stage.py:208-267,输入是最终纯文本。模型没有「这句单独发」「这两句连在一起」的表达方式;换行、空行、语义停顿都不影响切分,结果类型中也没有「分段意图」字段。
  2. 流式下配置也不生效:streaming_response=true 时 ResultDecorateStage 对流式结果直接 return(stage.py:134-135、:137/191-193),实际按适配器硬编码的标点 。?!~… 和固定 sleep(1.5) 切分(platform/astr_message_event.py:342-353、sources/aiocqhttp/aiocqhttp_message_event.py:244-261),regex/interval 无人读取。
  3. 长文本不分段:超过 words_count_threshold(默认 150)的 Plain 整段跳过(stage.py:220)。
  4. 首段也要等待:respond/stage.py:355-356 每段发送前 asyncio.sleep(i),首段同样等待一个 interval(#9931 曾提出跳过,但未合并)。

期望行为

  1. 模型可控(可选,默认关闭):新增 segmented_reply.model_controlled,向 system prompt 注入约定「需要换气泡时用空行或 <|seg|> 分隔」;切分时优先按标记,模型未给标记则回退现有 regex/words,老用户行为不变。
  2. 流式复用配置(可选;若维护者认为 #8313 已覆盖,可只做第 1 点):send_streaming 的 fallback 接收 split_mode / regex / split_words / interval,不再硬编码标点和 1.5s。
  3. 长文本语义:words_count_threshold 改为「超过则按更粗粒度再切」,而不是跳过切分。
  4. 首段延迟可配:增加「首段前是否 sleep」的开关(可复用 #9931 的思路)。

与已有 issue 的关系

  • #8313(open)只要求流式 fallback 的分割字符可自定义;本 issue 的核心是模型参与分段,第 2 点只是附带。
  • #10176(open PR)方向相反,要求工具调用后的最终答案不要乱切。
  • #10722(open)是发送侧管控(刷屏、在途分段不可打断),与「边界由谁决定」不同层。
  • #10916(open PR)是最大分段数;#9931(closed 未合并)是跳过首段延迟。
  • 本 issue 不是以上任一条的重复。

复现(模型无法控制边界)

  1. 开启 segmented_reply(split_mode=regex,默认正则)。
  2. 要求模型「刚才那句单独发」「这三句连成一条发」,实际仍按 。?!~… 切,模型意图不生效。
  3. 让模型用空行或换行表达换气泡,结果被忽略或并入同一段。
  4. 打开 streaming_response=true 再试:连 regex/interval 也不生效,变成硬编码标点加固定 1.5s。

版本 / 环境

  • AstrBot v4.29.4(6133541,2026-10-31);master 630d5cee(2026-11-14)核心分段逻辑未变
  • Linux + aiocqhttp/NapCat,Python 3.12
  • streaming_response=true,segmented_reply.enable=true

建议实现

  • ResultDecorateStage:不要对流式结果一刀切 return;把分段参数传给 send_streaming,由 fallback 使用配置切句(同时消化 #8313)。
  • RespondStage:流式分支复用 _calc_comp_interval 的节奏控制,而不是在适配器内部写死 1.5s。
  • system prompt:按 model_controlled 开关注入分隔协议;切分函数优先按标记,其次 regex;兼容 only_llm_result。
Ngôn ngữ chính
Python
Star
46.9k
Fork
3.6k
Merge trung bình
1 ngày 5 giờ
Pull request đã merge (30 ngày)
140

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của AstrBotDevs/AstrBot

Tất cả issue của AstrBotDevs/AstrBot

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.