This repository enables you to host a powerful AI backend that supports chat and image generation using xAI/OpenAI for conversational AI and FLUX for advanced image generation.
This guide will help you set up, configure, and use the server for your projects.
-
Search Functionality
The search model used in DevEvil AI is not part of this repository. -
User Usage Limits
This repository does not impose any user usage limits, allowing users to chat or generate images without restrictions. This makes it an excellent choice for testing and development purposes. Additionally, auserId
parameter has been implemented, providing a foundation for easily adding usage limit functionality if needed in the future. -
DevEvil API Integration
DevEvil API is the brain of DevEvil AI and its models, its not included in this repository. This repository utilizes publicly available APIs for chat and image generation models.
- Introduction
- Features Not Included in This Repository
- Repository Structure
- Features
- Chat API
- Image Generation API
- FTP Integration
- Setup Guide
- How to Use OpenAI Instead of xAI
- Usage
- How to Integrate in Your Project
- Environment Variables
- License
- Support
-
server.js
The main server file. Handles API endpoints for chat and image generation. -
.env.example
Template for environment variables. Rename this file to.env
and fill in your credentials. -
package.json
Contains project metadata and dependencies for setting up the server.
-
Chat API
A conversational AI model powered by xAI or OpenAI to generate intelligent and context-aware responses. -
Image Generation API
Generate images based on user prompts using the FLUX model. -
FTP Integration
Images are securely stored on an FTP server and accessible via a URL.
- Node.js (v14 or higher)
- npm (Node Package Manager)
- An FTP server for image storage
- API keys for:
- Hugging Face
- xAI
-
Clone this repository:
git clone https://github.com/DevEvil99/DevEvil-AI.git cd DevEvil-AI
-
Install dependencies:
npm install
-
Rename
.env.example
to.env
:mv .env.example .env
-
Fill in the
.env
file with your credentials:XAI_API_KEY=your_xai_api_key HUGGING_FACE_API_KEY=your_hugging_face_api_key
Start the server:
node server.js
You should see:
Server is running on http://localhost:5500
If you'd like to switch from xAI to OpenAI for your project, follow these steps:
-
Remove the
baseURL
Property
In theconst openai
declaration, remove thebaseURL
property:const openai = new OpenAI({ apiKey: process.env.XAI_API_KEY, // Replace with your OpenAI API key });
-
Replace the API Key
- Update the
apiKey
value to use your OpenAI API key. - Alternatively, you can create a separate environment variable for the OpenAI API key, e.g.,
OPENAI_API_KEY
, and reference it in your code:const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, // Use the OpenAI API key from the environment variable });
- Update the
-
Update the Model
In thechatCompletion
section, change the model to one of OpenAI's chat models, such asgpt-4o
:const chatCompletion = await openai.chat.completions.create({ model: "gpt-4o", // Use OpenAI's chat model messages: conversationHistory, temperature: 0, max_tokens: 1024, });
-
Save and Test
Save the changes and test your server to ensure it functions correctly with OpenAI.
Endpoint:
POST http://localhost:5500/chat
Headers:
{
"Content-Type": "application/json"
}
Body:
{
"userMessage": "Hello, how are you?",
"userId": "unique_user_id"
}
Response:
{
"botResponse": "I'm great! How can I assist you today?"
}
The /chat
endpoint also supports image generation. To generate an image, include a command like "Create an image of a sunset over mountains" in the userMessage
.
Example Request:
{
"userMessage": "Create an image of a futuristic city at night.",
"userId": "unique_user_id"
}
Response:
{
"botResponse": "<img class=\"ai-image\" src=\"https://your_ftp_domain/unique_image_name.png\" alt=\"Generated Image\" />"
}
-
Include the API in Your Frontend
Usefetch
or any HTTP client (e.g., Axios) to send requests to the server.Example (JavaScript):
fetch('http://localhost:5500/chat', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ userMessage: "Help me write a function", userId: "1" }), }) .then(response => response.json()) .then(data => console.log(data.botResponse)) .catch(error => console.error('Error:', error));
-
Host the Server Online
Use a VPS or cloud platform like AWS, Google Cloud, or Heroku to deploy your server and make it publicly accessible.
Variable | Description | Example Value |
---|---|---|
XAI_API_KEY |
API key for xAI | xai-abc123 |
HUGGING_FACE_API_KEY |
API key for Hugging Face | hf_abc123 |
This project is licensed under the MIT License. Feel free to use, modify, and distribute it.
For issues or questions, join our Discord Community or open an issue in this repository.