feat(backend): 完成模塊一投資人格分析 (Upload API + MBTI Profiler)#1
Open
meatmeateater wants to merge 1 commit into
Open
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
📘 模塊一:投資人格分析 (Investment Profiler) 整合指南
1. 🚀 前端調用與整合流程 (Frontend Integration)
整個業務流程由兩個部分組成:文件上傳 (API) 與 Agent 對話 (Tool Calling)。
步驟 A:交易紀錄上傳 (Upload API)
前端需提供一個上傳按鈕,將用戶的
.csv或.xlsx文件傳送到後端,並獲取後端回傳的絕對路徑。POST /api/uploadmultipart/form-datafile: (Binary) 用戶選擇的檔案。前端請求範例 (JS/TS)
成功回應 (Response)
{ "status": "success", "file_path": "D:\\projects\\spark-ai-demo\\apps\\server\\uploads\\trade_history.csv", "filename": "trade_history.csv", "message": "上傳成功!..." }步驟 B:Agent 交互流程 (Agent Interaction)
本模塊透過 Agent 自動調用工具來完成,前端只需負責渲染 UI 與傳遞訊息。
1. 觸發問卷 (Get Questions)
當用戶說:「幫我分析投資人格」時,Agent 會調用工具
generate_investment_quiz。[ { "id": "EI_01", "dimension": "EI", "question": "在交易群組中,你的活躍程度是?", "options": { "A": "非常活躍,喜歡分享觀點", "B": "潛水居多,默默觀察" } }, ... (共8題) ]2. 提交分析 (Submit Analysis)
當用戶填完問卷並上傳文件後,前端需將資訊整理成 Prompt 發送給 Agent。
前端發送的 Prompt 範本:
回答數據格式 (
user_answers):{ "EI_01": "A", "SN_02": "B", "TF_01": "A" // 格式支援 "A" 或 "A: 選項文字" }analyze_user_profile工具,進行運算並輸出最終 MBTI 分析報告。2. 📝 代碼變更履歷 (Changelog)
為了實現此功能,我們在後端 (
apps/server) 進行了以下修改與新增:🟢 新增/修改的核心檔案
apps/server/main.py/api/upload接口。負責將前端上傳的交易文件儲存至uploads/目錄,並回傳絕對路徑供 Python Tool 讀取。.../skills/investment_profiler/tools.py1.
generate_investment_quiz: 隨機抽取 8 題問卷。2.
analyze_user_profile: 接收路徑與回答,執行核心分析。.../skills/investment_profiler/core/performance.pyQuantStats與Pandas,計算夏普率、回撤等數據。支援 Excel 與多種 CSV 格式 (含雜訊 Header)。.../skills/investment_profiler/core/questionnaire.py.../skills/investment_profiler/data/question_bank.py⚙️ 設定配置變更
.../skills/investment_profiler/__init__.pytools列表,使系統能識別新工具。.../skills/registry.pyinvestment_profiler註冊到全局SKILL_REGISTRY。3. 💡 補充說明 (Technical Notes)
1. 題目隨機性機制
generate_investment_quiz,後端會從每個維度 (EI / SN / TF / JP) 隨機抽取 2 題。2. 交易文件兼容性
目前的
PerformanceEngine已針對常見交易所格式優化:AssetChangeDetails...) 能自動識別UID:等雜訊並跳過前幾行。