Skip to content

DevEvil AI's server source code includes a chat and image model utilizing xAI, OpenAI and Flux.

License

Notifications You must be signed in to change notification settings

DevEvil99/DevEvil-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevEvil AI Server - Chat and Image Generation

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.


Features Not Included in This Repository

  • 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, a userId 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.


Table of Contents

  1. Introduction
  2. Features Not Included in This Repository
  3. Repository Structure
  4. Features
    • Chat API
    • Image Generation API
    • FTP Integration
  5. Setup Guide
  6. How to Use OpenAI Instead of xAI
  7. Usage
  8. How to Integrate in Your Project
  9. Environment Variables
  10. License
  11. Support

Repository Structure

  • 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.


Features

  1. Chat API
    A conversational AI model powered by xAI or OpenAI to generate intelligent and context-aware responses.

  2. Image Generation API
    Generate images based on user prompts using the FLUX model.

  3. FTP Integration
    Images are securely stored on an FTP server and accessible via a URL.


Setup Guide

1. Prerequisites

  • Node.js (v14 or higher)
  • npm (Node Package Manager)
  • An FTP server for image storage
  • API keys for:
    • Hugging Face
    • xAI

2. Installation

  1. Clone this repository:

    git clone https://github.com/DevEvil99/DevEvil-AI.git
    cd DevEvil-AI
  2. Install dependencies:

    npm install
  3. Rename .env.example to .env:

    mv .env.example .env
  4. Fill in the .env file with your credentials:

    XAI_API_KEY=your_xai_api_key
    HUGGING_FACE_API_KEY=your_hugging_face_api_key

3. Run the Server

Start the server:

node server.js

You should see:

Server is running on http://localhost:5500

How to Use OpenAI Instead of xAI

If you'd like to switch from xAI to OpenAI for your project, follow these steps:

  1. Remove the baseURL Property
    In the const openai declaration, remove the baseURL property:

    const openai = new OpenAI({
        apiKey: process.env.XAI_API_KEY, // Replace with your OpenAI API key
    });
  2. 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
      });
  3. Update the Model
    In the chatCompletion section, change the model to one of OpenAI's chat models, such as gpt-4o:

    const chatCompletion = await openai.chat.completions.create({
        model: "gpt-4o", // Use OpenAI's chat model
        messages: conversationHistory,
        temperature: 0,
        max_tokens: 1024,
    });
  4. Save and Test
    Save the changes and test your server to ensure it functions correctly with OpenAI.


Usage

Chat API

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?"
}

Image Generation API

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\" />"
}

How to Integrate in Your Project

  1. Include the API in Your Frontend
    Use fetch 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));
  2. 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.


Environment Variables

Variable Description Example Value
XAI_API_KEY API key for xAI xai-abc123
HUGGING_FACE_API_KEY API key for Hugging Face hf_abc123

License

This project is licensed under the MIT License. Feel free to use, modify, and distribute it.


Support

For issues or questions, join our Discord Community or open an issue in this repository.

About

DevEvil AI's server source code includes a chat and image model utilizing xAI, OpenAI and Flux.

Topics

Resources

License

Stars

Watchers

Forks