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:
mindesbunister
2025-07-17 16:44:32 +02:00
parent 303c19fe30
commit 39de37e7eb
2 changed files with 32 additions and 36 deletions

View File

@@ -89,18 +89,17 @@ CURRENT POSITION DETAILS:
messages: [ messages: [
{ {
role: "system", 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: PROVIDE CONCISE ANALYSIS (Max 100 words):
1. Current market structure and price action Current price action vs entry
2. Whether to hold, exit, or adjust the position • Key levels to watch
3. Stop loss and take profit recommendations • Risk assessment
4. Risk assessment based on current conditions • Immediate action needed
5. Key levels to watch
Be specific with price levels and actionable advice. Focus on PRACTICAL trade management.` Be direct. Give exact price levels only.`
}, },
{ {
role: "user", 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 temperature: 0.1
}) })
@@ -123,25 +122,23 @@ Be specific with price levels and actionable advice. Focus on PRACTICAL trade ma
} }
// Generate conversational response // 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} ${positionContext}
${chatContext}
${screenshotAnalysis ? `\nLATEST CHART ANALYSIS:\n${screenshotAnalysis}` : ''} ${screenshotAnalysis ? `LATEST CHART ANALYSIS:\n${screenshotAnalysis}\n` : ''}
GUIDELINES: RESPONSE STYLE:
- Be conversational and supportive - Be direct and actionable
- Give specific, actionable advice - Give EXACT price levels only
- Use exact price levels when possible - Use bullet points for clarity
- Consider risk management principles - Maximum 150 words total
- Be honest about market uncertainty - Focus on immediate action needed
- Use emojis appropriately
- Format important information clearly
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({ const response = await openai.chat.completions.create({
model: "gpt-4o-mini", model: "gpt-4o-mini",
@@ -155,8 +152,8 @@ Provide helpful, specific guidance for their current position.`
content: message content: message
} }
], ],
max_tokens: 800, max_tokens: 200,
temperature: 0.3 temperature: 0.1
}) })
const assistantResponse = response.choices[0]?.message?.content const assistantResponse = response.choices[0]?.message?.content

View File

@@ -96,7 +96,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
setChatMessages([{ setChatMessages([{
id: Date.now().toString(), id: Date.now().toString(),
type: 'system', 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() timestamp: new Date().toISOString()
}]) }])
} else { } else {
@@ -107,7 +107,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
setChatMessages([{ setChatMessages([{
id: Date.now().toString(), id: Date.now().toString(),
type: 'system', 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() timestamp: new Date().toISOString()
}]) }])
} }
@@ -116,7 +116,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
setChatMessages([{ setChatMessages([{
id: Date.now().toString(), id: Date.now().toString(),
type: 'system', 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() timestamp: new Date().toISOString()
}]) }])
} }
@@ -150,7 +150,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
const statusMessage: ChatMessage = { const statusMessage: ChatMessage = {
id: (Date.now() + 1).toString(), id: (Date.now() + 1).toString(),
type: 'assistant', 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() timestamp: new Date().toISOString()
} }
setChatMessages(prev => [...prev, statusMessage]) setChatMessages(prev => [...prev, statusMessage])
@@ -173,7 +173,7 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
const thinkingMessage: ChatMessage = { const thinkingMessage: ChatMessage = {
id: (Date.now() + 1).toString(), id: (Date.now() + 1).toString(),
type: 'assistant', 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() timestamp: new Date().toISOString()
} }
setChatMessages(prev => [...prev, thinkingMessage]) setChatMessages(prev => [...prev, thinkingMessage])
@@ -262,12 +262,11 @@ export default function TradeFollowUpPanel({ onClose }: TradeFollowUpPanelProps)
} }
const quickActions = [ const quickActions = [
"status", "Exit now?",
"Should I exit now?", "Move stop loss",
"Update my stop loss", "Fresh analysis",
"Current market analysis", "Risk check",
"Risk assessment", "status"
"Take profit strategy"
] ]
return ( return (