ground0state / GPT-on-LINE

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

GPT on LINE

System

Using Chalice and AWS CDK, we will build a REST API that will serve as a webhook for LINE bot. We use AWS API Gate way, Lambda, and Dynamo DB.

Credentials

Before you can deploy an application, be sure you have credentials configured. Create an AWS IAM user named "chalice" and attouch admin (or appropriate) role. You can follow these steps to configure aws credentials:

$ mkdir ~/.aws
$ cat >> ~/.aws/config
[chalice]
aws_access_key_id=YOUR_ACCESS_KEY_HERE
aws_secret_access_key=YOUR_SECRET_ACCESS_KEY
region=YOUR_REGION (such as us-west-2, us-west-1, etc)
output=json

Install

Install Python3.9 and Node.js in advance. Install AWS-CDK, chalice.

npm install -g aws-cdk
pip install "chalice[cdkv2]"

Clone this repository. We will call the root directory of this repository $ROOT_DIRECTORY

git clone https://github.com/ground0state/GPT-on-LINE.git

Install libraries.

cd $ROOT_DIRECTORY
pip install -r requirements.txt

Environment variables

Create your OpenAI API Key. Please also set up payment methods for Billing. Create your new Messaging API channel.

Copy config file and edit to set your openAI API Key and LINE token.

cd runtime/.chalice
cp config_sample.json config.json
vi config.json

Deploy

Deploy with the following command.

cd infrastructure
cdk bootstrap --profile chalice
cdk deploy --profile chalice

If you are using a virtual environment and receive the following error, deactivate the virtual environment and re-activate it.

Traceback (most recent call last):
  File "/Users/masafumi/work/chatgpt_aws_line/infrastructure/app.py", line 3, in <module>
    from aws_cdk import core as cdk
ModuleNotFoundError: No module named 'aws_cdk'

After deployment is complete, the API Gateway URL will be displayed. Copy this and set it to the webhook URL of LINE Bot as https://YOUR_ADDRESS/callback.

Usage

Chat with bot from your line app. "EXIT" command is special command to reset chat histories. When you want to instruct, edit SYSTEM_PROMPTS in runtime/chalicelib/chatgpt_api.py.

Undeploy

Uneploy with the following command. Delete your LINE channel.

cdk destroy --profile chalice

Rederences

About

License:MIT License


Languages

Language:Python 100.0%