diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2101587 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,13 @@ +# .dockerignore +.git +.github +.env +*.pyc +__pycache__ +.pytest_cache +.coverage +*.egg-info +.venv +.llamastack-venv +*.log +.DS_Store \ No newline at end of file diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..74db433 --- /dev/null +++ b/.env.template @@ -0,0 +1,16 @@ +# .env.template - Template for Environment Variables +# Copy this file to .env and modify the values as needed + +# vLLM Configuration +VLLM_URL=https://your-model-endpoint/v1/completions +VLLM_MAX_TOKENS=4096 +VLLM_API_TOKEN=your-api-token +VLLM_TLS_VERIFY=false + +# Kubernetes Configuration +K8S_NAMESPACE=default +K8S_SERVICE_ACCOUNT= + +# LMEval Provider Configuration +LMEVAL_USE_K8S=true +LMEVAL_DEFAULT_TOKENIZER=google/flan-t5-base \ No newline at end of file diff --git a/Dockerfile.local b/Dockerfile.local new file mode 100644 index 0000000..af13d66 --- /dev/null +++ b/Dockerfile.local @@ -0,0 +1,53 @@ +# Dockerfile for llama-stack-provider-lmeval (Local Development) +ARG PYTHON_VERSION=3.11 +FROM python:${PYTHON_VERSION}-slim + +# Set working directory +WORKDIR /app + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + git \ + curl \ + wget \ + build-essential \ + && rm -rf /var/lib/apt/lists/* + +# Install uv for fast Python package management +RUN pip install --no-cache-dir uv + +# Set environment variable for uv to use system Python +ENV UV_SYSTEM_PYTHON=1 + +# Copy project files first (for better layer caching) +COPY pyproject.toml README.md LICENSE ./ + +# Install dependencies +RUN uv pip install --no-cache -e ".[dev]" + +# Copy source code +COPY src/ ./src/ +COPY tests/ ./tests/ +COPY pytest.ini ./ + +# Copy demo and configuration files +COPY demo/ ./demo/ +COPY providers.d/ ./providers.d/ +COPY run.yaml ./run.yaml + +# Create directories for llama stack with proper permissions +RUN mkdir -p /.llama/providers.d /.cache && \ + chmod -R 777 /.llama /.cache + +# Remove uv after installation (following Meta's pattern) +RUN pip uninstall -y uv + +# Expose port +EXPOSE 8321 + +# Set Python path +ENV PYTHONPATH=/app/src:$PYTHONPATH + +# Default entrypoint +ENTRYPOINT ["python", "-m", "llama_stack.distribution.server.server"] +CMD ["--help"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..870e4a9 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,63 @@ +version: '3.8' + +services: + llama-stack-lmeval: + build: + context: . + dockerfile: Dockerfile.local + image: llama-stack-lmeval:local + ports: + - "8321:8321" + volumes: + # Mount your run.yaml config file + - ./run.yaml:/app/run.yaml:ro + # Mount external providers directory + - ./providers.d:/app/providers.d:ro + # Mount source code for development (optional) + - ./src:/app/src:ro + # Mount tests for running them + - ./tests:/app/tests:ro + environment: + - PYTHONPATH=/app/src + # Environment variables that can be overridden + - VLLM_URL=${VLLM_URL:-https://phi-3-predictor-llama-test.apps.rosa.p2i7w2k6p6w7t7e.3emk.p3.openshiftapps.com/v1/completions} + - VLLM_MAX_TOKENS=${VLLM_MAX_TOKENS:-4096} + - VLLM_API_TOKEN=${VLLM_API_TOKEN:-fake} + - VLLM_TLS_VERIFY=${VLLM_TLS_VERIFY:-true} + # Override default command to use your config + command: ["--config", "/app/run.yaml"] + # Or use this to run tests instead: + # command: ["python", "-m", "pytest", "tests/", "-v"] + + # Service for running tests only + test: + build: + context: . + dockerfile: Dockerfile.local + image: llama-stack-lmeval:local + volumes: + - ./src:/app/src:ro + - ./tests:/app/tests:ro + - ./pytest.ini:/app/pytest.ini:ro + environment: + - PYTHONPATH=/app/src + command: ["python", "-m", "pytest", "tests/", "-v"] + profiles: ["test"] + + # Service for development with shell access + dev: + build: + context: . + dockerfile: Dockerfile.local + image: llama-stack-lmeval:local + volumes: + - ./src:/app/src + - ./tests:/app/tests + - ./run.yaml:/app/run.yaml + - ./providers.d:/app/providers.d + environment: + - PYTHONPATH=/app/src + command: ["bash"] + stdin_open: true + tty: true + profiles: ["dev"] \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 1d78460..496bff2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,9 @@ dependencies = [ "aiosqlite", "uvicorn", "ipykernel", + "pydantic>=2.0", + "pyyaml", + "litellm", ] [project.optional-dependencies] diff --git a/scripts/build-and-test.sh b/scripts/build-and-test.sh new file mode 100755 index 0000000..df84e98 --- /dev/null +++ b/scripts/build-and-test.sh @@ -0,0 +1,77 @@ +#!/bin/bash +set -euo pipefail + +# Color codes +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +NC='\033[0m' + +# Error handler +error_handler() { + echo -e "${RED}Error on line $1${NC}" + exit 1 +} +trap 'error_handler $LINENO' ERR + +# Configuration +IMAGE_NAME="${IMAGE_NAME:-llama-stack-lmeval}" +VERSION="${VERSION:-local}" +FULL_IMAGE_NAME="${IMAGE_NAME}:${VERSION}" + +echo -e "${GREEN}๐Ÿš€ Building ${FULL_IMAGE_NAME} Docker image...${NC}" + +# Build the Docker image +docker build -f Dockerfile.local -t "${FULL_IMAGE_NAME}" . + +echo -e "${GREEN}โœ… Build completed successfully!${NC}" + +# Test the installation - Override entrypoint to run python directly +echo -e "${YELLOW}๐Ÿงช Testing Python imports...${NC}" +docker run --rm --entrypoint python "${FULL_IMAGE_NAME}" -c " +import sys +sys.path.insert(0, '/app/src') +from llama_stack_provider_lmeval.config import LMEvalEvalProviderConfig +from llama_stack_provider_lmeval.lmeval import LMEval +print('โœ… All imports successful!') +" + +# Run the unit tests - Override entrypoint +echo -e "${YELLOW}๐Ÿงช Running unit tests...${NC}" +docker run --rm \ + --entrypoint python \ + -v "$(pwd)/src:/app/src:ro" \ + -v "$(pwd)/tests:/app/tests:ro" \ + -v "$(pwd)/pytest.ini:/app/pytest.ini:ro" \ + -e PYTHONPATH=/app/src \ + "${FULL_IMAGE_NAME}" \ + -m pytest tests/ -v + +echo -e "${GREEN}๐ŸŽ‰ All tests passed!${NC}" + +# Test the server help command (with default entrypoint) +echo -e "${YELLOW}๐Ÿ”ง Testing server startup (help command)...${NC}" +docker run --rm "${FULL_IMAGE_NAME}" --help + +# Display usage information +cat << EOF + +${GREEN}๐Ÿ“‹ Usage Examples:${NC} +=================== + +1. Run the server with your config: + docker run -p 8321:8321 -v \$(pwd)/run.yaml:/app/run.yaml:ro \\ + -v \$(pwd)/providers.d:/app/providers.d:ro \\ + ${FULL_IMAGE_NAME} --config /app/run.yaml + +2. Run with docker-compose: + docker-compose up llama-stack-lmeval + +3. Run tests: + docker-compose --profile test up test + +4. Development shell: + docker-compose --profile dev run --rm dev + +${GREEN}โœจ Your Docker image is ready: ${FULL_IMAGE_NAME}${NC} +EOF \ No newline at end of file diff --git a/scripts/run-server.sh b/scripts/run-server.sh old mode 100644 new mode 100755 diff --git a/src/llama_stack_provider_lmeval/__init__.py b/src/llama_stack_provider_lmeval/__init__.py index f76a97e..0a3729f 100644 --- a/src/llama_stack_provider_lmeval/__init__.py +++ b/src/llama_stack_provider_lmeval/__init__.py @@ -29,8 +29,6 @@ async def get_adapter_impl( if deps is None: deps = {} - - # Extract base_url from config if available base_url = None if hasattr(config, "model_args") and config.model_args: @@ -52,5 +50,4 @@ async def get_adapter_impl( # Configurations "LMEval", "get_provider_spec", - -] \ No newline at end of file +]