使用するOSS
- 言語:Python
ゴール
AWS LambdaでChatGPTと連続的な会話を実現するSlackアプリを構築する
ローカルで動かす
まずはREADMEに従ってローカルで動かしてみましょう
Slack API
Slack APIで新しいAppを作成
- Slack ApiでCreate New Appをクリックします
Appで必要な設定を行います
OpenAI API
- OpenAI API keyを作成し、控えます
https://platform.openai.com/account/api-keys
Appを立ち上げます
- READMEに記載の通り、実行します
- 環境変数は前段階で控えたものに置き換えてください
- OPENAI_MODELは
gpt-3.5-turbo
としてください
# 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-...
# Optional: gpt-3.5-turbo and gpt-4 are currently supported (default: gpt-3.5-turbo)
export OPENAI_MODEL=gpt-3.5-turbo
# Optional: You can adjust the timeout seconds for OpenAI calls (default: 30)
export OPENAI_TIMEOUT_SECONDS=60
# Optional: You can include priming instructions for ChatGPT to fine tune the bot purpose
export OPENAI_SYSTEM_TEXT="You proofread text. When you receive a message, you will check
for mistakes and make suggestion to improve the language of the given text"
# Optional: When the string is "true", this app translates ChatGPT prompts into a user's preferred language (default: true)
export USE_SLACK_LANGUAGE=true
# Optional: Adjust the app's logging level (default: DEBUG)
export SLACK_APP_LOG_LEVEL=INFO
# Optional: When the string is "true", translate between OpenAI markdown and Slack mrkdwn format (default: false)
export TRANSLATE_MARKDOWN=true
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python main.py
Slackで会話してみましょう
後編
次回はこのアプリをAWS Lambdaに構築します