Skip to content
Back to search

StarWhisper

Astronomy LLMs, StarWhisper Telescope, Virtual Sitian, and astronomy research skills

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/yu-yang-li--starwhisper/badge.svg)](/listings/yu-yang-li--starwhisper)

HTML

<a href="/listings/yu-yang-li--starwhisper"><img src="/api/listings/yu-yang-li--starwhisper/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 49 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

This file has changed since it was scanned, so this is not exactly the text that was scanned, and no line is marked. The findings are listed with the safety scan above.

  1. # 星语 / StarWhisper
  2. 中文 · [English](README_EN.md) · [研究文档](docs/research.md) · [技能包](skills/README.md) · [仓库结构](docs/architecture.md)
  3. ![山地天文台与夜空的概念插画](docs/assets/starwhisper-cover.png)
  4. StarWhisper(星语)收录了天文语言模型、光变曲线与光谱分析、望远镜自主观测等工作的代码、数据和模型。这里也有一些可在 Codex / Cursor 中使用的科研技能。相关工作由国家天文台、之江实验室等单位支持。
  5. [![License](https://img.shields.io/badge/License-Apache--2.0-172b4d)](LICENSE)
  6. [![GitHub Repo stars](https://img.shields.io/github/stars/Yu-Yang-Li/StarWhisper?style=social)](https://github.com/Yu-Yang-Li/StarWhisper/stargazers)
  7. ## 项目
  8. | 研究方向 | 项目入口 |
  9. | --- | --- |
  10. | 天文语言模型 | [训练数据](projects/language-models/README.md) · [StarWhisper 3 权重](https://www.modelscope.cn/models/AstroYuYang/StarWhisper3) |
  11. | 光变与暂现源 | [Kepler / K2 分类](projects/light-curves/README.md) · [稀疏光变](projects/sparse-light-curves/README.md) · [SN Clock](projects/snclock/README.md) · [Pulsar](https://github.com/ACMISLab/StarWhisper-Pulsar) |
  12. | 恒星光谱 | [低信噪比光谱分析](projects/stellar-spectra/README.md) |
  13. | 观测与调度 | [NGSS](projects/ngss/README.md) · [全天相机](projects/allsky-camera/README.md) · [Explore](projects/explore/README.md) · [SitianClaw](https://github.com/Yu-Yang-Li/SitianClaw) |
  14. 各项目的内容和运行条件见[项目目录](projects/README.md)。文献检索、研究设计、统计、写作与绘图工具见[科研技能](skills/README.md)。
  15. 论文图表、实验结果和复现说明见[研究文档](docs/research.md)。
  16. ## 使用
  17. 先在[项目目录](projects/README.md)查看各项工作已经提供的材料和运行条件。SN Clock、Explore、稀疏光变指标和 NGSS 配置有现成的本地读取命令;重新训练模型需要对应的数据与环境,完整观测流程还需准备台站系统。[科研技能](skills/README.md)也可按任务安装到 Codex / Cursor。
  18. 例如,下面的命令读取仓库附带的 SN Clock 历史预测表:
  19. ```bash
  20. git clone https://github.com/Yu-Yang-Li/StarWhisper.git
  21. cd StarWhisper
  22. python skills/starwhisper-snclock/scripts/screen_snclock.py rank --top 10
  23. ```
  24. 需要 Python 3.10 或更新版本,不需要安装其他依赖或先安装技能。表里是 22 个源的一次历史预测,来源和局限见[数据说明](projects/snclock/README.md)。筛选当前候选体时,应换用最新数据。其他离线示例见[项目目录](projects/README.md#先试一条命令)。
  25. ## 论文与引用
  26. - [StarWhisper Telescope: an AI framework for automating end-to-end astronomical observations](https://doi.org/10.1038/s44172-025-00520-4) — *Communications Engineering*, 2025。
  27. - [StarWhisper LC](https://spj.science.org/doi/10.34133/icomputing.0110) — *Intelligent Computing*, 2025。
  28. - [StarWhisper-Pulsar](https://openreview.net/pdf?id=8SKgWpZiDL) — NeurIPS 2024 FM4Science workshop。
  29. 引用格式见 [CITATION.cff](CITATION.cff) 和 [BibTeX](docs/research.md#引用)。使用某个项目的代码或数据时,也请引用相应论文。
  30. 问题和复现记录可以提交到 [Issue](https://github.com/Yu-Yang-Li/StarWhisper/issues)。也欢迎通过 Pull Request 改进代码或文档,提交前请阅读[贡献说明](CONTRIBUTING.md)。
  31. 代码采用 [Apache-2.0](LICENSE)。改编的科研技能保留原有 MIT 许可和来源标注,见 [NOTICE](skills/NOTICE.md);模型权重按各自许可证使用。
skills/sci-employee-deep-research/scripts/stream_deep_research.py · Bundled script · 368 lines · 1 finding marked
  1. #!/usr/bin/env python3
  2. """Forward Deep Research SSE events as progress JSONL.
  3. Each stdout line is a standalone JSON object. A web backend can forward these
  4. lines as Server-Sent Events without waiting for the final answer.
  5. """
  6. from __future__ import annotations
  7. import argparse
  8. import json
  9. import sys
  10. import time
  11. import urllib.error
  12. import urllib.parse
  13. import urllib.request
  14. from datetime import datetime
  15. from pathlib import Path
  16. from typing import Any, Iterable, Iterator
  17. DEFAULT_ENDPOINT = "http://123.56.218.60:18000/api/research/ask"
    • Warning: Talks to a raw IP address or throwaway host, where malware is often staged
    • Line 22 on GitHub
  18. AUTH_URL = "https://giiisp.com/#/mcp/authenticate"
  19. INTERFACE_UNAVAILABLE_ACTION = (
  20. "Deep Research 接口不可用或未配置;请检查服务地址/网络/后端状态。"
  21. f" 如果失败来自 Giiisp 认证或 key 过期,请到 {AUTH_URL} 申请或刷新认证后重试。"
  22. )
  23. STARTED_AT = time.monotonic()
  24. def emit(event: dict[str, Any]) -> None:
  25. event.setdefault("ts", datetime.now().astimezone().isoformat(timespec="milliseconds"))
  26. event.setdefault("elapsed_ms", int((time.monotonic() - STARTED_AT) * 1000))
  27. print(json.dumps(event, ensure_ascii=False, separators=(",", ":")), flush=True)
  28. def load_json(data: str) -> Any:
  29. try:
  30. return json.loads(data)
  31. except json.JSONDecodeError:
  32. return None
  33. def iter_sse_lines(lines: Iterable[str]) -> Iterator[tuple[str | None, str]]:
  34. event = None
  35. data_parts: list[str] = []
  36. for raw in lines:
  37. line = raw.rstrip("\r\n")
  38. if not line:
  39. if event or data_parts:
  40. yield event, "\n".join(data_parts)
  41. event = None
  42. data_parts = []
  43. continue
  44. if line.startswith(":"):
  45. continue
  46. if line.startswith("event:"):
  47. event = line.split(":", 1)[1].strip()
  48. elif line.startswith("data:"):
  49. data_parts.append(line.split(":", 1)[1].strip())
  50. if event or data_parts:
  51. yield event, "\n".join(data_parts)
  52. def first_references(references: list[dict[str, Any]], limit: int = 10) -> list[dict[str, Any]]:
  53. return [
  54. {
  55. "title": ref.get("title"),
  56. "url": ref.get("url"),
  57. "sourceApi": ref.get("sourceApi"),
  58. "sourceType": ref.get("sourceType"),
  59. }
  60. for ref in references[:limit]
  61. ]
  62. def answer_status(references: list[dict[str, Any]], answer_text: str, done: dict[str, Any] | None, total_results: int | None) -> str:
  63. if done and done.get("ok") and references:
  64. return "complete"
  65. if done and done.get("answer") and not references:
  66. return "clarification_or_no_evidence"
  67. if references and answer_text:
  68. return "incomplete"
  69. if references:
  70. return "references_only"
  71. if total_results == 0:
  72. return "no_evidence"
  73. if answer_text:
  74. return "clarification_or_no_evidence"
  75. return "unknown"
  76. def user_action_for_status(status: str, failures: list[Any]) -> str:
  77. if status == "interface_unavailable":
  78. return INTERFACE_UNAVAILABLE_ACTION
  79. if status == "incomplete":
  80. return "先展示已返回 references 和 answer 片段;继续等待、收窄问题或改走候选论文过滤"
  81. if status == "references_only":
  82. return "先展示 references;继续等待 answer 或把候选论文交给报告整理"
  83. if status in {"no_evidence", "clarification_or_no_evidence"}:
  84. return "不要包装成研究报告;收窄问题、换关键词或先走论文检索"
  85. if failures:
  86. return "保留失败 endpoint 和关键词;必要时提示用户完成 Giiisp 认证或改用开放源回退"
  87. return ""
  88. def infer_health_url(endpoint_url: str) -> str:
  89. parsed = urllib.parse.urlparse(endpoint_url)
  90. if not parsed.scheme or not parsed.netloc:
  91. return ""
  92. return urllib.parse.urlunparse((parsed.scheme, parsed.netloc, "/health", "", "", ""))
  93. def interface_unavailable_event(reason: str, **details: Any) -> dict[str, Any]:
  94. return {
  95. "event": "interface_unavailable",
  96. "reason": reason,
  97. "user_action": INTERFACE_UNAVAILABLE_ACTION,
  98. **details,
  99. }
  100. def check_health(health_url: str, timeout: float) -> tuple[bool, dict[str, Any]]:
  101. if not health_url:
  102. return False, interface_unavailable_event("missing_health_url")
  103. request = urllib.request.Request(health_url, method="GET")
  104. try:
  105. with urllib.request.urlopen(request, timeout=timeout) as response:
  106. status = getattr(response, "status", response.getcode())
  107. body = response.read(500).decode("utf-8", errors="replace")
  108. if 200 <= status < 300:
  109. return True, {"event": "interface_status", "ok": True, "health_url": health_url, "http_status": status}
  110. return False, interface_unavailable_event(
  111. "health_check_non_2xx",
  112. health_url=health_url,
  113. http_status=status,
  114. raw_excerpt=body,
  115. )
  116. except urllib.error.HTTPError as exc:
  117. body = exc.read().decode("utf-8", errors="replace")[:500]
  118. return False, interface_unavailable_event(
  119. "health_check_http_error",
  120. health_url=health_url,
  121. http_status=exc.code,
  122. raw_excerpt=body,
  123. )
  124. except OSError as exc:
  125. return False, interface_unavailable_event(
  126. "health_check_failed",
  127. health_url=health_url,
  128. error=type(exc).__name__,
  129. message=str(exc),
  130. )
  131. def forward_events(events: Iterable[tuple[str | None, str]], source: str, max_events: int | None = None) -> int:
  132. started_at = time.time()
  133. phases: list[dict[str, Any]] = []
  134. keywords: list[str] = []
  135. references: list[dict[str, Any]] = []
  136. failures: list[Any] = []
  137. answer_chunks: list[str] = []
  138. private_search_summary: dict[str, Any] | None = None
  139. done: dict[str, Any] | None = None
  140. usage: Any = None
  141. raw_event_count = 0
  142. interrupted: dict[str, Any] | None = None
  143. interface_error: dict[str, Any] | None = None
  144. emit({"event": "stream_started", "source": source})
  145. for raw_event, data in events:
  146. raw_event_count += 1
  147. payload = load_json(data)
  148. event = raw_event or "message"
  149. if event == "phase" and isinstance(payload, dict):
  150. phases.append(payload)
  151. emit({"event": "phase", "phase": payload.get("phase") or payload.get("name"), "payload": payload})
  152. elif event == "keywords" and isinstance(payload, dict):
  153. keywords = payload.get("keywords") or []
  154. emit({"event": "keywords_ready", "keywords": keywords, "payload": payload})
  155. elif event == "private_search_hit" and isinstance(payload, dict):
  156. if payload.get("ok") is False or payload.get("error"):
  157. failures.append(payload)
  158. emit({"event": "private_search_hit", "payload": payload})
  159. elif event == "private_search_summary" and isinstance(payload, dict):
  160. private_search_summary = payload
  161. failures.extend(payload.get("failures") or [])
  162. emit(
  163. {
  164. "event": "private_search_summary",
  165. "totalResults": payload.get("totalResults"),
  166. "failure_count": len(payload.get("failures") or []),
  167. "payload": payload,
  168. }
  169. )
  170. elif event == "references" and isinstance(payload, dict):
  171. references = payload.get("references") or []
  172. emit(
  173. {
  174. "event": "references_ready",
  175. "references_count": len(references),
  176. "first_references": first_references(references),
  177. }
  178. )
  179. elif event == "delta" and isinstance(payload, dict):
  180. content = payload.get("content") or ""
  181. answer_chunks.append(content)
  182. emit({"event": "answer_delta", "content": content, "answer_chars": sum(len(chunk) for chunk in answer_chunks)})
  183. elif event == "done" and isinstance(payload, dict):
  184. done = payload
  185. emit({"event": "done", "ok": payload.get("ok"), "payload": payload})
  186. elif event == "usage" and isinstance(payload, dict):
  187. usage = payload.get("usage") or payload
  188. emit({"event": "usage", "usage": usage})
  189. elif event in {"stream_error", "interface_unavailable"} and isinstance(payload, dict):
  190. interface_error = payload
  191. emit({"event": "interface_unavailable", **payload})
  192. else:
  193. emit({"event": "raw_event", "raw_event": event, "payload": payload if payload is not None else data[:500]})
  194. if max_events is not None and raw_event_count >= max_events:
  195. interrupted = {
  196. "reason": "max_events",
  197. "max_events": max_events,
  198. "message": "Stopped after the requested number of SSE events; preserve partial evidence for the UI.",
  199. }
  200. emit({"event": "stream_interrupted", **interrupted})
  201. break
  202. answer_text = "".join(answer_chunks)
  203. total_results = private_search_summary.get("totalResults") if private_search_summary else None
  204. status = (
  205. "interface_unavailable"
  206. if interface_error and not references and not answer_text and done is None
  207. else answer_status(references, answer_text, done, total_results)
  208. )
  209. user_action = user_action_for_status(status, failures)
  210. if interrupted and not user_action:
  211. user_action = "已输出阶段进度;继续等待更多事件,或收窄问题后重试"
  212. emit(
  213. {
  214. "event": "stream_final",
  215. "source": source,
  216. "raw_event_count": raw_event_count,
  217. "phase_count": len(phases),
  218. "keywords": keywords,
  219. "private_search": {
  220. "totalResults": total_results,
  221. "failure_count": len(failures),
  222. "failures": failures[:10],
  223. },
  224. "references_count": len(references),
  225. "answer_status": status,
  226. "user_action": user_action,
  227. "answer_chars": len(answer_text or (done or {}).get("answer", "")),
  228. "has_done": done is not None,
  229. "has_usage": usage is not None,
  230. "interrupted": interrupted,
  231. "interface_error": interface_error,
  232. "elapsed_ms": int((time.time() - started_at) * 1000),
  233. }
  234. )
  235. return 2 if status == "interface_unavailable" else 0
  236. def lines_from_log(path: Path) -> Iterator[str]:
  237. with path.open("r", encoding="utf-8", errors="replace") as handle:
  238. yield from handle
  239. def lines_from_http(endpoint: str, body: dict[str, Any], timeout: float) -> Iterator[str]:
  240. request = urllib.request.Request(
  241. endpoint,
  242. data=json.dumps(body, ensure_ascii=False).encode("utf-8"),
  243. headers={"Content-Type": "application/json", "Accept": "text/event-stream"},
  244. method="POST",
  245. )
  246. try:
  247. with urllib.request.urlopen(request, timeout=timeout) as response:
  248. for raw in response:
  249. yield raw.decode("utf-8", errors="replace")
  250. except urllib.error.HTTPError as exc:
  251. body_excerpt = exc.read().decode("utf-8", errors="replace")[:500]
  252. payload = interface_unavailable_event(
  253. "stream_http_error",
  254. http_status=exc.code,
  255. content_type=exc.headers.get("Content-Type", ""),
  256. raw_excerpt=body_excerpt,
  257. )
  258. yield "event: interface_unavailable\n"
  259. yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
  260. except OSError as exc:
  261. payload = interface_unavailable_event("stream_request_failed", error=type(exc).__name__, message=str(exc))
  262. yield "event: interface_unavailable\n"
  263. yield f"data: {json.dumps(payload, ensure_ascii=False)}\n\n"
  264. def request_body(args: argparse.Namespace) -> dict[str, Any]:
  265. endpoints = [item.strip() for item in args.endpoint_names.split(",") if item.strip()]
  266. return {
  267. "prompt": args.prompt,
  268. "model": args.model,
  269. "keyword_model": args.keyword_model,
  270. "page_num": args.page_num,
  271. "page_size": args.page_size,
  272. "endpoint_names": endpoints,
  273. "include_raw": args.include_raw,
  274. }
  275. def main() -> int:
  276. parser = argparse.ArgumentParser(description="Forward Deep Research SSE as JSONL progress events.")
  277. parser.add_argument("--from-log", type=Path, help="Replay an existing SSE log instead of calling the live endpoint.")
  278. parser.add_argument("--endpoint-url", default=DEFAULT_ENDPOINT)
  279. parser.add_argument("--prompt")
  280. parser.add_argument("--model", default="qwen-deep-research")
  281. parser.add_argument("--keyword-model", default="qwen-plus")
  282. parser.add_argument("--page-num", type=int, default=1)
  283. parser.add_argument("--page-size", type=int, default=5)
  284. parser.add_argument(
  285. "--endpoint-names",
  286. default="searchArticlesByQuery1,searchArxivByTitle,searchArxivByAbstract,searchArxivByArxivNo1,searchArxiv",
  287. )
  288. parser.add_argument("--include-raw", action="store_true")
  289. parser.add_argument("--timeout", type=float, default=300)
  290. parser.add_argument("--health-url", help="Override the Deep Research health-check URL.")
  291. parser.add_argument("--health-timeout", type=float, default=10)
  292. parser.add_argument("--skip-health-check", action="store_true")
  293. parser.add_argument("--max-events", type=int, help="Stop after N SSE events and emit a partial final summary.")
  294. args = parser.parse_args()
  295. if args.from_log:
  296. return forward_events(iter_sse_lines(lines_from_log(args.from_log)), str(args.from_log), args.max_events)
  297. if not args.prompt:
  298. raise SystemExit("--prompt is required unless --from-log is used")
  299. if not args.endpoint_url:
  300. missing_event = interface_unavailable_event("missing_endpoint_url")
  301. return forward_events(
  302. iter_sse_lines(
  303. [
  304. "event: interface_unavailable\n",
  305. f"data: {json.dumps(missing_event, ensure_ascii=False)}\n\n",
  306. ]
  307. ),
  308. "<missing endpoint>",
  309. args.max_events,
  310. )
  311. if not args.skip_health_check:
  312. ok, health_event = check_health(args.health_url or infer_health_url(args.endpoint_url), args.health_timeout)
  313. emit(health_event)
  314. if not ok:
  315. return forward_events(
  316. iter_sse_lines(
  317. [
  318. "event: interface_unavailable\n",
  319. f"data: {json.dumps(health_event, ensure_ascii=False)}\n\n",
  320. ]
  321. ),
  322. args.endpoint_url,
  323. args.max_events,
  324. )
  325. return forward_events(iter_sse_lines(lines_from_http(args.endpoint_url, request_body(args), args.timeout)), args.endpoint_url, args.max_events)
  326. if __name__ == "__main__":
  327. raise SystemExit(main())

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.