From dd3db561e54fc71a3927143d178f2b47433ca2dc Mon Sep 17 00:00:00 2001 From: Kunthawat Greethong Date: Fri, 26 Jun 2026 12:19:45 +0700 Subject: [PATCH] fix: strengthen entity filtering for ad/business content - Add marketing metadata to 'Not allowed' list in ontology prompt - Strengthen exclude_self filter instruction - Add exclude_rules support from template filter rules - Update business_ad template with more excluded types --- backend/app/services/ontology_generator.py | 16 ++++++-- backend/app/templates.json | 47 +++++++++++++++++----- frontend/package-lock.json | 4 -- package-lock.json | 4 +- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/backend/app/services/ontology_generator.py b/backend/app/services/ontology_generator.py index 7ae82f0..46a49fb 100644 --- a/backend/app/services/ontology_generator.py +++ b/backend/app/services/ontology_generator.py @@ -53,6 +53,9 @@ Therefore, **entities must be real-world subjects that can speak and interact on - Abstract concepts (such as "public opinion", "emotion", "trend") - Topics/subjects (such as "academic integrity", "education reform") - Viewpoints/attitudes (such as "supporters", "opponents") +- Marketing/advertising metadata (such as "campaign name", "ad position", "ad channel", "ad format", "brand name") +- The entity that created the uploaded content (e.g., if the data is an ad, do NOT create an entity for the advertiser/brand) +- Non-human concepts that cannot speak or interact on social media ## Output Format @@ -221,14 +224,21 @@ class OntologyGenerator: if exclude_self: filter_instruction += ( - "- IMPORTANT: The uploaded data is from a business/brand/advertiser. " - "Do NOT create entity types for the business/brand that created this content. " - "Only create entities for the TARGET AUDIENCE, competitors, influencers, media, etc.\n" + "- CRITICAL: The uploaded data is from a business/brand/advertiser. " + "Do NOT create entity types for: the business itself, its brand name, campaign names, " + "ad positions, ad channels, ad formats, or any marketing metadata. " + "ONLY create entity types for real people/organizations who would REACT to this content: " + "target audience segments, competitors, influencers, media outlets, consumer groups.\n" ) if exclude_types: filter_instruction += f"- Do NOT create entity types matching: {', '.join(exclude_types)}\n" + # Add custom exclude rules from template + exclude_rules = template_filter_rules.get('exclude_rules', []) + for rule in exclude_rules: + filter_instruction += f"- {rule}\n" + if focus: filter_instruction += f"- Focus entity types on: {focus}\n" diff --git a/backend/app/templates.json b/backend/app/templates.json index 914b057..f9bfdfe 100644 --- a/backend/app/templates.json +++ b/backend/app/templates.json @@ -7,7 +7,10 @@ "prompt_th": "จำลองปฏิกิริยาของประชาชนบนโซเชียลมีเดียหลังจาก [เหตุการณ์] ในช่วง [ระยะเวลา] ชั่วโมง", "prompt_en": "Simulate public reactions on social media after [event] within [timeframe] hours", "prompt_zh": "模拟[事件]发生后公众在社交媒体上的反应,时间范围[时间]小时", - "placeholders": ["event", "timeframe"], + "placeholders": [ + "event", + "timeframe" + ], "entity_filter": { "exclude_types": [], "focus": "affected_parties, public, media, officials" @@ -20,7 +23,9 @@ "prompt_th": "จำลองผลกระทบของนโยบาย [ชื่อนโยบาย] ต่อกลุ่มต่างๆ ในสังคม รวมถึงการโต้ตอบบนโซเชียลมีเดีย", "prompt_en": "Simulate the impact of [policy name] on different social groups, including social media interactions", "prompt_zh": "模拟[政策名称]对不同社会群体的影响,包括社交媒体互动", - "placeholders": ["policy_name"], + "placeholders": [ + "policy_name" + ], "entity_filter": { "exclude_types": [], "focus": "citizens, experts, media, government, affected_groups" @@ -33,11 +38,28 @@ "prompt_th": "จำลองการแพร่กระจายและผลตอบรับของ [แคมเปญ/สินค้า] บนโซเชียลมีเดีย รวมถึงปฏิกิริยาของกลุ่มเป้าหมาย", "prompt_en": "Simulate the spread and reception of [campaign/product] on social media, including target audience reactions", "prompt_zh": "模拟[活动/产品]在社交媒体上的传播和反馈,包括目标受众的反应", - "placeholders": ["campaign_product"], + "placeholders": [ + "campaign_product" + ], "entity_filter": { "exclude_self": true, - "exclude_types": ["Advertiser", "BrandOwner"], - "focus": "target_audience, competitors, influencers, media" + "exclude_types": [ + "Advertiser", + "BrandOwner", + "Campaign", + "AdPosition", + "AdChannel", + "AdCreative", + "MarketingPlan", + "Brand" + ], + "exclude_rules": [ + "Do NOT create entities for the business/brand that created the ad", + "Do NOT create entities for ad metadata (campaign name, ad position, ad channel, ad format)", + "Do NOT create entities for abstract marketing concepts", + "ONLY create entities for real people/organizations who would react to the ad" + ], + "focus": "target_audience, competitors, influencers, media, consumer_groups" } }, { @@ -47,9 +69,14 @@ "prompt_th": "จำลองเรื่องราวต่อจาก [เนื้อเรื่อง] โดยให้ตัวละครแต่ละตัวมีปฏิสัมพันธ์กันบนโซเชียลมีเดีย และทำนายตอนจบ", "prompt_en": "Simulate the story continuation from [plot] with characters interacting on social media, and predict the ending", "prompt_zh": "模拟从[情节]开始的故事延续,角色在社交媒体上互动,并预测结局", - "placeholders": ["plot"], + "placeholders": [ + "plot" + ], "entity_filter": { - "exclude_types": ["Author", "Narrator"], + "exclude_types": [ + "Author", + "Narrator" + ], "focus": "characters, story_entities" } }, @@ -60,11 +87,13 @@ "prompt_th": "จำลองผลกระทบของ [กระแสสังคม] ต่อกลุ่มคนต่างๆ บนโซเชียลมีเดีย รวมถึงการแพร่กระจายของข้อมูล", "prompt_en": "Simulate the impact of [social trend] on different groups on social media, including information spread", "prompt_zh": "模拟[社会潮流]对不同群体在社交媒体上的影响,包括信息传播", - "placeholders": ["social_trend"], + "placeholders": [ + "social_trend" + ], "entity_filter": { "exclude_types": [], "focus": "public_figures, communities, media, influencers, general_public" } } ] -} +} \ No newline at end of file diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 3e56d75..fdab7ac 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -1435,7 +1435,6 @@ "resolved": "https://registry.npmjs.org/d3-selection/-/d3-selection-3.0.0.tgz", "integrity": "sha512-fmTRWbNMmsmWq6xJV8D19U/gw/bwrHfNXxrIN+HfZgnzqTHp9jOmKMhsTUjXOJnZOdZY9Q28y4yebKzqDKlxlQ==", "license": "ISC", - "peer": true, "engines": { "node": ">=12" } @@ -1913,7 +1912,6 @@ "integrity": "sha512-QP88BAKvMam/3NxH6vj2o21R6MjxZUAd6nlwAS/pnGvN9IVLocLHxGYIzFhg6fUQ+5th6P4dv4eW9jX3DSIj7A==", "dev": true, "license": "MIT", - "peer": true, "engines": { "node": ">=12" }, @@ -2053,7 +2051,6 @@ "integrity": "sha512-ITcnkFeR3+fI8P1wMgItjGrR10170d8auB4EpMLPqmx6uxElH3a/hHGQabSHKdqd4FXWO1nFIp9rRn7JQ34ACQ==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.25.0", "fdir": "^6.5.0", @@ -2128,7 +2125,6 @@ "resolved": "https://registry.npmjs.org/vue/-/vue-3.5.25.tgz", "integrity": "sha512-YLVdgv2K13WJ6n+kD5owehKtEXwdwXuj2TTyJMsO7pSeKw2bfRNZGjhB7YzrpbMYj5b5QsUebHpOqR3R3ziy/g==", "license": "MIT", - "peer": true, "dependencies": { "@vue/compiler-dom": "3.5.25", "@vue/compiler-sfc": "3.5.25", diff --git a/package-lock.json b/package-lock.json index 64b5f2f..737afc3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { - "name": "mirofish", + "name": "crowdsight", "version": "0.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "mirofish", + "name": "crowdsight", "version": "0.1.0", "license": "AGPL-3.0", "devDependencies": {