Summary¶
目的¶
Summary 模組負責在使用者請求時,根據某段期間的事件資料(Moodle, Google Tasks, Google Calendar),產生溫柔、具體、不責備的區間回顧文字 (summary_text)。
是一個 dspy module。
Inputs¶
| Input | Type | 說明 |
|---|---|---|
dialog_history | str | 過去的對話紀錄(可為空),會傳給 LLM 作為上下文。 |
user_input | str | 使用者當前輸入,觸發 summary 的需求。 |
previous_signature_output | List[PreviousSignature] | 前一模組的 signature 清單,每項包含 module、signature、content(字串),供 LLM 作為上下文使用。 |
pipeline | List[str] | 完整的 pipeline 清單(按執行順序),例如:[Router, EmotionSupport, Summary]。 |
current_pipeline_index | int | 目前正在執行的 pipeline 索引(從 0 開始);用以告知 LLM 自己在流程中的位置。 |
Outputs¶
- 回傳型態:
dspy.Prediction(含summary_text欄位)。
Workflow¶
- 解析輸入:從
user_input抽取時間範圍與來源關鍵字。 - 時間正規化:將模糊描述(例如「這週」「上個月」「最近三天」)轉為具體的起訖日期。
- 決定資料來源:
- 若使用者有指定來源 → 使用相似詞比對以決定要抓取的來源集合。
- 若未指定 → 預設同時從 Moodle、Google Tasks、Google Calendar 抓取。
- 抓取資料(可並行):對各來源呼叫抓取函式。
- 檢查資料:
- 若沒有任何 interval data → 直接回傳說明文字(不呼叫 LLM)。
- 若有資料 → 呼叫外部工具
interval_data_tool(或類似的 aggregator)並行抓取各來源後整合成interval_data_all(moodle、tasks、calendar)。將所有取得的 dict 以 toon 格式編碼為字串(例如產生interval_data_toon_str),toon 為基於 JSON、專為大語言模型優化的資料格式,然後將該字串傳給 LLM(dspy.Predict)。
- 呼叫 LLM:以
dspy.Predict(SummaryWriterSignature)傳入dialog_history、user_input、interval_data_json,產生summary_text。 - 回傳:將
dspy.Prediction.summary_text回傳給上層。
流程圖(Mermaid):
flowchart TD
Start([開始])
Parse["解析 `user_input`<br>(抽時間範圍、來源關鍵字)"]
Normalize["時間正規化<br>(模糊→具體起訖日期)"]
DecideSrc{"有指定資料來源嗎?"}
MapKeywords["以相似詞比對決定來源集合"]
DefaultSrc["預設來源:Moodle<br>Google Tasks<br>Google Calendar"]
Fetch["抓取資料(可並行)"]
Assemble["調用 `interval_data_tool` 整合 interval_data_all<br>(moodle、tasks、calendar)"]
EncodeCall["將所有 dict 編碼為 toon 字串並呼叫 LLM<br>(interval_data_toon_str -> dspy.Predict)"]
Return["回傳 `dspy.Prediction.summary_text`"]
End([結束])
Start --> Parse --> Normalize --> DecideSrc
DecideSrc -- 是 --> MapKeywords --> Fetch
DecideSrc -- 否 --> DefaultSrc --> Fetch
Fetch --> Assemble --> EncodeCall --> Return --> End