ChatService is a Golang project that provides an interactive chat service based on ChatGPT using Open AI's API. All user conversations are stored and managed in a MySQL database, allowing for easy data analysis and monitoring. The architecture follows clean architecture principles, separating the layers for easy maintenance and evolution. The service can be accessed through HTTP or gRPC (stream), and Docker is used for easy installation and execution.
Documentation for the ChatService microservice can be accessed through Postman at https://www.postman.com/blue-rocket-958887/workspace/chatservice
Go 1.20
https://go.dev/dl/
Docker
https://docs.docker.com/get-docker/
sqlc
sudo snap install sqlc
migrate to Go
curl -s https://packagecloud.io/install/repositories/golang-migrate/migrate/script.deb.sh | sudo bash
sudo apt-get update
sudo apt-get install migrate
protoc
https://grpc.io/docs/protoc-installation/
Make a copy of the env.example
file named .env
inside the chatservice
folder. Enter your OpenAI API Key in OPENAI_API_KEY
inside the .env
file. You can get an OpenAI API Key by clicking here.
# Clone this repository
git clone git@github.com:andre-ols/chatservice.git
# Access the project folder
cd chatservice
# Copy the env.example file to .env
cp env.example .env
docker compose up -d
If you choose to run the chatservice microservice using Docker, make sure to change the value of DB_HOST to
DB_HOST=mysql
inside your.env
file
go run cmd/chatservice/main.go
If you choose to run the chatservice microservice locally, make sure to change the value of DB_HOST to
DB_HOST=localhost
inside your.env
file
On the first run it will be necessary to apply the migrate
to create the tables in the MySQL database, through the Makefile
.
make migrate
When doing
make migrate
make sure that the MySQL connection string inside theMakefile
points to mysql:3306 when the chatservice is running in Docker, or localhost:3306 when the chatservice is running locally.
On Windows, use the Ubuntu terminal with WSL 2 to run the commands.
For more details, see Full Cycle's WSL2 + Docker Quick Start.
This project is under the license MIT.
Made with ❤️ by André Oliveira!