feat: 信源透传 (webSearchResults + xSearchResults)#468
Open
Huan-zhaojun wants to merge 1 commit intochenyme:mainfrom
Open
feat: 信源透传 (webSearchResults + xSearchResults)#468Huan-zhaojun wants to merge 1 commit intochenyme:mainfrom
Huan-zhaojun wants to merge 1 commit intochenyme:mainfrom
Conversation
… Sources
Grok SSE 流中的 webSearchResults 和 xSearchResults 透传给下游消费者。
采集层(StreamAdapter):
- webSearchResults: 直接使用原始 url + title
- xSearchResults: postId+username 拼接 URL,text 前 50 字构造 title,
空白归一化,共享 set 跨类型去重
- references_suffix() 统一转义 Markdown 特殊字符后输出
多轮剥离(_extract_message):
- 标记行 [grok2api-sources]: # (CommonMark link ref def,渲染器不显示)
- 正则覆盖 string content + block list content,CRLF 兼容
- 仅匹配含标记行的段落,用户自写 ## Sources 不受影响
配置:
- features.show_search_sources(默认 false),管理面板可开关
- 管理面板 + 6 语言 i18n (zh/en/de/es/fr/ja)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Grok 搜索时 SSE 流返回 44~400 条信源(web + X 帖子),但此前 grok2api 全部丢弃,
下游消费者(如 GrokSearch MCP)的
sources_count为 0。三层 URL 体系中,模型正文内联引用
[[N]](url)仅 5–15 条(严格子集),大量的信源没有暴露给调用方。本 PR 将完整信源透传到响应中,可作为 GrokSearch MCP 信源链路的基础设施。
Summary
webSearchResults(网页)和xSearchResults(X 帖子)透传到响应末尾的## Sources段落features.show_search_sources配置开关(默认关闭),管理面板可切换Changes
采集层 —
xai_chat.pyStreamAdapterwebSearchResults: 直接使用原始 url + title,多帧累积去重xSearchResults:postId+username拼接 URL,text前 50 字构造 title,空白归一化_web_search_urls_seenset 跨类型去重(web 中的 x.com URL 与 X 帖子自动去重)references_suffix()统一转义 Markdown 特殊字符(\[])多轮剥离 —
chat.py_extract_message[grok2api-sources]: #(CommonMark link reference definition,渲染器不显示)## Sources不受影响配置 & UI
config.defaults.toml新增show_search_sources = falseTest plan
show_search_sources,发送搜索类问题,验证响应末尾出现## Sources段落https://x.com/{username}/status/{postId})