Skip to content

Commit 15e3fa7

Browse files
authored
Merge pull request #30 from jasonacox/v0.16.3
OpenAI Image Generation Support
2 parents 4201419 + 291d948 commit 15e3fa7

File tree

11 files changed

+1145
-148
lines changed

11 files changed

+1145
-148
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,4 @@ chatbot/d
182182
images/output.png
183183
agents/moviebot.db
184184
agents/message.txt
185+
chatbot/localtest.sh

chatbot/IMAGE_CONFIG.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# TinyLLM Chatbot Image Generation Configuration Examples
2+
3+
## SwarmUI Configuration (Default)
4+
5+
```bash
6+
# Use SwarmUI for image generation (default)
7+
export IMAGE_PROVIDER="swarmui"
8+
export SWARMUI="http://localhost:7801"
9+
export IMAGE_MODEL="OfficialStableDiffusion/sd_xl_base_1.0"
10+
export IMAGE_WIDTH=1024
11+
export IMAGE_HEIGHT=1024
12+
export IMAGE_CFGSCALE=7.5
13+
export IMAGE_STEPS=20
14+
export IMAGE_SEED=-1
15+
export IMAGE_TIMEOUT=300
16+
```
17+
18+
## OpenAI Configuration
19+
20+
```bash
21+
# Use OpenAI for image generation
22+
export IMAGE_PROVIDER="openai"
23+
export OPENAI_API_KEY="your-openai-api-key-here"
24+
export OPENAI_API_BASE="https://api.openai.com/v1" # Optional, defaults to OpenAI
25+
export OPENAI_IMAGE_MODEL="dall-e-3" # or "dall-e-2"
26+
export OPENAI_IMAGE_SIZE="1024x1024" # Valid sizes depend on model
27+
export OPENAI_IMAGE_QUALITY="standard" # or "hd" (DALL-E 3 only)
28+
export OPENAI_IMAGE_STYLE="vivid" # or "natural" (DALL-E 3 only)
29+
export IMAGE_TIMEOUT=300
30+
```
31+
32+
## Valid Image Sizes by Model
33+
34+
### DALL-E 2
35+
- 256x256
36+
- 512x512
37+
- 1024x1024
38+
39+
### DALL-E 3
40+
- 1024x1024 (square)
41+
- 1792x1024 (landscape)
42+
- 1024x1792 (portrait)
43+
44+
## Docker Compose Example
45+
46+
```yaml
47+
version: '3.8'
48+
services:
49+
chatbot-swarmui:
50+
image: jasonacox/chatbot:latest
51+
ports:
52+
- "5000:5000"
53+
environment:
54+
- IMAGE_PROVIDER=swarmui
55+
- SWARMUI=http://swarmui:7801
56+
- IMAGE_MODEL=OfficialStableDiffusion/sd_xl_base_1.0
57+
depends_on:
58+
- swarmui
59+
60+
chatbot-openai:
61+
image: jasonacox/chatbot:latest
62+
ports:
63+
- "5001:5000"
64+
environment:
65+
- IMAGE_PROVIDER=openai
66+
- OPENAI_API_KEY=${OPENAI_API_KEY}
67+
- OPENAI_IMAGE_MODEL=dall-e-3
68+
- OPENAI_IMAGE_SIZE=1024x1024
69+
- OPENAI_IMAGE_QUALITY=hd
70+
```
71+
72+
## Switching Between Providers
73+
74+
You can switch between providers by changing the `IMAGE_PROVIDER` environment variable:
75+
76+
- Set to `"swarmui"` for local SwarmUI image generation
77+
- Set to `"openai"` for OpenAI DALL-E image generation
78+
79+
The chatbot will automatically use the appropriate configuration and test the connection on startup.
80+
81+
## Notes
82+
83+
- OpenAI image generation requires a valid API key and may incur costs
84+
- SwarmUI requires a local installation and GPU resources
85+
- The chatbot will gracefully fall back to text-only mode if image generation is unavailable
86+
- You can check the current image provider status at `/stats` endpoint

chatbot/README.md

Lines changed: 78 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,49 @@ The intent of this project is to build and interact with a locally hosted LLM us
88

99
Below are steps to get the Chatbot and Document Manager running.
1010

11+
## Quick Start
12+
13+
The fastest way to get started is using Docker Compose with LiteLLM:
14+
15+
```bash
16+
# Clone the repository
17+
git clone https://github.com/jasonacox/TinyLLM.git
18+
cd TinyLLM/chatbot/litellm
19+
20+
# Edit the configuration files for your setup
21+
nano compose.yaml # Configure your models and API keys
22+
nano config.yaml # Set up LLM providers (OpenAI, local models, etc.)
23+
24+
# Launch the complete stack
25+
docker compose up -d
26+
```
27+
28+
This will start:
29+
- **Chatbot** at http://localhost:5000
30+
- **LiteLLM Dashboard** at http://localhost:4000/ui
31+
- **PostgreSQL** database for usage tracking
32+
- **SearXNG** search engine at http://localhost:8080
33+
34+
### Alternative: Docker Only
35+
36+
If you prefer to run just the chatbot with a local LLM:
37+
38+
```bash
39+
# Create the configuration directory
40+
mkdir -p .tinyllm
41+
42+
# Run with your local LLM endpoint
43+
docker run -d \
44+
-p 5000:5000 \
45+
-e OPENAI_API_BASE="http://localhost:8000/v1" \
46+
-e OPENAI_API_KEY="your-api-key" \
47+
-v $PWD/.tinyllm:/app/.tinyllm \
48+
--name chatbot \
49+
jasonacox/chatbot
50+
```
51+
52+
Visit http://localhost:5000 to start chatting!
53+
1154
## Chatbot
1255

1356
The Chatbot can be launched as a Docker container or via command line.
@@ -42,12 +85,17 @@ Below are the main environment variables you can set to configure the TinyLLM Ch
4285
| `PROMPT_RO` | false | Enable read-only prompts |
4386
| `SEARXNG` | http://localhost:8080 | SearxNG URL for web search |
4487
| `WEB_SEARCH` | false | Enable web search for all queries |
88+
| `IMAGE_PROVIDER` | swarmui | Image generation provider (swarmui or openai) |
4589
| `SWARMUI` | http://localhost:7801 | SwarmUI host URL for image generation |
46-
| `IMAGE_MODEL` | OfficialStableDiffusion/sd_xl_base_1.0 | Image model to use |
47-
| `IMAGE_CFGSCALE` | 7.5 | CFG scale for image generation |
48-
| `IMAGE_STEPS` | 20 | Steps for image generation |
49-
| `IMAGE_SEED` | -1 | Seed for image generation |
90+
| `IMAGE_MODEL` | OfficialStableDiffusion/sd_xl_base_1.0 | SwarmUI image model to use |
91+
| `IMAGE_CFGSCALE` | 7.5 | CFG scale for SwarmUI image generation |
92+
| `IMAGE_STEPS` | 20 | Steps for SwarmUI image generation |
93+
| `IMAGE_SEED` | -1 | Seed for SwarmUI image generation |
5094
| `IMAGE_TIMEOUT` | 300 | Timeout for image generation (seconds) |
95+
| `OPENAI_IMAGE_MODEL` | dall-e-3 | OpenAI image model (dall-e-2 or dall-e-3) |
96+
| `OPENAI_IMAGE_SIZE` | 1024x1024 | OpenAI image size |
97+
| `OPENAI_IMAGE_QUALITY` | standard | OpenAI image quality (standard or hd) |
98+
| `OPENAI_IMAGE_STYLE` | vivid | OpenAI image style (vivid or natural) |
5199
| `IMAGE_WIDTH` | 1024 | Image width |
52100
| `IMAGE_HEIGHT` | 1024 | Image height |
53101
| `REPEAT_WINDOW` | 200 | Window size for repetition detection |
@@ -206,10 +254,36 @@ Some RAG (Retrieval Augmented Generation) features including:
206254
/model [LLM_name] # Display or select LLM model to use (dialogue popup)
207255
/search [opt:number] [prompt] # Search the web to help answer the prompt
208256
/intent [on|off] # Activate intent router to automatically run above functions
257+
/image [prompt] # Generate an image based on the prompt
209258
```
210259

211260
See the [rag](../rag/) for more details about RAG.
212261

262+
### Image Generation
263+
264+
The chatbot supports image generation through two providers:
265+
266+
1. **SwarmUI** (default) - Local image generation using Stable Diffusion models
267+
2. **OpenAI** - Cloud-based image generation using DALL-E models
268+
269+
#### SwarmUI Configuration
270+
271+
```bash
272+
export IMAGE_PROVIDER="swarmui"
273+
export SWARMUI="http://localhost:7801"
274+
export IMAGE_MODEL="OfficialStableDiffusion/sd_xl_base_1.0"
275+
```
276+
277+
#### OpenAI Configuration
278+
279+
```bash
280+
export IMAGE_PROVIDER="openai"
281+
export OPENAI_API_KEY="your-openai-api-key"
282+
export OPENAI_IMAGE_MODEL="dall-e-3"
283+
```
284+
285+
See [IMAGE_CONFIG.md](IMAGE_CONFIG.md) for complete configuration options.
286+
213287
### Example Session
214288

215289
The examples below use a Llama 2 7B model served up with the OpenAI API compatible [llmserver](https://github.com/jasonacox/TinyLLM/tree/main/llmserver) on an Intel i5 system with an Nvidia GeForce GTX 1060 GPU.

0 commit comments

Comments
 (0)