Skip to content

Commit

Permalink
Merge pull request #36 from ajcwebdev/docs
Browse files Browse the repository at this point in the history
Ollama Docker Support
  • Loading branch information
ajcwebdev authored Oct 23, 2024
2 parents b226287 + 97b705b commit f8ceb73
Show file tree
Hide file tree
Showing 22 changed files with 823 additions and 398 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ GEMINI_API_KEY=""
COHERE_API_KEY=""
MISTRAL_API_KEY=""
OCTOAI_API_KEY=""
TOGETHER_API_KEY=""
FIREWORKS_API_KEY=""

DEEPGRAM_API_KEY=""
ASSEMBLY_API_KEY=""
33 changes: 14 additions & 19 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- whisper
# - ollama
# environment:
# - OLLAMA_HOST=ollama
# - OLLAMA_PORT=11434
- ollama
environment:
- OLLAMA_HOST=ollama
networks:
- autoshownet
whisper:
Expand All @@ -29,20 +28,16 @@ services:
stdin_open: true
networks:
- autoshownet
# ollama:
# image: ollama/ollama
# command: ["ollama", "serve", "--address", "0.0.0.0"] # Listen on all interfaces
# ports:
# - "11434:11434"
# volumes:
# - ./ollama:/root/.ollama
# healthcheck:
# test: ["CMD", "curl", "-f", "http://localhost:11434/healthz"]
# interval: 10s
# timeout: 5s
# retries: 5
# networks:
# - autoshownet
ollama:
image: ollama/ollama
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_HOST=0.0.0.0
networks:
- autoshownet
networks:
autoshownet:
driver: bridge
driver: bridge
volumes:
ollama:
51 changes: 45 additions & 6 deletions docs/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --together Q
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --together QWEN_2_5_7B
```

### Groq

```bash
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq
```

Select Groq model:

```bash
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq LLAMA_3_1_70B_VERSATILE
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq LLAMA_3_1_8B_INSTANT
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq LLAMA_3_2_1B_PREVIEW
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq LLAMA_3_2_3B_PREVIEW
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --groq MIXTRAL_8X7B_32768
```

### Llama.cpp

```bash
Expand Down Expand Up @@ -334,6 +350,9 @@ npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisper me

# large-v2 model
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisper large-v2

# large-v3-turbo model
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisper large-v3-turbo
```

Run `whisper.cpp` in a Docker container with `--whisperDocker`:
Expand All @@ -342,6 +361,22 @@ Run `whisper.cpp` in a Docker container with `--whisperDocker`:
npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisperDocker base
```

### Whisper Python

Use the original [`openai/whisper`](https://github.com/openai/whisper) Python library with the newly released [`turbo`](https://github.com/openai/whisper/discussions/2363) model:

```bash
npm run as -- --file "content/audio.mp3" --whisperPython turbo
```

### Whisper Diarization

Use [`whisper-diarization`](https://github.com/MahmoudAshraf97/whisper-diarization) to provide speaker labels:

```bash
npm run as -- --file "content/audio.mp3" --whisperDiarization tiny
```

### Deepgram

Create a `.env` file and set API key as demonstrated in `.env.example` for `DEEPGRAM_API_KEY`.
Expand Down Expand Up @@ -424,25 +459,29 @@ npm run as -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --prompt tit

### Docker Compose

This will start both `whisper.cpp` and the AutoShow Commander CLI in their own Docker containers.
This will start `whisper.cpp`, Ollama, and the AutoShow Commander CLI in their own Docker containers.

```bash
npm run docker-up
```

Replace `as` with `docker` to run most other commands explained in this document.
Replace `as` with `docker` to run most other commands explained in this document. Does not support all options at this time, notably `--llama`, `--whisperPython`, and `--whisperDiarization`.

```bash
npm run docker -- --video "https://www.youtube.com/watch?v=MORMZXEaONk"
npm run docker -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisperDocker tiny
```

- Does not support all commands at this time, notably `--llama` and `--ollama`.
- Currently working on the `llama.cpp` Docker integration so the entire project can be encapsulated in one local Docker Compose file.
Currently supports Ollama's official Docker image so the entire project can be encapsulated in one local Docker Compose file:

```bash
npm run docker -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisperDocker base
npm run docker -- --video "https://www.youtube.com/watch?v=MORMZXEaONk" --whisperDocker tiny --ollama
```

To reset your Docker images and containers, run:

```bash
docker system prune -af --volumes
npm run prune
```

### Bun
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
},
"scripts": {
"setup": "bash ./scripts/setup.sh",
"setup-python": "bash ./scripts/setup-python.sh",
"autoshow": "tsx --env-file=.env --no-warnings src/autoshow.ts",
"as": "tsx --env-file=.env --no-warnings src/autoshow.ts",
"docker": "docker compose run --remove-orphans autoshow",
"docker": "docker compose run --remove-orphans --rm autoshow --whisperDocker",
"docker-up": "docker compose up --build -d --remove-orphans --no-start",
"ds": "docker compose images && docker compose ls",
"prune": "docker system prune -af --volumes && docker image prune -af && docker container prune -f && docker volume prune -af",
"v": "tsx --env-file=.env --no-warnings src/autoshow.ts --whisper large-v2 --video",
"u": "tsx --env-file=.env --no-warnings src/autoshow.ts --whisper large-v2 --urls",
"p": "tsx --env-file=.env --no-warnings src/autoshow.ts --whisper large-v2 --playlist",
Expand All @@ -34,8 +36,9 @@
"fetch-local": "tsx --env-file=.env --no-warnings packages/server/tests/fetch-local.ts",
"fetch-all": "tsx --env-file=.env --no-warnings packages/server/tests/fetch-all.ts",
"t": "npm run test-local",
"test-local": "tsx --test test/local.test.js",
"test-all": "tsx --test test/all.test.js",
"test-local": "tsx --test test/local.test.ts",
"test-docker": "tsx --test test/docker.test.ts",
"test-integrations": "tsx --test test/integrations.test.ts",
"clean": "tsx scripts/cleanContent.ts",
"bun-as": "bun --env-file=.env --no-warnings src/autoshow.ts",
"deno-as": "deno run --allow-sys --allow-read --allow-run --allow-write --allow-env src/autoshow.ts"
Expand All @@ -53,7 +56,6 @@
"commander": "12.1.0",
"fast-xml-parser": "4.5.0",
"fastify": "5.0.0",
"ffmpeg-static": "5.2.0",
"file-type": "19.5.0",
"inquirer": "12.0.0",
"node-llama-cpp": "3.1.1",
Expand All @@ -64,6 +66,7 @@
"@types/inquirer": "9.0.7",
"@types/node": "22.7.5",
"tsx": "4.19.1",
"typedoc": "^0.26.10",
"typescript": "5.6.3"
}
}
33 changes: 26 additions & 7 deletions scripts/setup-python.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
#!/bin/bash

# Clone the repository
git clone https://github.com/MahmoudAshraf97/whisper-diarization.git
# scripts/setup-python.sh

# Create and activate virtual environment
python3.12 -m venv whisper-diarization/venv
source whisper-diarization/venv/bin/activate
# Clone the repository if it doesn't exist
if [ ! -d "whisper-diarization" ]; then
echo "Cloning the whisper-diarization repository..."
git clone https://github.com/MahmoudAshraf97/whisper-diarization.git
else
echo "whisper-diarization repository already exists. Skipping clone."
fi

# Install the requirements
pip install -c whisper-diarization/constraints.txt -r whisper-diarization/requirements.txt
# Create the virtual environment if it doesn't exist
if [ ! -f "whisper-diarization/venv/bin/activate" ]; then
echo "Creating virtual environment..."
python3.12 -m venv whisper-diarization/venv
else
echo "Virtual environment already exists. Skipping creation."
fi

# Install requirements if not already installed
if [ ! -f "whisper-diarization/.requirements_installed" ]; then
echo "Installing requirements..."
source whisper-diarization/venv/bin/activate
pip install -c whisper-diarization/constraints.txt -r whisper-diarization/requirements.txt
deactivate
touch whisper-diarization/.requirements_installed
else
echo "Requirements already installed. Skipping installation."
fi

echo "Setup complete. To activate this environment in the future, run:"
echo "source whisper-diarization/venv/bin/activate"
Expand Down
25 changes: 15 additions & 10 deletions src/autoshow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* Automate processing of audio and video content from various sources.
* Supports processing YouTube videos, playlists, local files, and podcast RSS feeds.
*
* Documentation: https://github.com/ajcwebdev/autoshow#readme
* Report Issues: https://github.com/ajcwebdev/autoshow/issues
* @packageDocumentation
*/

import { Command } from 'commander'
Expand All @@ -26,7 +25,9 @@ import type { ProcessingOptions, HandlerFunction, LLMServices, TranscriptService
// Initialize the command-line interface
const program = new Command()

// Define command-line options and their descriptions
/**
* Defines the command-line interface options and descriptions.
*/
program
.name('autoshow')
.version('0.0.1')
Expand Down Expand Up @@ -57,6 +58,7 @@ program
.option('--octo [model]', 'Use Octo for processing')
.option('--fireworks [model]', 'Use Fireworks AI for processing with optional model specification')
.option('--together [model]', 'Use Together AI for processing with optional model specification')
.option('--groq [model]', 'Use Groq for processing with optional model specification')
.option('--llama [model]', 'Use Node Llama for processing with optional model specification')
.option('--ollama [model]', 'Use Ollama for processing with optional model specification')
.option('--gemini [model]', 'Use Gemini for processing with optional model specification')
Expand All @@ -78,12 +80,16 @@ Report Issues: https://github.com/ajcwebdev/autoshow/issues

/**
* Helper function to validate that only one option from a list is provided.
* @param {string[]} optionKeys - The list of option keys to check.
* @param {ProcessingOptions} options - The options object.
* @param {string} errorMessage - The prefix of the error message.
* @returns {string | undefined} - The selected option or undefined.
* @param optionKeys - The list of option keys to check.
* @param options - The options object.
* @param errorMessage - The prefix of the error message.
* @returns The selected option or undefined.
*/
function getSingleOption(optionKeys: string[], options: ProcessingOptions, errorMessage: string): string | undefined {
function getSingleOption(
optionKeys: string[],
options: ProcessingOptions,
errorMessage: string
): string | undefined {
const selectedOptions = optionKeys.filter((opt) => options[opt as keyof ProcessingOptions])
if (selectedOptions.length > 1) {
console.error(`Error: Multiple ${errorMessage} provided (${selectedOptions.join(', ')}). Please specify only one.`)
Expand All @@ -94,8 +100,7 @@ function getSingleOption(optionKeys: string[], options: ProcessingOptions, error

/**
* Main action for the program.
* @param {ProcessingOptions} options - The command-line options provided by the user.
* @returns {Promise<void>}
* @param options - The command-line options provided by the user.
*/
program.action(async (options: ProcessingOptions) => {
log(opts(`Options received at beginning of command:\n`))
Expand Down
Loading

0 comments on commit f8ceb73

Please sign in to comment.