From 83a1552e2433dc818a6c5c2f67c98c9372396f67 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Mon, 25 Aug 2025 11:17:48 +0200 Subject: [PATCH 1/2] feat: add RHDH system-prompt --- config.yaml | 3 +++ docker-compose.yaml | 1 + 2 files changed, 4 insertions(+) diff --git a/config.yaml b/config.yaml index d4109a8..fce8b52 100644 --- a/config.yaml +++ b/config.yaml @@ -6,6 +6,9 @@ service: workers: 1 color_log: true access_log: true +customization: + # system-prompt from here: https://github.com/road-core/service/blob/9d65d15a4d1dec47e5aac15ee86fef39db975006/ols/customize/rhdh/prompts.py#L14 + system_prompt_path: lightspeed_system_prompt.txt llama_stack: use_as_library_client: false # url: http://llama-stack:8321 diff --git a/docker-compose.yaml b/docker-compose.yaml index f73e5d4..5d74535 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -41,6 +41,7 @@ services: - "8080:8080" volumes: - ./config.yaml:/app-root/lightspeed-stack.yaml:Z + - ./lightspeed_system_prompt.txt:/app-root/lightspeed_system_prompt.txt:Z depends_on: llama-stack: condition: service_healthy From e2db71b6a42aa3960e34b8b508a65264d6420099 Mon Sep 17 00:00:00 2001 From: Eloy Coto Date: Mon, 25 Aug 2025 11:39:04 +0200 Subject: [PATCH 2/2] feat: test functions cleanup Signed-off-by: Eloy Coto --- test-functions.sh | 339 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 239 insertions(+), 100 deletions(-) diff --git a/test-functions.sh b/test-functions.sh index 20d75d6..e11ac38 100644 --- a/test-functions.sh +++ b/test-functions.sh @@ -6,176 +6,315 @@ LLAMASTACK_BASE_URL="${LLAMASTACK_BASE_URL:-http://localhost:8321}" LIGHTSPEED_BASE_URL="${LIGHTSPEED_BASE_URL:-http://localhost:8080}" LLAMA_MODEL="${LLAMA_MODEL:-qwen3:4b}" +LLAMA_PROVIDER="${LLAMA_PROVIDER:-google-vertex}" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' +MAGENTA='\033[0;35m' +CYAN='\033[0;36m' NC='\033[0m' # No Color +# Debug and utility functions debug_print() { echo -e "${BLUE}[DEBUG]${NC} $1" >&2 } +info_print() { + echo -e "${GREEN}[INFO]${NC} $1" >&2 +} + +warn_print() { + echo -e "${YELLOW}[WARN]${NC} $1" >&2 +} + +error_print() { + echo -e "${RED}[ERROR]${NC} $1" >&2 +} + +# Reusable curl function with debug capabilities +api_curl() { + local method="$1" + local url="$2" + local content_type="${3:-application/json}" + local data="$4" + local extra_args="${5:-}" + + local curl_args=( + -X "$method" + -H "accept: application/json" + ) + + if [ "$content_type" != "none" ]; then + curl_args+=(-H "content-type: $content_type") + fi + + if [ -n "$data" ]; then + curl_args+=(-d "$data") + fi + + if [ "$CURL_DEBUG" = "1" ]; then + curl_args+=(-v) + debug_print "Full curl command: curl ${curl_args[*]} $extra_args $url" + else + curl_args+=(-s) + fi + + if [ -n "$extra_args" ]; then + curl_args+=($extra_args) + fi + + curl "${curl_args[@]}" "$url" +} + +# Interactive model and provider selection +select_model() { + info_print "Fetching available models..." + local models=($(llama::list_models)) + + if [ ${#models[@]} -eq 0 ]; then + error_print "No models found. Is the llama stack running?" + return 1 + fi + + echo -e "\n${CYAN}Available models:${NC}" + for i in "${!models[@]}"; do + echo " $((i+1)). ${models[$i]}" + done + + echo -n "Select a model (1-${#models[@]}) [current: $LLAMA_MODEL]: " + read -r choice + + if [ -n "$choice" ] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#models[@]} ]; then + LLAMA_MODEL="${models[$((choice-1))]}" + info_print "Model set to: $LLAMA_MODEL" + else + info_print "Keeping current model: $LLAMA_MODEL" + fi +} + +select_provider() { + info_print "Fetching available providers..." + local providers=($(llama::list_providers)) + + if [ ${#providers[@]} -eq 0 ]; then + error_print "No providers found. Is the llama stack running?" + return 1 + fi + + echo -e "\n${CYAN}Available providers:${NC}" + for i in "${!providers[@]}"; do + echo " $((i+1)). ${providers[$i]}" + done + + echo -n "Select a provider (1-${#providers[@]}) [current: $LLAMA_PROVIDER]: " + read -r choice + + if [ -n "$choice" ] && [ "$choice" -ge 1 ] && [ "$choice" -le ${#providers[@]} ]; then + LLAMA_PROVIDER="${providers[$((choice-1))]}" + info_print "Provider set to: $LLAMA_PROVIDER" + else + info_print "Keeping current provider: $LLAMA_PROVIDER" + fi +} + +configure_model() { + echo -e "\n${MAGENTA}=== Model Configuration ===${NC}" + echo "Current model: $LLAMA_MODEL" + echo "Current provider: $LLAMA_PROVIDER" + echo + echo "1. Select model interactively" + echo "2. Select provider interactively" + echo "3. Set model manually" + echo "4. Set provider manually" + echo "5. Show current configuration" + echo "6. Exit" + echo + echo -n "Choose an option (1-6): " + read -r choice + + case $choice in + 1) select_model ;; + 2) select_provider ;; + 3) + echo -n "Enter model name: " + read -r model_name + if [ -n "$model_name" ]; then + LLAMA_MODEL="$model_name" + info_print "Model set to: $LLAMA_MODEL" + fi + ;; + 4) + echo -n "Enter provider name: " + read -r provider_name + if [ -n "$provider_name" ]; then + LLAMA_PROVIDER="$provider_name" + info_print "Provider set to: $LLAMA_PROVIDER" + fi + ;; + 5) + echo -e "\n${CYAN}Current Configuration:${NC}" + echo " Model: $LLAMA_MODEL" + echo " Provider: $LLAMA_PROVIDER" + echo " Llama Stack URL: $LLAMASTACK_BASE_URL" + echo " Lightspeed URL: $LIGHTSPEED_BASE_URL" + ;; + 6) info_print "Configuration unchanged" ;; + *) warn_print "Invalid option" ;; + esac +} + llama::list_models() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/models" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/models" \ - -H 'accept: application/json' | jq -r '.data[].identifier' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/models" | jq -r '.data[].provider_resource_id' } llama::list_models_full() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/models (full)" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/models" \ - -H 'accept: application/json' | jq -r '.' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/models" | jq -r '.' } llama::list_providers() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/providers" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/providers" \ - -H 'accept: application/json' | jq -r '.data[].provider_id' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/providers" | jq -r '.data[].provider_id' } llama::list_providers_full() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/providers (full)" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/providers" \ - -H 'accept: application/json' | jq -r '.data[]' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/providers" | jq -r '.data[]' } llama::list_tools() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/tool-runtime/list-tools" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/tool-runtime/list-tools" \ - -H 'accept: application/json' | jq -r '.data[]' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/tool-runtime/list-tools" | jq -r '.data[]' } llama::list_toolgroups() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/toolgroups" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/toolgroups" \ - -H 'accept: application/json' | jq -r '.' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/toolgroups" | jq -r '.' } llama::list_agents() { debug_print "GET ${LLAMASTACK_BASE_URL}/v1/agents" - curl -X 'GET' -s \ - "${LLAMASTACK_BASE_URL}/v1/agents" \ - -H 'accept: application/json' | jq -r '.data[]' -} -llama::chat_completion() { - debug_print "POST ${LLAMASTACK_BASE_URL}/v1/inference/chat-completion" - curl -X 'POST' -s \ - "${LLAMASTACK_BASE_URL}/v1/inference/chat-completion" \ - -H 'accept: application/json' \ - -H 'content-type: application/json' \ - -d '{ - "model_id": "gemma3:27b-it-qat", - "messages": [ - { - "role": "user", - "content": "how much space I have on my disk?" - } - ], - "stream": false - }' + api_curl GET "${LLAMASTACK_BASE_URL}/v1/agents" | jq -r '.data[]' } llama::chat_completion() { + local prompt="${1:-how much space I have on my disk?}" + local model="${2:-$LLAMA_MODEL}" + debug_print "POST ${LLAMASTACK_BASE_URL}/v1/inference/chat-completion" - curl -X 'POST' -s \ - "${LLAMASTACK_BASE_URL}/v1/inference/chat-completion" \ - -H 'accept: application/json' \ - -H 'content-type: application/json' \ - -d '{ - "model_id": "gemma3:27b-it-qat", - "messages": [ - { - "role": "user", - "content": "how much space I have on my disk?" - } - ], - "stream": false - }' + debug_print "Using model: $model" + debug_print "Prompt: $prompt" + + local data='{ + "model_id": "'$model'", + "messages": [ + { + "role": "user", + "content": "'$(echo "$prompt" | sed 's/"/\\\\"'/g)'" + } + ], + "stream": false + }' + + api_curl POST "${LLAMASTACK_BASE_URL}/v1/inference/chat-completion" "application/json" "$data" } ls::info() { debug_print "GET ${LIGHTSPEED_BASE_URL}/v1/info" - curl -s \ - "${LIGHTSPEED_BASE_URL}/v1/info" \ - -H 'accept: application/json' \ - -H 'content-type: application/json' | jq . + api_curl GET "${LIGHTSPEED_BASE_URL}/v1/info" | jq . } ls::config() { debug_print "GET ${LIGHTSPEED_BASE_URL}/v1/config" - curl -s \ - "${LIGHTSPEED_BASE_URL}/v1/config" \ - -H 'accept: application/json' \ - -H 'content-type: application/json' | jq . + api_curl GET "${LIGHTSPEED_BASE_URL}/v1/config" | jq . } ls::models() { debug_print "GET ${LIGHTSPEED_BASE_URL}/v1/models" - curl -s \ - "${LIGHTSPEED_BASE_URL}/v1/models" \ - -H 'accept: application/json' \ - -H 'content-type: application/json' | jq . + api_curl GET "${LIGHTSPEED_BASE_URL}/v1/models" | jq . } -ls::test() { +CHUCK_WORKFLOW_REQUEST=$(cat <" + return 1 + fi + debug_print "GET ${LIGHTSPEED_BASE_URL}/v1/conversations/$id" + api_curl GET "${LIGHTSPEED_BASE_URL}/v1/conversations/$id" | jq . +}