🌟

LLM x semanticlayerな分析bot

に公開

背景

無料LLM使って最大限楽して分析レポートの下書き欲しい、らしい

poc作ってくれって感じ

目的

無料LLM使ってsemanticlayerと組み合わせて自動レポート生成の仕組みを作る

Caveat

  1. dataは学習されないらしいので大丈夫
  2. promptは企業秘密なので雑なものを仮使用

内容

github actions x github model x metricsflow のコンボでいく、これで完全無料

スニペット

.github/workflows/daily-analysis-report.yml

      - name: Generate Strategic Analysis Report
        id: analysis
        uses: actions/ai-inference@v1
        with:
          model: openai/gpt-4o
          max-tokens: 3500
          system-prompt: |
            あなたはマッキンゼー、BCG、ベインなどのトップティア戦略コンサルティングファームのシニアパートナーです。
            提供されたビジネスメトリクスデータを分析し、経営陣向けの戦略的な日次分析レポートを作成してください。

            レポートは以下の要素を含む必要があります:
            - データドリブンな洞察(具体的な数値と変化率を含む)
            - 戦略的な推奨事項(実行可能で具体的)
            - リスク要因の特定と対策
            - 競争優位性を築くための提案

            フォーマット:
            - Markdownで記述
            - プロフェッショナルなビジネス言語を使用
            - 数値は適切にフォーマット(例:$1.2M、+15.3%)
            - 一般的な表現を避け、具体的で実践的な内容にする
          prompt: |
            ## Store Performance Analysis (Last 7 Days)
            ${{ steps.store_metrics.outputs.store_data }}

            Based on this data, create a comprehensive strategic analysis report in Japanese with:

            1. **Executive Summary**
               - 3-4 key insights that C-level executives need to know
               - Focus on strategic implications, not just operational metrics

            2. **Performance Deep Dive**
               - Analyze trends and patterns in the data
               - Identify correlations and causations
               - Compare channel effectiveness
               - Evaluate product portfolio performance

            3. **Customer Intelligence**
               - Customer behavior patterns
               - Retention and acquisition insights
               - Customer lifetime value optimization opportunities

            4. **Strategic Recommendations**
               - Immediate actions (0-7 days)
               - Short-term initiatives (7-30 days)
               - Long-term strategic priorities (30+ days)

            5. **Risk Assessment**
               - Identify potential risks based on current trends
               - Propose mitigation strategies
               - Early warning indicators to monitor
      - name: Collect Store Performance Metrics
        id: store_metrics
        run: |
          STORE_DATA=$(docker compose --profile tools run --rm app mf query \
            --saved-query store_day_of_week_analysis \
            --start-time "$(date -d "${{ steps.dates.outputs.target_date }} -7 days" '+%Y-%m-%d')" \
            --end-time '${{ steps.dates.outputs.target_date }}')

          WEEKEND_DATA=$(docker compose --profile tools run --rm app mf query \
            --metrics weekend_revenue,weekday_revenue,weekend_revenue_ratio \
            --start-time "$(date -d "${{ steps.dates.outputs.target_date }} -7 days" '+%Y-%m-%d')" \
            --end-time '${{ steps.dates.outputs.target_date }}')

          echo "store_data<<EOF" >> $GITHUB_OUTPUT
          echo "Store Day of Week Analysis:" >> $GITHUB_OUTPUT
          echo "$STORE_DATA" >> $GITHUB_OUTPUT
          echo "" >> $GITHUB_OUTPUT
          echo "Weekend vs Weekday Analysis:" >> $GITHUB_OUTPUT
          echo "$WEEKEND_DATA" >> $GITHUB_OUTPUT
          echo "EOF" >> $GITHUB_OUTPUT

.github/prompts/strategic-analysis.prompt.yml
を直接使えるといいのに

コメント

まあmetricsをnotionに連携してnotion aiでやってくれてもいい
すぷしにai functionでたしそれでもいい
notebook lm apiも出たしそれにも使える

なのでみんなセマンティックレイヤーをちゃんと使おうね

参考

https://github.blog/ai-and-ml/generative-ai/automate-your-project-with-github-models-in-actions/

https://github.blog/news-insights/product-news/introducing-github-models/

https://github.com/actions/ai-inference

Discussion