Skip to main content
Glama

Google Places MCP Server

by colakang
评分系统.md14.1 kB
# 基于Google Places数据的LLM餐厅评分系统 ## 📋 系统概述 针对Google Places API数据格式优化的餐厅评论评分系统,将情感分析和综合评分计算合并到统一的prompt中,提高处理效率。 --- ## 🎯 核心 Prompt 模板 ### 1. 餐厅综合评分分析 Prompt (情感分析+评分计算一体化) ``` 你是一个专业的餐厅数据分析专家。基于Google Places的餐厅数据,进行综合评分分析。 **分析规则:** **数据源权重配置:** - Google Reviews: 70% (主要数据源) - 其他平台评论: 30% (如果有多个数据源) **情感分析标准:** - 正面(positive): 表达满意、推荐、赞美,通常对应4-5星评分 - 负面(negative): 表达不满、抱怨、批评,通常对应1-2星评分 - 中性(neutral): 客观陈述或3星评分,无明显情感倾向 **时间权重计算:** - 1个月内: 权重1.0 - 1-3个月: 权重0.9 - 3-6个月: 权重0.8 - 6-12个月: 权重0.7 - 1-2年: 权重0.6 - 2年以上: 权重0.5 **负面影响放大系数:** 1.5倍 **输入数据:** ```json { "restaurant_name": "{restaurant_name}", "overall_rating": {overall_rating}, "total_reviews": {userRatingCount}, "price_level": "{priceLevel}", "reviews": [ { "rating": {rating}, "text": "{review_text}", "publish_time": "{relativePublishTimeDescription}", "author": "{author_name}" } ] } ``` **计算公式:** 最终得分 = Σ(情感调整评分 × 时间权重 × 情感权重) / Σ(总权重) 其中: - 情感调整评分 = 标准化评分(0-1) × 情感修正系数 - 情感修正系数:正面1.0,中性0.9,负面0.7 - 情感权重:正面1.0,中性0.8,负面1.5 **输出格式(严格JSON):** ```json { "restaurant_analysis": { "name": "餐厅名称", "final_score": 0.78, "score_grade": "良好", "confidence_level": 0.85 }, "review_analysis": { "total_processed": 15, "sentiment_distribution": { "positive": 8, "negative": 3, "neutral": 4 }, "time_distribution": { "recent_1month": 3, "recent_3months": 5, "recent_6months": 4, "older": 3 }, "detailed_reviews": [ { "review_id": 1, "original_rating": 4, "normalized_score": 0.75, "sentiment": "positive", "sentiment_confidence": 0.92, "time_weight": 0.9, "sentiment_weight": 1.0, "final_contribution": 0.675, "key_sentiment_indicators": ["味道很棒", "服务好"], "concerns": [] } ] }, "quality_metrics": { "review_volume": "充足", "data_freshness": "良好", "sentiment_consistency": "稳定", "potential_red_flags": [], "standout_strengths": ["菜品质量", "服务态度"], "main_concerns": ["等位时间"] }, "recommendation_level": { "category": "推荐", "reasoning": "评分稳定,正面评价占主导,近期表现良好", "risk_factors": ["偶有服务投诉"], "best_for": ["商务用餐", "朋友聚会"] } } ``` **分析示例:** 基于提供的Peace Harmony餐厅数据: - 总评分4.7/5,540条评论 - 价格等级:便宜 - 最新评论显示正面情感占主导 - 计算结果应反映高质量和性价比 ``` ### 2. 多餐厅对比分析 Prompt ``` 你是餐厅市场分析专家。对多个餐厅进行横向对比分析,生成排名和推荐报告。 **输入数据:** ```json { "analysis_context": { "user_location": "{user_location}", "search_criteria": "{search_criteria}", "analysis_date": "2025-07-17" }, "restaurants": [ { "name": "餐厅名称", "google_data": {...}, "calculated_score": 0.78, "analysis_results": {...} } ] } ``` **对比维度:** 1. 综合评分对比 2. 性价比分析 3. 服务质量稳定性 4. 用户群体偏好 5. 地理位置便利性 6. 特色优势分析 **输出格式(严格JSON):** ```json { "comparison_summary": { "total_analyzed": 5, "analysis_date": "2025-07-17", "market_leader": { "name": "Peace Harmony", "score": 0.85, "key_advantages": ["高性价比", "稳定质量", "便利位置"] }, "market_insights": { "average_score": 0.72, "score_range": [0.45, 0.89], "common_strengths": ["食物质量", "素食选择"], "common_weaknesses": ["等位时间", "空间大小"] } }, "detailed_rankings": [ { "rank": 1, "restaurant_name": "Peace Harmony", "score": 0.85, "price_category": "经济实惠", "standout_features": ["正宗泰式风味", "优秀性价比"], "weakness_areas": ["座位有限"], "target_audience": "追求性价比的素食爱好者", "recommendation_strength": "强烈推荐" } ], "category_leaders": { "highest_quality": "Peace Harmony", "best_value": "Peace Harmony", "most_consistent": "天慈素食楼", "best_location": "Peace Harmony" }, "scenario_recommendations": { "快速午餐": ["Peace Harmony"], "商务聚餐": ["天慈素食楼"], "朋友聚会": ["Peace Harmony", "天慈素食楼"], "家庭用餐": ["天慈素食楼"] }, "market_trends": { "emerging_themes": ["健康饮食", "素食流行"], "customer_priorities": ["性价比", "食物质量", "服务效率"], "competitive_landscape": "竞争激烈,差异化明显" } } ``` ``` ### 3. 个性化推荐生成 Prompt ``` 你是智能餐厅推荐系统。基于用户画像和餐厅分析结果,生成个性化推荐。 **用户画像:** ```json { "preferences": { "cuisine_type": ["{preferred_cuisines}"], "price_sensitivity": "{price_level}", "dining_context": "{context}", "group_size": {group_size}, "dietary_restrictions": ["{restrictions}"] }, "behavioral_data": { "previous_ratings": [...], "review_patterns": "{patterns}", "frequency": "{dining_frequency}" }, "location_context": { "current_location": "{location}", "travel_radius": "{radius_km}", "transportation": "{method}" } } ``` **餐厅候选池:** ```json { "candidates": [ { "restaurant": {...}, "analysis_score": 0.78, "match_factors": {...} } ] } ``` **推荐算法权重:** - 餐厅质量评分: 40% - 用户偏好匹配: 35% - 地理便利性: 15% - 性价比: 10% **输出格式(严格JSON):** ```json { "personalized_recommendations": [ { "restaurant_name": "Peace Harmony", "match_score": 0.92, "quality_score": 0.85, "recommendation_level": "强烈推荐", "match_reasons": [ "符合您的素食偏好", "价格区间匹配", "位置便利(距离500米)", "评价稳定正面" ], "experience_prediction": { "satisfaction_probability": 0.88, "likely_rating": 4.5, "estimated_wait_time": "10-15分钟", "best_visit_time": "工作日午餐时间" }, "potential_concerns": [ "用餐高峰期可能需要排队" ], "suggested_dishes": [ "Pad Thai", "绿咖喱", "素食炒河粉" ], "booking_advice": "建议提前电话预订" } ], "alternative_options": [ { "restaurant_name": "天慈素食楼", "reason": "如果首选餐厅客满的备选方案", "key_differences": "更传统的中式素食,价格稍高" } ], "user_insights": { "taste_profile": "偏爱亚洲风味,注重性价比", "dining_pattern": "频繁的午餐用餐者", "recommendation_confidence": 0.85 }, "contextual_advice": { "timing": "避开12:00-13:00高峰期", "ordering": "推荐尝试招牌菜品", "experience_tips": "该餐厅适合快速用餐" } } ``` ``` --- ## 🔄 工作流程实现 ### Python实现示例 ```python import json from datetime import datetime from typing import Dict, List, Any class RestaurantAnalyzer: def __init__(self, llm_client): self.llm_client = llm_client self.time_weights = { "1个月前": 1.0, "2个月前": 0.9, "3个月前": 0.9, "4个月前": 0.8, "5个月前": 0.8, "6个月前": 0.8, "1年前": 0.6, "2年前": 0.5 } def analyze_restaurant(self, google_places_data: Dict) -> Dict: """分析单个餐厅""" prompt = self._build_analysis_prompt(google_places_data) result = self.llm_client.generate(prompt) return self._parse_analysis_result(result) def compare_restaurants(self, restaurants_data: List[Dict]) -> Dict: """对比多个餐厅""" analyzed_restaurants = [] for restaurant in restaurants_data: analysis = self.analyze_restaurant(restaurant) analyzed_restaurants.append({ "restaurant": restaurant, "analysis": analysis }) comparison_prompt = self._build_comparison_prompt(analyzed_restaurants) result = self.llm_client.generate(comparison_prompt) return self._parse_comparison_result(result) def generate_recommendations(self, user_profile: Dict, restaurants_analysis: Dict) -> Dict: """生成个性化推荐""" recommendation_prompt = self._build_recommendation_prompt( user_profile, restaurants_analysis ) result = self.llm_client.generate(recommendation_prompt) return self._parse_recommendation_result(result) def _build_analysis_prompt(self, data: Dict) -> str: """构建分析prompt""" restaurant_info = { "restaurant_name": data.get("displayName", {}).get("text", ""), "overall_rating": data.get("rating", 0), "userRatingCount": data.get("userRatingCount", 0), "priceLevel": data.get("priceLevel", ""), "reviews": [] } for review in data.get("reviews", []): restaurant_info["reviews"].append({ "rating": review.get("rating", 0), "text": review.get("text", {}).get("text", ""), "publish_time": review.get("relativePublishTimeDescription", ""), "author": review.get("authorAttribution", {}).get("displayName", "") }) return ANALYSIS_PROMPT.format( restaurant_data=json.dumps(restaurant_info, ensure_ascii=False, indent=2) ) # 使用示例 analyzer = RestaurantAnalyzer(llm_client) # 分析单个餐厅 restaurant_analysis = analyzer.analyze_restaurant(google_places_data) print(f"餐厅评分: {restaurant_analysis['restaurant_analysis']['final_score']}") # 对比多个餐厅 comparison_result = analyzer.compare_restaurants([restaurant1, restaurant2]) print(f"推荐餐厅: {comparison_result['comparison_summary']['market_leader']['name']}") # 生成个性化推荐 user_profile = { "preferences": { "cuisine_type": ["素食", "亚洲菜"], "price_sensitivity": "中等", "dining_context": "朋友聚餐" } } recommendations = analyzer.generate_recommendations(user_profile, comparison_result) ``` --- ## ⚙️ 优化配置 ### 数据源权重动态调整 ```json { "google_reviews_weight": 0.7, "other_sources_weight": 0.3, "minimum_reviews_threshold": 10, "confidence_adjustment": { "high_volume": 1.0, "medium_volume": 0.9, "low_volume": 0.8 } } ``` ### 时间衰减函数 ```python def calculate_time_weight(publish_time_desc: str) -> float: """计算时间权重""" time_mapping = { "1个月前": 1.0, "2个月前": 0.95, "3个月前": 0.9, "4个月前": 0.85, "5个月前": 0.8, "6个月前": 0.75, "8个月前": 0.7, "1年前": 0.6, "2年前": 0.5, "3年前": 0.4 } for time_phrase, weight in time_mapping.items(): if time_phrase in publish_time_desc: return weight # 默认权重(未知时间) return 0.5 ``` ### 情感分析关键词库 ```json { "positive_keywords": [ "很棒", "好吃", "推荐", "满意", "优秀", "新鲜", "美味", "服务好", "性价比高", "环境好", "authentic", "delicious", "fresh", "excellent", "recommend", "tasty" ], "negative_keywords": [ "差", "难吃", "贵", "慢", "失望", "不推荐", "一般", "油腻", "服务差", "等位久", "terrible", "bad", "expensive", "slow", "disappointed", "not recommend", "poor service" ], "neutral_indicators": [ "还可以", "还行", "普通", "中等", "一般般", "okay", "average", "decent" ] } ``` --- ## 🚀 实际应用场景 ### 场景1: 单餐厅快速评估 ```python # 处理Peace Harmony餐厅数据 peace_harmony_result = analyzer.analyze_restaurant(peace_harmony_data) # 输出结果 { "final_score": 0.82, "recommendation_level": "强烈推荐", "key_strengths": ["正宗口味", "优秀性价比", "快速服务"], "main_concerns": ["座位有限", "用餐高峰期等位"] } ``` ### 场景2: 区域餐厅排名 ```python # 悉尼素食餐厅对比 sydney_vegan_restaurants = [peace_harmony_data, tianci_data, other_restaurants...] ranking = analyzer.compare_restaurants(sydney_vegan_restaurants) # 生成排名报告 top_restaurant = ranking['detailed_rankings'][0] print(f"第一名: {top_restaurant['restaurant_name']} (评分: {top_restaurant['score']})") ``` ### 场景3: 个性化推荐 ```python # 素食爱好者推荐 user = { "preferences": { "cuisine_type": ["素食", "泰式"], "price_sensitivity": "经济实惠", "dining_context": "快速午餐" }, "location": "悉尼市中心" } recommendations = analyzer.generate_recommendations(user, ranking) print(f"为您推荐: {recommendations['personalized_recommendations'][0]['restaurant_name']}") ``` 这套优化后的系统直接对接Google Places API数据格式,将情感分析和评分计算合并到一个高效的prompt中,大大提高了处理效率和实用性!

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/colakang/google-places-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server