Skip to content

Commit 505000c

Browse files
committed
updated templates
1 parent e1d4f0c commit 505000c

File tree

3 files changed

+118
-1
lines changed

3 files changed

+118
-1
lines changed

client/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@ async def get_mcp_client(client_id: str):
241241
- Respond in human-like conversational, friendly, and professional tone in concise manner.
242242
- When market data is requested, always present it in a clean, easy-to-read format.
243243
- For numerical values like prices and quantities, always display them with appropriate units.
244+
- IMPORTANT: When displaying tables of data (orders, positions, etc.), format them using markdown tables with clear headers and aligned columns. For example:
245+
246+
```
247+
| Order ID | Symbol | Action | Quantity | Price | Status |
248+
|----------|--------|--------|----------|-------|--------|
249+
| 12345678 | RELIANCE | BUY | 10 | 1426.5 | complete |
250+
```
244251
- Help users construct proper symbol formats based on OpenAlgo's standardized conventions.
245252
246253
# Responsibilities:

client/static/script.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,55 @@ class TradingAssistant {
442442

443443
parseMarkdown(content) {
444444
if (typeof marked !== 'undefined') {
445-
return marked.parse(content);
445+
// Configure marked for better table rendering
446+
marked.setOptions({
447+
gfm: true, // GitHub Flavored Markdown
448+
breaks: true,
449+
tables: true,
450+
headerIds: false
451+
});
452+
453+
// Process table-specific content for better formatting
454+
let processedContent = content;
455+
456+
// Fix malformed tables from GROQ responses
457+
// Check for table-like content and ensure proper formatting
458+
if (content.includes('|') && !content.includes('```')) {
459+
const lines = content.split('\n');
460+
const tableLines = [];
461+
let inTable = false;
462+
463+
for (let i = 0; i < lines.length; i++) {
464+
const line = lines[i].trim();
465+
if (line.startsWith('|') && line.endsWith('|')) {
466+
if (!inTable) {
467+
inTable = true;
468+
// If this is first line of table and next line isn't a separator, add one
469+
if (i + 1 < lines.length) {
470+
const nextLine = lines[i + 1].trim();
471+
if (!nextLine.includes('---') && !nextLine.includes('===')) {
472+
// Count columns and create separator
473+
const colCount = (line.match(/\|/g) || []).length - 1;
474+
tableLines.push(line);
475+
tableLines.push('|' + Array(colCount).fill(' --- |').join(''));
476+
continue;
477+
}
478+
}
479+
}
480+
tableLines.push(line);
481+
} else if (inTable && line.includes('|')) {
482+
// Handle malformed table rows that don't start/end with |
483+
tableLines.push('|' + line + (line.endsWith('|') ? '' : '|'));
484+
} else if (line === '' && inTable) {
485+
inTable = false;
486+
} else {
487+
tableLines.push(line);
488+
}
489+
}
490+
processedContent = tableLines.join('\n');
491+
}
492+
493+
return marked.parse(processedContent);
446494
}
447495
return this.escapeHtml(content).replace(/\n/g, '<br>');
448496
}

client/static/style.css

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,68 @@
424424
}
425425

426426
/* Print Styles */
427+
/* Enhanced Table Styles for Chat Messages */
428+
.chat-bubble table {
429+
width: 100%;
430+
border-collapse: collapse;
431+
margin: 10px 0;
432+
font-size: 0.9em;
433+
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
434+
border-radius: 8px;
435+
overflow: hidden;
436+
background: rgba(255, 255, 255, 0.05);
437+
border: 1px solid rgba(255, 255, 255, 0.2);
438+
}
439+
440+
.chat-bubble th {
441+
background-color: rgba(0, 0, 0, 0.3);
442+
color: var(--color-text-bright);
443+
font-weight: 600;
444+
text-align: left;
445+
padding: 8px 12px;
446+
border: 1px solid rgba(255, 255, 255, 0.2);
447+
}
448+
449+
.chat-bubble td {
450+
padding: 8px 12px;
451+
border: 1px solid rgba(255, 255, 255, 0.2);
452+
}
453+
454+
/* Removed redundant border-bottom rule */
455+
456+
.chat-bubble tr:nth-child(even) {
457+
background-color: rgba(255, 255, 255, 0.03);
458+
}
459+
460+
.chat-bubble tr:hover {
461+
background-color: rgba(255, 255, 255, 0.08);
462+
}
463+
464+
/* Fixed width columns for specific data types */
465+
.chat-bubble table th:nth-child(1),
466+
.chat-bubble table td:nth-child(1) {
467+
min-width: 100px;
468+
}
469+
470+
.chat-bubble table th:nth-child(3),
471+
.chat-bubble table td:nth-child(3),
472+
.chat-bubble table th:nth-child(4),
473+
.chat-bubble table td:nth-child(4) {
474+
text-align: center;
475+
}
476+
477+
/* Responsive tables */
478+
@media (max-width: 768px) {
479+
.chat-bubble table {
480+
font-size: 0.8em;
481+
}
482+
483+
.chat-bubble th,
484+
.chat-bubble td {
485+
padding: 6px 8px;
486+
}
487+
}
488+
427489
@media print {
428490
.sidebar-modern,
429491
.navbar-modern,

0 commit comments

Comments
 (0)