将交互式航班价格趋势图表嵌入AI响应。需要SerpAPI密钥获取实时数据,用于可视化60天价格历史。
Embed an interactive flight price trend visualization component when AI responses contain flight recommendations with confirmed OD (Origin-Destination) pairs.
本 skill 需要 SerpAPI Key 才能获取实时航班价格数据。
如果用户尚未配置 SerpAPI Key,请先引导用户完成以下步骤:
注册 SerpAPI 账号:访问 https://serpapi.com/users/sign_up 免费注册
获取 API Key:登录后在 Dashboard 中复制你的 API Key
配置项目:
price/config.example.json 为 price/config.jsonconfig.json 中的 serpapi.apiKey 字段💡 SerpAPI 提供免费额度,足够个人使用。配置完成后即可获取真实的航班价格趋势数据。
PriceChart component at the end of the responsejsx
<PriceChart
data={priceHistory} // Array of {date, price}
currentPrice={currentPrice} // Current flight price
analysis={analysis} // Price analysis object
destination={destination} // Destination info
/>
priceHistory - 60-day price history:
javascript
[
{ date: "2026-03-01", price: 1299 },
{ date: "2026-03-02", price: 1350 },
// ... up to 60 days
]
analysis - Price analysis object:
javascript
{
min: 1199, // Lowest price in period
max: 1899, // Highest price in period
average: 1450, // Average price
pctDiff: -12, // Percentage vs average
level: "low", // "low" | "mid" | "high"
trend: "falling" // "falling" | "rising" | "stable"
}
destination - Destination info:
javascript
{
code: "TYO", // Airport/city code
name: "Tokyo" // City name
}
When AI returns flight recommendations:
text
[Flight cards showing 3-5 options]
[Price trend chart showing 60-day history]
[Buy/wait recommendation]
When user asks about price trends:
text
"Here's the price trend for Tokyo flights over the past 60 days..."
[Price trend chart]
"Current prices are 12% below average, making it a good time to buy."
When providing purchase timing advice:
text
[Price analysis summary]
[Recommendation card: "Buy Now" or "Wait"]
[Price trend chart for context]
When using flyai for flight searches:
flyai search-flight to get flight resultsBy default, the price trend uses simulated data (for demo/development only).
To enable real price data, configure your SerpAPI Key:
Get API Key at https://serpapi.com/users/sign_up
Add to price/config.json:
json
{ "serpapi": { "apiKey": "your-key-here" } }
Restart the server
See references/configure-serpapi.md for detailed setup guide.
text
Before: User Query → Mock Data Generator → Estimated Prices
After: User Query → SerpAPI → Real Prices → Auto-collect & Store
As data accumulates, AI responses should indicate confidence:
Days of DataConfidenceAI Disclaimer< 7 daysLow"价格数据为估算值,仅供参考"7-29 daysMedium"根据部分真实价格数据..."30+ daysHigh"根据积累的真实价格数据..."
See references/data-sources.md for more details.
ComponentDocPriceChartreferences/price-chart-component.mdData APIreferences/price-api.mdAnalysis Logicreferences/price-analysis.mdData Sourcesreferences/data-sources.md
markdown
Based on your search, here are the best flights to Tokyo:
[Flight Cards Component]
## Price Analysis
Current prices are **12% below average** for this route.
[PriceChart Component]
### Recommendation: Buy Now ✅
- Current price: ¥1,299
- Historical average: ¥1,450
- You save: ¥151
Prices have been falling over the past 2 weeks. If you need to travel in peak season, booking now is recommended.