Skip to content

Commit e51b725

Browse files
committed
fix: Handle community theme entities as objects in frontend and API
- Fix React rendering error: entities are objects, not strings - Update ThemeExtractionView to display entity objects with name, type, description - Update summary endpoint to handle entities as objects or strings - Add support for community_id in theme details display - Fix entities array handling in query context building
1 parent 819ebd4 commit e51b725

2 files changed

Lines changed: 59 additions & 13 deletions

File tree

api.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,11 +1372,36 @@ async def generate_theme_summary(
13721372
f" {i}. {p.get('from', 'Unknown')}{p.get('to', 'Unknown')}"
13731373
)
13741374

1375+
if theme_data.get("entities"):
1376+
entities = theme_data["entities"]
1377+
context_parts.append(f"\nEntities ({theme_data.get('total_entities', len(entities))}):")
1378+
for i, entity in enumerate(entities[:10], 1):
1379+
if isinstance(entity, dict):
1380+
entity_name = entity.get("name", entity.get("entity", "Unknown"))
1381+
entity_type = entity.get("type", "")
1382+
entity_desc = entity.get("description", "")
1383+
entity_info = f" {i}. {entity_name}"
1384+
if entity_type:
1385+
entity_info += f" ({entity_type})"
1386+
if entity_desc:
1387+
entity_info += f" - {entity_desc[:100]}"
1388+
context_parts.append(entity_info)
1389+
else:
1390+
context_parts.append(f" {i}. {entity}")
1391+
13751392
if theme_data.get("relationships"):
13761393
relationships = theme_data["relationships"]
1377-
context_parts.append(f"\nRelated Entities ({len(relationships)}):")
1394+
context_parts.append(f"\nRelationships ({len(relationships)}):")
13781395
for i, rel in enumerate(relationships[:10], 1):
1379-
context_parts.append(
1396+
if isinstance(rel, dict):
1397+
rel_info = f" {i}. {rel.get('name', 'Unknown')}"
1398+
if rel.get("relationship"):
1399+
rel_info += f" - {rel.get('relationship')}"
1400+
if rel.get("type"):
1401+
rel_info += f" ({rel.get('type')})"
1402+
context_parts.append(rel_info)
1403+
else:
1404+
context_parts.append(
13801405
f" {i}. {rel.get('name', 'Unknown')} ({rel.get('relationship', 'related')})"
13811406
)
13821407

frontend/src/components/ThemeExtractionView.tsx

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,11 @@ export function ThemeExtractionView() {
146146
themeContext += `\n\nKey Partnerships: ${partnerships}`;
147147
}
148148
if (themeDetails.entities && themeDetails.entities.length > 0) {
149-
themeContext += `\n\nRelated Entities: ${themeDetails.entities.slice(0, 10).join(', ')}`;
149+
// Handle entities as objects or strings
150+
const entityNames = themeDetails.entities.slice(0, 10).map((e: any) =>
151+
typeof e === 'string' ? e : e.name || e.entity || String(e)
152+
);
153+
themeContext += `\n\nRelated Entities: ${entityNames.join(', ')}`;
150154
}
151155
}
152156

@@ -876,21 +880,38 @@ export function ThemeExtractionView() {
876880
{themeDetails.entities && themeDetails.entities.length > 0 && (
877881
<div>
878882
<div style={{ fontSize: 12, color: '#94a3b8', marginBottom: 12, fontWeight: 500 }}>
879-
RELATED ENTITIES ({themeDetails.entities.length})
883+
ENTITIES ({themeDetails.total_entities || themeDetails.entities.length})
880884
</div>
881-
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 6 }}>
882-
{themeDetails.entities.map((entity: string, i: number) => (
883-
<span
885+
<div style={{ display: 'grid', gap: 10 }}>
886+
{themeDetails.entities.slice(0, 20).map((entity: any, i: number) => (
887+
<div
884888
key={i}
885889
style={{
886-
padding: '4px 10px',
887-
background: 'rgba(59, 130, 246, 0.2)',
888-
borderRadius: 6,
889-
fontSize: 12
890+
padding: 12,
891+
background: 'rgba(30, 41, 59, 0.6)',
892+
borderRadius: 8,
893+
border: '1px solid rgba(59, 130, 246, 0.1)'
890894
}}
891895
>
892-
{entity}
893-
</span>
896+
<div style={{ fontWeight: 600, color: '#f1f5f9', marginBottom: 4 }}>
897+
{typeof entity === 'string' ? entity : entity.name || entity.entity || 'Unknown'}
898+
</div>
899+
{typeof entity === 'object' && entity.type && (
900+
<div style={{ fontSize: 11, color: '#64748b', marginBottom: 4 }}>
901+
Type: {entity.type}
902+
</div>
903+
)}
904+
{typeof entity === 'object' && entity.description && (
905+
<div style={{ fontSize: 13, color: '#cbd5e1', marginBottom: 4 }}>
906+
{entity.description}
907+
</div>
908+
)}
909+
{typeof entity === 'object' && entity.mention_count && (
910+
<div style={{ fontSize: 12, color: '#94a3b8' }}>
911+
Mentioned {entity.mention_count} times
912+
</div>
913+
)}
914+
</div>
894915
))}
895916
</div>
896917
</div>

0 commit comments

Comments
 (0)