Skip to content

Commit

Permalink
feat: harbor qr <service> - print service QR code in a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
av committed Aug 5, 2024
1 parent 98d00b6 commit 064da1e
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 21 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ harbor vllm model google/gemma-2-2b-it
harbor aphrodite model google/gemma-2-2b-it
harbor tabbyapi model google/gemma-2-2b-it-exl2
harbor mistralrs model google/gemma-2-2b-it
harbor opint model google/gemma-2-2b-it

# Convenience tools for docker setup
harbor logs llamacpp
harbor exec llamacpp ./scripts/llama-bench --help
harbor shell tabbyapi

# Tell your shell that you don't like it anymore,
# courtesy of Open Interpreter
harbor opint

# Access service CLIs without installing them
harbor hf scan-cache
harbor ollama list
Expand Down
6 changes: 6 additions & 0 deletions compose.qrgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
services:
qrgen:
build:
context: ./qrgen
dockerfile: Dockerfile

81 changes: 69 additions & 12 deletions harbor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,23 @@ show_help() {
echo " openai - Configure OpenAI API keys and URLs"
echo " vllm - Configure VLLM service"
echo " aphrodite - Configure Aphrodite service"
echo " parllama - Launch Parllama - TUI for chatting with Ollama models"
echo " tabbyapi - Configure TabbyAPI service"
echo " mistralrs - Configure mistral.rs service"
echo
echo "Huggingface CLI:"
echo " hf [dl|parse-url|token] - Run the Harbor's Huggingface CLI. Expanded with a few additional commands."
echo " hf dl - HuggingFaceModelDownloader CLI"
echo " hf parse-url - Parse file URL from Hugging Face"
echo " hf token - Get/set the Hugging Face Hub token"
echo " hf * - Anything else is passed to the official Huggingface CLI"
echo "Service CLIs:"
echo " parllama - Launch Parllama - TUI for chatting with Ollama models"
echo " plandex - Launch Plandex CLI"
echo " interpreter|opint - Launch Open Interpreter CLI"
echo " hf - Run the Harbor's Huggingface CLI. Expanded with a few additional commands."
echo " hf dl - HuggingFaceModelDownloader CLI"
echo " hf parse-url - Parse file URL from Hugging Face"
echo " hf token - Get/set the Hugging Face Hub token"
echo " hf * - Anything else is passed to the official Huggingface CLI"
echo
echo "Harbor CLI Commands:"
echo " open handle - Open a service in the default browser"
echo " url <handle> - Get the URL for a service"
echo " qr <handle> - Print a QR code for a service"
echo " config [get|set|ls] - Manage the Harbor environment configuration"
echo " config ls - All config values in ENV format"
echo " config get <field> - Get a specific config value"
Expand Down Expand Up @@ -263,7 +268,7 @@ unlink_cli() {
fi
}

get_service_url() {
get_service_port() {
# Get list of running services
services=$(docker ps --format "{{.Names}}")

Expand All @@ -275,7 +280,7 @@ get_service_url() {

# If no service name provided, default to webui
if [ -z "$1" ]; then
get_service_url "$default_open"
get_service_port "$default_open"
return 0
fi

Expand All @@ -297,10 +302,39 @@ get_service_url() {
return 1
fi

# Construct the URL
url="http://localhost:$port"
echo "$port"
}

get_service_url() {
local service_name="$1"
local port=$(get_service_port "$service_name")

echo "$url"
if [ -z "$port" ]; then
return 1
fi

echo "http://localhost:$port"
}

print_service_qr() {
local ip_address=$(get_ip)
local service_name="$1"
local port=$(get_service_port "$service_name")

if [ -z "$port" ]; then
echo "Failed to get port for service '$service_name'."
return 1
fi

if [ -z "$ip_address" ]; then
echo "Failed to get IP address."
return 1
fi

local url="http://$ip_address:$port"

echo "URL: $url"
$(compose_with_options "qrgen") run --rm qrgen "$url"
}

sys_info() {
Expand Down Expand Up @@ -710,6 +744,25 @@ get_active_services() {
docker compose ps --format "{{.Service}}" | tr '\n' ' '
}

get_ip() {
# Try ip command first
ip_cmd=$(which ip 2>/dev/null)
if [ -n "$ip_cmd" ]; then
ip route get 1 | awk '{print $7; exit}'
return
fi

# Fallback to ifconfig
ifconfig_cmd=$(which ifconfig 2>/dev/null)
if [ -n "$ifconfig_cmd" ]; then
ifconfig | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1' | head -n1
return
fi

# Last resort: hostname
hostname -I | awk '{print $1}'
}

# ========================================================================
# == Service CLIs
# ========================================================================
Expand Down Expand Up @@ -1295,6 +1348,10 @@ case "$1" in
shift
get_service_url "$@"
;;
qr)
shift
print_service_qr "$@"
;;
version|--version|-v)
shift
show_version
Expand Down
9 changes: 0 additions & 9 deletions open-webui/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,5 @@
"base_urls": [
"http://ollama:11434"
]
},
"openai": {
"api_base_urls": [
"http://vllm:8000/v1"
],
"api_keys": [
"sk-vllm"
],
"enabled": true
}
}
10 changes: 10 additions & 0 deletions qrgen/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM pkgxdev/pkgx

WORKDIR /app

RUN pkgx +node@20 npm install qrcode-terminal
COPY ./gen.ts /app/gen.ts
# Activate pkgx env
RUN pkgx gen.ts test

ENTRYPOINT [ "pkgx", "gen.ts" ]
12 changes: 12 additions & 0 deletions qrgen/gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import qrcode from 'qrcode-terminal';

// Get the URL from the command line arguments
const url = Deno.args[0];

if (!url) {
console.log('Usage: node qrgen/gen.ts <url>');
Deno.exit(1);
}

console.log('QR Code:');
qrcode.generate(url);

0 comments on commit 064da1e

Please sign in to comment.