OmniGPT Server is a robust backend service designed to facilitate interactions with multiple Large Language Model (LLM) APIs. The server enables the creation, management, and querying of user data, conversations, and API keys, while ensuring seamless communication with LLM providers such as OpenAI and Anthropic. The service is built using Node.js, Express, and various supporting libraries to ensure scalability, security, and ease of use.
- Features
- Project Structure
- Installation
- Configuration
- API Endpoints
- Validation and Error Handling
- Logging
- Contributing
- License
- User Management: Create, update, delete, and manage users.
- Conversation Management: Handle conversations between users and LLMs, including message history.
- API Provider Management: Add, update, and delete API providers, allowing integration with multiple LLMs.
- WebSocket Support: Real-time communication and logging via WebSocket.
- Input Validation: Robust validation using
express-validatorto ensure the integrity of data. - Logging: Comprehensive logging of all operations and requests for easy debugging and monitoring.
├── README.md
├── package.json
├── server
│ ├── server.js # Server entry point
│ ├── messageBroker.js # WebSocket message broker
├── controllers # Express controllers
│ ├── apiProviderController.js
│ ├── conversationController.js
│ ├── userController.js
│ ├── authController.js
│ ├── messageController.js
│ ├── userApiProviderController.js
├── routes # Express routes
│ ├── authRoutes.js
│ ├── userApiProviderRoutes.js
│ ├── messageRoutes.js
│ ├── userRoutes.js
│ ├── apiProviderRoutes.js
│ ├── conversationRoutes.js
├── services # Business logic and service functions
│ ├── userService.js
│ ├── apiKeyService.js
│ ├── userApiProviderService.js
│ ├── conversationService.js
│ ├── messageService.js
│ ├── apiProviderService.js
├── utils # Utility functions
│ ├── fileUtils.js
│ ├── logger.js
├── data # JSON data storage
│ ├── users.json
│ ├── conversations.json
│ ├── messages.json
│ ├── api_providers.json
│ ├── user_api_providers.json
│ ├── apiKeys.json
- Node.js (v14.x or higher)
- npm (v6.x or higher)
- Git (for cloning the repository)
-
Clone the repository:
git clone https://github.com/your-username/omnigpt-server.git cd omnigpt-server -
Install dependencies:
npm install -
Start the server:
npm start -
The server should now be running on
http://localhost:3001.
You can configure the server using environment variables. Create a .env file in the root directory of the project:
env
PORT=3001
NODE_ENV=development
The project stores data in JSON files located in the data/ directory. These files include users.json, conversations.json, messages.json, api_providers.json, user_api_providers.json, and apiKeys.json. Ensure that these files are writable by the server process.
- POST /api/login
- Logs in a user with their username and password.
- Request body:
{ "username": "yourUsername", "password": "yourPassword" }
-
POST /api/users
- Creates a new user.
- Request body:
{ "username": "newUser", "email": "user@example.com", "password": "securePassword" }
-
GET /api/users
- Fetches all users.
-
GET /api/users/
- Fetches a user by ID.
-
PUT /api/users/
- Updates user details by ID.
-
DELETE /api/users/
- Deletes a user by ID.
-
GET /api/conversations
- Fetches all conversations or conversations by a specific user using
?userId=USER_ID.
- Fetches all conversations or conversations by a specific user using
-
POST /api/conversations
- Creates a new conversation.
- Request body:
{ "title": "New Conversation", "userId": "USER_ID" }
-
GET /api/conversations/
- Fetches a conversation by ID.
-
PUT /api/conversations/
- Updates a conversation's title by ID.
-
DELETE /api/conversations/
- Deletes a conversation by ID.
-
POST /api/send-message
- Sends a message to an LLM API and stores the conversation.
- Request body:
{ "conversationId": "CONVO_ID", "userInput": "Hello", "provider": "openai", "model": "gpt-4", "userId": "USER_ID" }
-
GET /api/messages/
- Fetches all messages for a specific conversation.
-
POST /api/providers
- Adds a new API provider.
- Request body:
{ "name": "ProviderName", "models": ["model1", "model2"] }
-
GET /api/providers
- Fetches all API providers.
-
GET /api/providers/
- Fetches an API provider by ID.
-
PUT /api/providers/
- Updates the models for an API provider by ID.
-
DELETE /api/providers/
- Deletes an API provider by ID.
-
POST /api/user-api-providers
- Associates a user with an API provider.
- Request body:
{ "userId": "USER_ID", "providerId": "PROVIDER_ID", "apiKey": "API_KEY" }
-
GET /api/user-api-providers
- Fetches all user API providers.
-
GET /api/user-api-providers/
- Fetches a user API provider by ID.
-
DELETE /api/user-api-providers/
- Deletes a user API provider by ID.
- All user inputs are validated using
express-validatorto ensure data integrity. - Comprehensive error handling is implemented across all services, with detailed logs stored in the
app.logfile.
- The server uses the
winstonlibrary for logging. Logs are output to both the console and a file (data/app.log). - Log entries include timestamps, log levels, filenames, and detailed metadata for easy debugging.
Contributions are welcome! Please fork the repository, create a new branch, and submit a pull request. Ensure that your code adheres to the project's coding standards and is well-documented.
- Fork the repository.
- Create a new branch:
git checkout -b feature-branch-name. - Make your changes.
- Commit your changes:
git commit -m 'Add new feature'. - Push to the branch:
git push origin feature-branch-name. - Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.