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'.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user