This project simplifies the development of AI Agents by managing chat sessions. Chat-Backend, along with its peer services, provides chat summaries, file handling, and retrieval of specific numbers of chats from previous sessions to AI-Agents. It automatically manages chat responses, allowing developers to focus on implementing AI Agents rather than managing the infrastructure.
-
we need all of these services to make system work
-
Clone the repository:
git clone https://github.com/AI-at-Work/Chat-Backend cd Chat-Backend -
Copy the
.env.sampleto.envand configure the environment variables:cp .env.sample .env
Edit the
.envfile to set your specific configurations and add openai api key. -
Start the service:
make && docker compose up -d --build -
Create a user in the database and note down the
user_idfor further use:insert into user_data(username, models, balance) VALUES ('Test User', array[4,5,8], 1);
4and5represent that user have access toGPT4Turbo,GPT4Turbo09andllama3.1:8bmodels. balance is in dollar. -
Start
Sync-BackendandChat-AIservice by following steps mention in respective repositories. -
Restart the service:
docker-compose down && docker-compose up -d -
Start
Chat-UIservice for the existing UI by following steps mention in respective repository.
Key configuration options in the .env file:
SERVER_HOSTandSERVER_PORT: Host and port for the Chat-Backend serverDB_*: PostgreSQL database configurationsREDIS_*: Redis configurationsAI_SERVER_HOSTandAI_SERVER_PORT: AI service gRPC server detailsMAX_FILE_SIZE: Maximum allowed file upload size in MBMAX_CHAT_HISTORY_CONTEXT: Number of previous chat messages to include in context
Refer to the .env.sample file for a complete list of configuration options.
GPTTurbo125 = 0
GPTTurbo = 1
GPTTurbo1106 = 2
GPTTurboInstruct = 3
GPT4Turbo = 4
GPT4Turbo09 = 5
GPT4 = 6
GPT40613 = 7
llama3.1:8b = 8
The Chat-Backend uses gRPC to communicate with the AI Agent. The protocol is defined in proto/ai_service.proto.
Key message types:
Request: Contains user chat information, including user ID, session ID, chat message, model name, etc.Response: Contains the AI's response text and timestamp.
This documentation provides an overview of the WebSocket request handlers defined in the provided code. Each function generates a request to be sent via WebSocket for various operations related to user details, sessions, and chat messages. Below is the detailed explanation of each function and the corresponding message types.
The following constants represent the different message types used in the WebSocket requests:
MessageCodeUserDetails: 0MessageCodeListSessions: 1MessageCodeChatsBySessionId: 2MessageCodeChatMessage: 3MessageCodeSessionDelete: 4MessageCodeGetAIModels: 5
Generates a request to fetch user details.
user_id(String): The ID of the user.
{
type: MessageCodeUserDetails,
data: {
user_id: (String),
},
}{
"user_id": "String",
"username": "String"
}Generates a request to fetch the list of user sessions.
user_id(String): The ID of the user.
{
type: MessageCodeListSessions,
data: {
user_id: (String),
},
}{
"user_id": "String",
"session_info": [{
"session_id": "String",
"session_name": "String"
}]
}Generates a request to fetch chats by session ID.
user_id(String): The ID of the user.session_id(String): The ID of the session.
{
type: MessageCodeChatsBySessionId,
data: {
user_id: (String),
session_id: (String),
},
}{
"user_id": "String",
"session_id": "String",
"chat": "String"
}Generates a request to send a chat message in a specific session.
user_id(String): The ID of the user.session_id(String): The ID of the session.model_id(Int): The ID of the AI model.message(String): The chat message.session_prompt(String): The session prompt.file_name(String): The name of the file (optional).
{
type: MessageCodeChatMessage,
data: {
user_id: (String),
session_id: (String),
model_id: (Int),
message: (String),
session_prompt: (String),
file_name: (String),
},
}{
"user_id": "String",
"session_id": "String",
"session_name": "String",
"message": "String"
}Generates a request to delete a user session.
user_id(String): The ID of the user.session_id(String): The ID of the session.
{
type: MessageCodeSessionDelete,
data: {
user_id: userId,
session_id: sessionId,
},
}{
"user_id": "String"
}Generates a request to fetch the list of AI models available.
user_id(String): The ID of the user.
{
type: MessageCodeGetAIModels,
data: {
user_id: userId,
},
}{
"models": ["String"]
}We welcome contributions to the Chat-Backend project! Here's how you can contribute:
- Fork the repository
- Create a new branch (
git checkout -b feature/AmazingFeature) - Make your changes
- Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the GNU GENERAL PUBLIC LICENSE V3.
For any questions or suggestions, please open an issue in the GitHub repository.
