An open API service indexing awesome lists of open source software.

https://github.com/samuel-ricardo/gpt-chat_service


https://github.com/samuel-ricardo/gpt-chat_service

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# GPT-Chat_Service





🚀 🟨 Full Cycle Learning Experience - 2023 🟨 🚀


Application developed during a Programmer Event, the Full Cycle Learning Experience promoted by @FullCycleSchool

#


|  
Overview   |   
Technologies   |   
Project   |  
Run   |  
Author   |   

#










| :artificial_satellite: About:


This project is one application of a complete Full Cycle Chat project to talk in real time with Chat-GPT, with amazing technologies like NextJS for front-end, Back-End for Front-end with NextJS, Next Auth + Keyclock for Authentication and Users management, MySQL database, GO Lang for microsservice, Docker and the power of Chat-GPT with real time reactive data and gRPC communication.














This microsservice propurse it's basically connect with Chat-GPT and handle with this data. Creating and managing Chats, receiving a message and calculating a response, all communication doesn't use REST & JSON's but gRCP that is more fast, light and economic. Using MySQL as DataBase.

>


#


- Front-End & Back-End : NextJS | [ [repositories](https://github.com/Samuel-Ricardo/NextGPT) ]
- microsservice : GO Lang | [ [repositories](https://github.com/Samuel-Ricardo/GPT-Chat_Service) ]

#



:building_construction: | Technologies and Concepts Studied:

>

>




- Go Lang
- Chat-GPT - [OpenAI]
- Docker
- gRPC
- Protobuf
- Performance
- MySQL
- Tiktoken
- Viper
- uuid
- Gotenv
- Chi
- Streams
- Real Time
- Multi Thread & Concurrency
- Scalability

> Among Others...


#


💻 | Application:

>


This API open a webserver stream connection that receive chat status and datas in real time from Front-End, connect with Chat-GPT using OpenAI Client and send a "pre-message" that gives to GPT a little context of this chat, storage the messages and tokens in order, calculate the specific used model token limit and when hit the token limit i keep in other storage the old tokens, it gives to us a best control of GPT context and avoid unforeseens and extra expenses, with this in mund, the API connect with MySQL Database to create or update the current chat and messages. GPT-Chat will read all valid tokens and analize the chat context to give a response incrementally, so the API will receive from GPT and send to Front-End piece by piece of GPT response in real time


This API is a Hybrid and support a REST connection, but i recomend to use gRPC for a better experience.

API Examples: ./api/chat.http

```bash

###

POST http://localhost:8081/chat HTTP/1.1
Content-Type: application/json
Authorization: 123456

{
"user_id": "1",
"user_message": "Olá, qual é o seu nome?"
}

###

POST http://localhost:8081/chat HTTP/1.1
Content-Type: application/json
Authorization: 123456

{
"chat_id": "a14fc851-7e95-49b5-a5b5-44479434becd",
"user_id": "1",
"user_message": "Quero saber mais sobre arquitetura de software"
}

POST http://localhost:8081/chat HTTP/1.1
Content-Type: application/json
Authorization: 123456

{
"chat_id": "a14fc851-7e95-49b5-a5b5-44479434becd",
"user_id": "1",
"user_message": "continue"
}

###
```

#


👨‍💻 | How to use


### Open your Git Terminal and clone this repository

```git
$ git clone "[email protected]:Samuel-Ricardo/GPT-Chat_Service.git"
```

### Make Pull

```git
$ git pull "[email protected]:Samuel-Ricardo/GPT-Chat_Service.git"
```


This application use `Docker` so you dont need to install and cofigurate anything other than docker on your machine.

>


Once Docker is setup, we can start the project :D

```bash

# After setup docker environment just run this commmand on root project folder:

$ docker-compose up --build # For First Time run this command

$ docker-compose up # to run project

```

```bash

#Apps Running on:

$ MySQL: http://localhost:3306

$ API - REST: http://localhost:8081
$ API - gRPC: localhost:50052

See more: ./docker-compose.yaml

```

- You need to set your own GPT data on `.env`, get a free API key from OpenAI [ [Click Here](https://auth0.openai.com/u/signup/identifier?state=hKFo2SBiSEVoVDgxV20ybk1KdE9LQUk5R2xLRmRMMTRiWTFCeqFur3VuaXZlcnNhbC1sb2dpbqN0aWTZIGdRSXBEc1k1eC1DMHVnV1Z5bDlVZmR1NEwzdENuN1Vno2NpZNkgRFJpdnNubTJNdTQyVDNLT3BxZHR3QjNOWXZpSFl6d0Q) ].



👨‍💻 | How to run the full project

First, you need to setup the GO Lang Microsservice, click on image bellow to setup it

>

Now, you can setup this NextJS App, click on image bellow to setup it

>

#




#


:octocat: | Author:

>

- Samuel Ricardo