CoAI.Dev Documentation

repository·main·Indexed 27 days ago

https://github.com/coaidev/coai

A comprehensive AIGC business solution combining a chat UI with a backend for model management, API proxying, and multi-tenant billing. It features an OpenAI-compatible API proxy, administrative tools for user and quota management, and deployment options via Docker, Zeabur, BTPanel, and AlibabaCloud ComputeNest.

Tokens
9K
Snippets
24
Records
73
Agent score
94%

What's inside CoAI.Dev

  1. Overview of CoAI.Dev

    main
    CoAI.Dev is a next-generation AIGC (AI Generated Content) one-stop business solution. It combines the user-facing capabilities of Next Web with the powerful backend management and API distribution of One API. It is designed for developers and businesses to deploy a full-featured AI chat interface with advanced backend management, billing, and model proxying.
  2. Overview of CoAI.Dev features

    main

    CoAI.Dev is an all-in-one AIGC commercial solution that combines the capabilities of Next Web and One API.

    Key features include:

    • Extensive Model Support: Compatible with OpenAI, Anthropic, Gemini, Midjourney, and many others, including support for private LLMs.
    • Advanced UI/UX: Responsive design (PC/Pad/Mobile) using Shadcn UI and Tremor Charts, with light/dark mode and custom color support.
    • Rich Markdown: Supports LaTeX, Mermaid diagrams, tables, code highlighting, and progress bars.
    • Image Generation: Supports OpenAI DALL-E, Midjourney (including U/V/R actions), and Stable Diffusion.
    • File Parsing & OCR: Out-of-the-box support for PDF, Docx, Pptx, Excel, and images. Integrates with S3, R2, and MinIO for cloud storage.
    • Web Search: Integrated with SearXNG for searching via Google, Bing, DuckDuckGo, etc.
    • Commercial Features: Supports subscription and elastic billing (per token or per request), gift codes, exchange codes, and a comprehensive admin dashboard.
    • Channel Management: Enterprise-grade management including priority settings, weight-based load balancing, user grouping, automatic retries, and model redirection.
    • OpenAI Compatible Proxy: Acts as a proxy for various models using the OpenAI API standard.
  3. Deploy CoAI.Dev via Docker Compose

    main

    Docker Compose is the recommended installation method. Depending on your requirements, use one of the following commands:

    Standard Installation (Recommended):

    docker-compose up -d

    Stable Version: To use the stable version instead of the latest:

    docker-compose -f docker-compose.stable.yaml up -d

    Automatic Updates with Watchtower: To use Watchtower for automatic image updates:

    docker-compose -f docker-compose.watch.yaml up -d
  4. Compile and Install from Source

    main

    To build CoAI.Dev manually, you need pnpm (for the frontend) and go (for the backend). The default port after successful compilation is 8094.

    Build Steps:

    1. Clone the repository and enter the chatnio directory.
    2. Build the frontend in the app directory using pnpm.
    3. Build the backend using go.
    4. Run the binary (e.g., using nohup for background execution).

    Note: Configuration settings in ~/config/config.yaml can be overridden using environment variables (e.g., MYSQL_HOST overrides mysql.host).

    git clone https://github.com/coaidev/coai.git
    cd chatnio
    
    cd app
    npm install -g pnpm
    pnpm install
    pnpm build
    
    cd ..
    go build -o chatnio
    
    # Run in background
    nohup ./chatnio > output.log &
  5. Install via Docker (Lightweight Runtime)

    main

    Use this method if you want to use external MySQL or RDS services. After running, the service is accessible at http://localhost:8094.

    Important Configuration Notes:

    • Use programzmh/chatnio:stable instead of programzmh/chatnio:latest for the stable version.
    • --network host allows the container to use the host's network.
    • SECRET: A random string used as the JWT secret key. Change this for security.
    • SERVE_STATIC: Set to true to enable static file serving.
    • Volume mounts: ~/config for config, ~/logs for logs, and ~/storage for generated files.

    Environment Variables:

    • MYSQL_HOST, MYSQL_PORT, MYSQL_DB, MYSQL_USER, MYSQL_PASSWORD
    • REDIS_HOST, REDIS_PORT
    • SECRET (JWT secret)
    • SERVE_STATIC (boolean)

    Manual Update Procedure:

    docker stop chatnio
    docker rm chatnio
    docker pull programzmh/chatnio:latest
    docker run -d --name chatnio \
       --network host \
       -v ~/config:/config \
       -v ~/logs:/logs \
       -v ~/storage:/storage \
       -e MYSQL_HOST=localhost \
       -e MYSQL_PORT=3306 \
       -e MYSQL_DB=chatnio \
       -e MYSQL_USER=root \
       -e MYSQL_PASSWORD=chatnio123456 \
       -e REDIS_HOST=localhost \
       -e REDIS_PORT=6379 \
       -e SECRET=secret \
       -e SERVE_STATIC=true \
       programzmh/chatnio:latest
  6. Install via Docker Compose (Recommended)

    main

    The recommended way to run CoAI.Dev is using Docker Compose. After a successful run, the service is accessible at http://localhost:8000.

    Deployment Commands:

    • Standard deployment: docker-compose up -d
    • Stable version: docker-compose -f docker-compose.stable.yaml up -d
    • Automatic updates via Watchtower: docker-compose -f docker-compose.watch.yaml up -d

    Manual Update Procedure: If you are not using Watchtower, update the services using:

    docker-compose down 
    docker-compose pull
    docker-compose up -d

    Data Persistence (Mount Directories):

    • MySQL: ~/db
    • Redis: ~/redis
    • Configuration: ~/config
    git clone --depth=1 --branch=main --single-branch https://github.com/coaidev/coai.git
    cd chatnio
    docker-compose up -d
  7. Deploy via Zeabur (One-Click)

    main

    Deploy CoAI.Dev to Zeabur with a single click.

    1. Click the Deploy button on the Zeabur template page and enter your desired domain name.
    2. Wait for deployment to complete.
    3. Access the domain. Use the default administrator credentials to log in and follow the prompts to change your password.

    Default Credentials:

    • Username: root
    • Password: chatnio123456
    https://zeabur.com/templates/M86XJI
  8. Compile and Install CoAI from Source

    main

    To build CoAI manually, you need pnpm and go installed on your system. The default port after successful deployment is 8094 (http://localhost:8094).

    Build Steps

    git clone https://github.com/coaidev/coai.git
    cd chatnio
    
    cd app
    npm install -g pnpm
    pnpm install
    pnpm build
    
    cd ..
    go build -o chatnio

    Running the Application

    You can run the binary using nohup to keep it running in the background, or use a service manager like systemd:

    nohup ./chatnio > output.log &

    Configuration

    Configuration is managed via ~/config/config.yaml. You can override configuration items using environment variables. For example, the MYSQL_HOST environment variable will override the mysql.host configuration key.

    git clone https://github.com/coaidev/coai.git
    cd chatnio
    
    cd app
    npm install -g pnpm
    pnpm install
    pnpm build
    
    cd ..
    go build -o chatnio
    
    nohup ./chatnio > output.log &
  9. Deploy CoAI via Docker Compose (Recommended)

    main

    The recommended way to deploy CoAI is using Docker Compose. By default, the service will be accessible at http://localhost:8000.

    Deployment Commands

    To run the latest version:

    git clone --depth=1 --branch=main --single-branch https://github.com/coaidev/coai.git
    cd chatnio
    docker-compose up -d

    Version Variants

    • Stable Version: Use docker-compose -f docker-compose.stable.yaml up -d.
    • Automatic Updates: Use docker-compose -f docker-compose.watch.yaml up -d to enable Watchtower for automatic updates.

    Manual Updates

    If you are not using the Watchtower configuration, update manually with:

    docker-compose down
    docker-compose pull
    docker-compose up -d

    Data Persistence

    • MySQL database: ~/db
    • Redis database: ~/redis
    • Configuration files: ~/config
  10. Use Model Mapping for Channels

    main

    Model mapping allows you to redirect user requests for one model name to a different model name supported by your upstream provider.

    Syntax: [from]>[to] (one mapping per line).

    • from: The model name requested by the user.
    • to: The actual model name sent to the upstream provider.

    Examples:

    • gpt-4-all>gpt-4: When a user requests gpt-4-all, the backend sends a request for gpt-4 to the upstream.
    • !gpt-4-all>gpt-4: Adding a ! prefix prevents the channel from being used for the original gpt-4 requests, making it exclusive to the mapped model.
    gpt-4-all>gpt-4
    !gpt-4-all>gpt-4