Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ChatGPT in SlackでAI Slackbotを楽しく運用する

iwamot
September 13, 2023

ChatGPT in SlackでAI Slackbotを楽しく運用する

2023-09-14
みんなのPython勉強会#97
https://startpython.connpass.com/event/294703/

iwamot

September 13, 2023
Tweet

More Decks by iwamot

Other Decks in Technology

Transcript

  1. ChatGPT in SlackでAI Slackbotを楽しく運用する
    2023-09-14
    みんなのPython勉強会#97
    https://startpython.connpass.com/event/294703/
    ENECHANGE株式会社 CTO室
    インフラエンジニア兼SRE 岩本隆史 (iwamot)

    View Slide

  2. ChatGPT in Slackとは

    View Slide

  3. OSSのAI Slackbotアプリ
    https://github.com/seratch/ChatGPT-in-Slack

    View Slide

  4. Slackの瀬良さんが個人で開発
    https://www.linkedin.com/in/seratch/

    View Slide

  5. もちろんPythonで実装
    https://github.com/seratch/ChatGPT-in-Slack

    View Slide

  6. いろんな環境で実行可能

    View Slide

  7. ローカル環境・Amazon EC2等
    # Create an app-level token with connections:write scope
    export SLACK_APP_TOKEN=xapp-1-...
    # Install the app into your workspace to grab this token
    export SLACK_BOT_TOKEN=xoxb-...
    # Visit https://platform.openai.com/account/api-keys for this token
    export OPENAI_API_KEY=sk-...
    (snip)
    python -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    python main.py
    https://github.com/seratch/ChatGPT-in-Slack/blob/main/README.md

    View Slide

  8. Amazon ECS on AWS Fargate等 (Docker)
    FROM python:3.11.4-slim-buster as builder
    COPY requirements.txt /build/
    WORKDIR /build/
    RUN pip install -U pip && pip install -r requirements.txt
    FROM python:3.11.4-slim-buster as app
    WORKDIR /app/
    COPY *.py /app/
    RUN mkdir /app/app/
    COPY app/*.py /app/app/
    COPY --from=builder /usr/local/bin/ /usr/local/bin/
    COPY --from=builder /usr/local/lib/ /usr/local/lib/
    ENTRYPOINT python main.py
    https://github.com/seratch/ChatGPT-in-Slack/blob/main/Dockerfile

    View Slide

  9. AWS Lambda + Amazon API Gateway
    (Serverless Framework)
    frameworkVersion: '3'
    service: slack-chat-gpt-bot
    provider:
    name: aws
    runtime: python3.9
    region: us-east-1
    ...
    https://github.com/seratch/ChatGPT-in-Slack/blob/main/serverless.yml

    View Slide

  10. おすすめ記事
    ChatGPTとSlack上で会話するアプリを10分で構築しよう(前編:ローカル環境)
    https://qiita.com/rubita/items/f143f199e20b0310980a
    ChatGPTとSlack上で会話するアプリを10分で構築しよう(後編:AWS Lambda)
    https://qiita.com/rubita/items/f8d08552f98cc3b25a1a

    View Slide

  11. ぼくの提案で追加された機能

    View Slide

  12. Azure OpenAIの利用
    # To use Azure OpenAI, set the following optional environment variables according to your environment
    # default: None
    export OPENAI_API_TYPE=azure
    # default: https://api.openai.com/v1
    export OPENAI_API_BASE=https://YOUR_RESOURCE_NAME.openai.azure.com
    # default: None
    export OPENAI_API_VERSION=2023-05-15
    # default: None
    export OPENAI_DEPLOYMENT_ID=YOUR-DEPLOYMENT-ID
    https://github.com/seratch/ChatGPT-in-Slack/blob/main/README.md

    View Slide

  13. Function Calling(実験的機能)
    # Experimental: You can try out the Function Calling feature (default: None)
    export OPENAI_FUNCTION_CALL_MODULE_NAME=tests.function_call_example
    https://github.com/seratch/ChatGPT-in-Slack/blob/main/README.md

    View Slide

  14. Function Callingの利用例

    View Slide

  15. DALL·E 2を使った画像作成

    View Slide

  16. qrcodeライブラリを使ったQRコード作成

    View Slide

  17. Amazon Pollyを使った音声読み上げ

    View Slide

  18. まとめ

    View Slide

  19. 運用も開発も楽しいので是非お試しを!
    https://github.com/seratch/ChatGPT-in-Slack

    View Slide