From 39de37e7eb2ab42ab75283d4d9e67ac538c1df27 Mon Sep 17 00:00:00 2001 From: mindesbunister Date: Thu, 17 Jul 2025 16:44:32 +0200 Subject: [PATCH] feat: make Trade Follow-up Assistant responses concise and actionable - Updated system prompt to match main analysis style: precision of proprietary desk trader - Reduced max tokens from 800 to 200 for main responses - Reduced screenshot analysis tokens from 1000 to 150 - Made welcome messages more compact and focused - Shortened quick action buttons (Exit now?, Move stop loss, etc.) - Condensed status report to essential information only - Eliminated verbose explanations, focus on exact price levels and immediate actions - Changed temperature from 0.3 to 0.1 for more consistent responses Addresses user feedback that responses were 'way too vague and too much talk'. --- app/api/trade-followup/route.js | 47 +++++++++++++++---------------- components/TradeFollowUpPanel.tsx | 21 +++++++------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/app/api/trade-followup/route.js b/app/api/trade-followup/route.js index 7d3a6e9..78be099 100644 --- a/app/api/trade-followup/route.js +++ b/app/api/trade-followup/route.js @@ -89,18 +89,17 @@ CURRENT POSITION DETAILS: messages: [ { role: "system", - content: `You are an expert trading analyst providing real-time trade management advice. + content: `You are a professional trading analyst. Analyze this chart for an active ${position.side} position at $${position.entryPrice}. -CURRENT POSITION: ${positionContext} +Current P&L: ${position.pnl > 0 ? '+' : ''}$${position.pnl?.toFixed(2)} -Analyze the provided chart screenshots and provide specific guidance on: -1. Current market structure and price action -2. Whether to hold, exit, or adjust the position -3. Stop loss and take profit recommendations -4. Risk assessment based on current conditions -5. Key levels to watch +PROVIDE CONCISE ANALYSIS (Max 100 words): +• Current price action vs entry +• Key levels to watch +• Risk assessment +• Immediate action needed -Be specific with price levels and actionable advice. Focus on PRACTICAL trade management.` +Be direct. Give exact price levels only.` }, { role: "user", @@ -113,7 +112,7 @@ Be specific with price levels and actionable advice. Focus on PRACTICAL trade ma ] } ], - max_tokens: 1000, + max_tokens: 150, temperature: 0.1 }) @@ -123,25 +122,23 @@ Be specific with price levels and actionable advice. Focus on PRACTICAL trade ma } // Generate conversational response - const systemPrompt = `You are an expert trading coach helping a trader manage their active position. You have access to: + const systemPrompt = `You are a professional trading coach with the precision of a top proprietary desk trader. No vagueness, no fluff. +CURRENT POSITION: ${positionContext} -${chatContext} -${screenshotAnalysis ? `\nLATEST CHART ANALYSIS:\n${screenshotAnalysis}` : ''} +${screenshotAnalysis ? `LATEST CHART ANALYSIS:\n${screenshotAnalysis}\n` : ''} -GUIDELINES: -- Be conversational and supportive -- Give specific, actionable advice -- Use exact price levels when possible -- Consider risk management principles -- Be honest about market uncertainty -- Use emojis appropriately -- Format important information clearly +RESPONSE STYLE: +- Be direct and actionable +- Give EXACT price levels only +- Use bullet points for clarity +- Maximum 150 words total +- Focus on immediate action needed -The trader is asking: "${message}" +TRADER QUESTION: "${message}" -Provide helpful, specific guidance for their current position.` +Provide concise, specific guidance.` const response = await openai.chat.completions.create({ model: "gpt-4o-mini", @@ -155,8 +152,8 @@ Provide helpful, specific guidance for their current position.` content: message } ], - max_tokens: 800, - temperature: 0.3 + max_tokens: 200, + temperature: 0.1 }) const assistantResponse = response.choices[0]?.message?.content diff --git a/components/TradeFollowUpPanel.tsx b/components/TradeFollowUpPanel.tsx index d393f23..e57e388 100644 --- a/components/TradeFollowUpPanel.tsx +++ b/components/TradeFollowUpPanel.tsx @@ -96,7 +96,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) setChatMessages([{ id: Date.now().toString(), type: 'system', - content: `šŸŽÆ **Trade Follow-up Assistant**\n\n**System Status (${systemStatus?.timestamp || 'Loading...'})**\n${statusEmoji}\n\nI'm here to help you manage your active ${data.positions[0].symbol} ${data.positions[0].side} position.\n\n**Current Position:**\n• Entry: $${data.positions[0].entryPrice}\n• Size: ${data.positions[0].amount}\n• Current P&L: ${data.positions[0].unrealizedPnl > 0 ? '+' : ''}$${data.positions[0].unrealizedPnl.toFixed(2)}\n\n**Available Commands:**\n• "status" - System and trading status\n• "analysis" - Fresh chart analysis\n• "risk" - Risk assessment\n• "exit" - Exit strategy\n\nAsk me anything about your trade!`, + content: `šŸŽÆ **Trade Follow-up Assistant**\n\n**System:** ${statusEmoji}\n\n**Active Position:**\n• ${data.positions[0].symbol} ${data.positions[0].side}\n• Entry: $${data.positions[0].entryPrice} | Size: ${data.positions[0].amount}\n• P&L: ${data.positions[0].unrealizedPnl > 0 ? '+' : ''}$${data.positions[0].unrealizedPnl.toFixed(2)}\n\nAsk: "exit?", "analysis", "risk", or type your question.`, timestamp: new Date().toISOString() }]) } else { @@ -107,7 +107,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) setChatMessages([{ id: Date.now().toString(), type: 'system', - content: `āš ļø **No Active Positions Found**\n\n**System Status (${systemStatus?.timestamp || 'Loading...'})**\n${statusEmoji}\n\nI don't see any active positions to analyze. Please:\n1. Enter a trade first\n2. Mark it as traded using the blue button\n3. Come back for follow-up analysis\n\nOr type "status" for detailed system information.`, + content: `āš ļø **No Active Positions**\n\n**System:** ${statusEmoji}\n\nExecute a trade first, then mark it as traded for follow-up analysis.\n\nType "status" for system diagnostics.`, timestamp: new Date().toISOString() }]) } @@ -116,7 +116,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) setChatMessages([{ id: Date.now().toString(), type: 'system', - content: `āŒ **Error Loading Positions**\n\n**System Status:** ${systemStatus ? `API ${systemStatus.api ? 'āœ“' : 'āœ—'} Wallet ${systemStatus.wallet ? 'āœ“' : 'āœ—'} Trading ${systemStatus.trading ? 'āœ“' : 'āœ—'}` : 'Unknown'}\n\nCouldn't load your active positions. Please check:\n• Docker container is running (port 9001)\n• API endpoints are responding\n• Database connection is working\n\nType "status" for detailed diagnostics.`, + content: `āŒ **Error Loading Positions**\n\n**System:** ${systemStatus ? `API ${systemStatus.api ? 'āœ“' : 'āœ—'} Wallet ${systemStatus.wallet ? 'āœ“' : 'āœ—'} Trading ${systemStatus.trading ? 'āœ“' : 'āœ—'}` : 'Unknown'}\n\nConnection issues detected. Type "status" for diagnostics.`, timestamp: new Date().toISOString() }]) } @@ -150,7 +150,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) const statusMessage: ChatMessage = { id: (Date.now() + 1).toString(), type: 'assistant', - content: `šŸ“Š **System Status Report** (${new Date().toLocaleTimeString()})\n\n**🐳 Docker Container:**\n• Status: ${systemStatus?.api ? '🟢 Running' : 'šŸ”“ Issues detected'}\n• Port: 9001 → 3000\n• Health: ${systemStatus?.api ? 'Healthy' : 'Unhealthy'}\n\n**🌐 API Services:**\n• Main API: ${systemStatus?.api ? '🟢 Online' : 'šŸ”“ Offline'}\n• Wallet API: ${systemStatus?.wallet ? '🟢 Connected' : 'šŸ”“ Disconnected'}\n• Trading API: ${systemStatus?.trading ? '🟢 Active' : 'šŸ”“ Inactive'}\n\n**šŸ“ˆ Trading Services:**\n• Drift Protocol: ${systemStatus?.trading ? '🟢 Connected' : 'šŸ”“ Not connected'}\n• Jupiter DEX: ${systemStatus?.trading ? '🟢 Available' : 'šŸ”“ Unavailable'}\n• Screenshot Service: ${systemStatus?.api ? '🟢 Ready' : 'šŸ”“ Not ready'}\n\n**🧠 AI Services:**\n• OpenAI GPT-4o mini: ${process.env.OPENAI_API_KEY ? '🟢 Configured' : 'šŸ”“ Not configured'}\n• Analysis Engine: ${systemStatus?.api ? '🟢 Ready' : 'šŸ”“ Not ready'}\n\n**šŸ’¾ Database:**\n• SQLite: 🟢 Connected\n• Position Tracking: ${activePosition ? '🟢 Active position found' : '🟔 No active positions'}\n\n${!activePosition ? '**šŸ’” Tip:** Execute a trade and mark it as traded to enable full follow-up features!' : '**āœ… Ready:** All systems operational for trade follow-up!'}`, + content: `šŸ“Š **System Status** (${new Date().toLocaleTimeString()})\n\n**Core Services:**\n• API: ${systemStatus?.api ? '🟢' : 'šŸ”“'} | Wallet: ${systemStatus?.wallet ? '🟢' : 'šŸ”“'} | Trading: ${systemStatus?.trading ? '🟢' : 'šŸ”“'}\n\n**Trading:**\n• Drift Protocol: ${systemStatus?.trading ? '🟢 Connected' : 'šŸ”“ Disconnected'}\n• Screenshot Service: ${systemStatus?.api ? '🟢 Ready' : 'šŸ”“ Not ready'}\n• AI Analysis: ${process.env.OPENAI_API_KEY ? '🟢 Ready' : 'šŸ”“ No API key'}\n\n**Container:**\n• Docker: 🟢 Running (Port 9001)\n• Database: 🟢 SQLite Connected\n\n${!activePosition ? 'āš ļø No active positions for follow-up' : 'āœ… Ready for trade management'}`, timestamp: new Date().toISOString() } setChatMessages(prev => [...prev, statusMessage]) @@ -173,7 +173,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) const thinkingMessage: ChatMessage = { id: (Date.now() + 1).toString(), type: 'assistant', - content: 'šŸ”„ **Getting Updated Analysis...**\n\nCapturing fresh screenshots and analyzing current market conditions for your position...', + content: 'šŸ”„ **Capturing fresh screenshots and analyzing...**', timestamp: new Date().toISOString() } setChatMessages(prev => [...prev, thinkingMessage]) @@ -262,12 +262,11 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps) } const quickActions = [ - "status", - "Should I exit now?", - "Update my stop loss", - "Current market analysis", - "Risk assessment", - "Take profit strategy" + "Exit now?", + "Move stop loss", + "Fresh analysis", + "Risk check", + "status" ] return (