Router¶
Goals¶
Router 為系統的路由器。 給予使用者最立即的短回覆,並分辨需求、判斷情緒強度以決定後續模組執行順序與內容。
是一個dspy module。
Inputs¶
| Input | Type | 說明 |
|---|---|---|
user_input | string | 使用者輸入文字,會被傳給 Router 處理(必填)。 |
dialog_history | string | 對話歷史(選填,預設空字串)。 |
Outputs¶
| 欄位 | 型別 | 說明 |
|---|---|---|
pipeline_description | string | 1~3 句話的流程說明,對使用者描述接下來會做的步驟(不得在此展開具體內容)。來源:signature.py。 |
pipeline | List[Literal] | 要執行的模組名稱陣列;允許元素包括 EmotionSupport、Summary、Scheduling(來源:signature.py)。 |
signature¶
router¶
Goal¶
簡短:判斷使用者需求並決定後續 pipeline(例如 EmotionSupport、Summary、Scheduling)。
Inputs¶
| Input | Type | 說明 |
|---|---|---|
dialog_history | string | 對話歷史(選填,預設空字串)。 |
user_input | string | 使用者這一輪的完整輸入文字(必填)。 |
Outputs¶
回傳型態:dspy.Prediction,包含以下欄位:
| 欄位 | 型別 | 說明 |
|---|---|---|
pipeline_description | string | 由 dspy.Prediction.pipeline_description 回傳;1~3 句話的流程說明,對使用者描述接下來會做的步驟(不得在此展開具體內容)。 |
pipeline | List[Literal] | 由 dspy.Prediction.pipeline 回傳;要執行的模組名稱陣列,允許元素包括 EmotionSupport, Summary, Scheduling。 |
Workflow & Upstream Mapping¶
router 會將欄位直接轉送給 signature ,進行以下判斷流程。
flowchart TD
U["使用者輸入"] --> C1{"是否是第一個使用者輸入?"}
C1 -->|"是"| C2{"是否要調用核心功能(Summary 或 Scheduling)?"}
C1 -->|"否"| UNKNOWN["還沒想好怎麼處理"]
C2 -->|"只需要情緒"| EM_ONLY["Emotion:單獨回應"]
C2 -->|"需要核心功能"| E["情緒判斷"]
C2 -->|"無關"| OUT_UNSUPPORTED["Router:輸出空 pipeline;<br>description 提示:目前不支援此請求;<br>支援項目:Emotion、Summary、Scheduling"]
OUT_UNSUPPORTED --> R
EM_ONLY --> R["根據剛剛決定的流程,直接輸出結果"]
E -->|"低落"| P0["Router:接住1到2句、但情緒交給Emotion"]
P0 --> EM1["Emotion:前置"]
EM1 --> I{"意圖判斷"}
E -->|"普通或高漲"| P1["Router:接住1句"]
P1 --> I
I -->|"Summary"| T["Python:時間段粗判"]
I -->|"Scheduling"| S["Pass"]
T --> D["interval_data_tool:拉資料"]
D --> SUM["Summary:生成總結"]
SUM --> EM2{"是否收尾Emotion"}
S --> EM2
EM2 -->|"低落或需要暖收"| EM3["Emotion:後置收尾"]
EM2 -->|"不需要"| R
EM3 --> R 使用範例¶
router = RouterModule()
result = router(
user_input="我覺得有點沮喪,回顧一下這週好嗎?",
dialog_history=""
)
print(result.pipeline_description)
print(result.pipeline)
備註¶
- 本檔為整合版草稿,已把
README.md與signature.py的重點摘錄並與prompt/router.md做分工建議。 - 若你確認要把整合內容覆寫原
router.md,我可以替你做替換;或是把本檔改名為router.md的最終版本。