Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/pkoutsogiannis/aichat

A lightweight, self-hosted web interface for various AI chat providers. Written in PHP and no-dependencies modern javascript.
https://github.com/pkoutsogiannis/aichat

ai aichat anthropic chatbot chatgpt chatgpt-api claude deepseek gemini javascript ollama openai php

Last synced: 25 days ago
JSON representation

A lightweight, self-hosted web interface for various AI chat providers. Written in PHP and no-dependencies modern javascript.

Awesome Lists containing this project

README

        

# AiChat

A lightweight, self-hosted web interface for various AI chat providers including Anthropic Claude, OpenAI ChatGPT, Google Gemini, Mistral, Cohere, and more. Built with PHP and modern javascript with zero dependencies, it offers a clean, responsive interface with support for multiple AI models, file attachments, and real-time streaming.

Live demo at: https://ai.datasteam.com/aichat

## Features

### Provider Support
- **Anthropic Claude** - Including Claude 3 Opus, Sonnet, and Haiku (latest and versioned models)
- **OpenAI ChatGPT** - Including GPT-4 and variants
- **Google Gemini** - Including Gemini 2.0 Flash and 1.5 Flash
- **DeepSeek**
- **Mistral AI** - Including Mistral Large
- **Cohere** - Including Command-R Plus
- **X.AI Grok** - Including Grok Beta and Grok 2
- **Groq** - Including LLaMA 3.3 70B and Mixtral 8x7B
- **Together AI** - Including Meta LLaMA models and DeepSeek LLM
- **Local Providers**
- LM Studio
- Ollama

### Interface Features
- **Real-time Streaming** - Toggle-able streaming responses with SSE support
- **Code Highlighting** - Syntax highlighting via `prism` with copy-to-clipboard functionality
- **Theme Support**
- Light/Dark mode switching
- Multiple color themes
- **File Management**
- Upload and attach multiple files to prompts
- Support for text files and images (provider-dependent)
- PDF support for compatible providers
- 15MB file size limit
- Intelligent MIME type detection
- Base64 encoding for binary files
- **Chat Features**
- Message history with session persistence
- Token usage tracking
- Conversation reset capability
- Mobile-responsive design

## Requirements

- PHP 7.2 or higher
- Web server (Apache, Nginx, etc.)
- API keys for your chosen providers

## Installation

1. Download or clone this repository to your web server
2. Configure your web server to serve the application directory
3. Copy `lib/config.php` to your installation directory
4. Configure your API keys through either:
- Editing `lib/config.php` directly
- Using the UI's API key management

For usage instructions, please refer to the [User Guide](userguide.markdown).

## API Usage

The application provides a REST API that can be accessed using curl or any HTTP client. Here are some examples:

### Basic Text Request
```bash
curl -X POST "https://localhost/aichat/api.php" \
-H "apikey: PROVIDER-API-KEY" \
-d "provider=anthropic" \
-d "model=0" \
-d "stream=1" \
-d "reset=0" \
-d "text=add 1" \
-b "PHPSESSID=mysession"
```

### File Upload Request
```bash
curl -X POST "https://localhost/aichat/api.php" \
-H "apikey: PROVIDER-API-KEY" \s
-H "Content-Type: multipart/form-data" \
-F "provider=anthropic" \
-F "model=0" \
-F "stream=1" \
-F "reset=0" \
-F "text=analyze" \
-F "files[][email protected]" \
-b "PHPSESSID=mysession"
```

**Parameters:**
- `stream`: Set to 1 to enable streaming responses
- `reset`: Set to 1 to reset conversation history, 0 to maintain it
- `files[]`: Array of files to upload (multipart/form-data only)
- `PHPSESSID`: Cookie used to maintain conversation state.

## General Notes

- API keys entered via UI are stored in browser localStorage
- File uploads are temporary and cleared after each request
- Session data uses PHP native sessions with optional Memcache support
- Optional gzip compression for session storage
- File upload validation with MIME type checking

## Technical Guide

### Provider Implementation

1. Choose a [provider-id] string that represents your AI provider's name (e.g., 'anthropic', 'openai', 'xai'). The key must:
- Not contain spaces
- Use simple, descriptive names (e.g., 'mistral' for Mistral AI)
- Can include both uppercase and lowercase letters

2. Create a `[provider-id].php` file in `lib/providers` folder.

3. Configure the new provider in lib/config.php:
```php
"[provider-id]" => [
"name" => "Display Name",
"apikey" => "", // API key or leave empty for UI input
"endpoint" => "https://api.provider.com/v1/...",
"models" => [
"model-name-1",
"model-name-2"
],
"headers" => [ // Optional provider-specific headers
"Header-Name: Value"
],
"accumulate_tokens" => false, // Set to true for providers that accumulate tokens in responses (e.g., X.AI)
]
```

For local providers (LM Studio, Ollama) or providers that does not require authentication, set `"apikey" => "none"` to hide the API key button.

The `accumulate_tokens` parameter determines how token counts are handled:
- Set to `false` (default): Provider returns non-accumulated token counts in each response
- Set to `true`: Provider accumulates token counts across responses (e.g., X.AI Grok)

This setting ensures accurate token usage tracking in the UI's session counter.

### Session Configuration

The application supports two session storage modes:
- PHP native sessions (default)
- Memcache (for distributed systems)

Optional compression (gzdeflate) for session data can be enabled in `lib/config.php`:
```php
"compression_level" => 1, // 0-9, 0 = disabled
```

## Contributing

Contributions are welcome! Please feel free to submit Pull Requests. Areas for contribution include:
- Additional provider integrations
- New themes
- Interface improvements
- Documentation updates
- Bug fixes

## Credits

### Markdown Processing
- **markdown-it** (v13.0.1) - Markdown parser, created by Vitaly Puzrin and Alex Kocharin
- **markdown-it-footnote** (v3.0.3) - Footnote support, by Vitaly Puzrin
- **markdown-it-emoji** (v2.0.2) - Emoji support, by Alex Kocharin
- **markdown-it-task-lists** - Task list support, by Revin Guillen
- **markdown-it-sub** (v1.0.0) - Subscript support, by Vitaly Puzrin
- **markdown-it-sup** (v1.0.0) - Superscript support, by Vitaly Puzrin
- **markdown-it-deflist** (v2.1.0) - Definition list support, by Vitaly Puzrin
- **markdown-it-abbr** (v1.0.4) - Abbreviation support, by Vitaly Puzrin
- **markdown-it-container** (v3.0.0) - Container support, by Vitaly Puzrin
- **markdown-it-ins** (v3.0.1) - Insert/underline support, by Alex Kocharin
- **markdown-it-mark** (v3.0.1) - Mark/highlight support, by Vitaly Puzrin
- **markdown-it-attrs** (v4.3.1) - Attribute support, by Anton Medvedev
- **markdown-it-anchor** (v9.2.0) - Header anchor support, by Valentin Gagarin

### Syntax Highlighting
- **Prism** (v1.29.0) - Syntax highlighting with autoloader plugin, created by Lea Verou and maintained by the Prism team

### Fonts
- **Inter** - Primary UI font, designed by Rasmus Andersson
- **JetBrains Mono** - Monospace font for code blocks, designed by JetBrains

## License

This project is open source software under the Apache 2.0 license.\
Created and maintained by Periklis Koutsogiannis [email protected]