Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 53 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,34 @@ jobs:
- name: Run type checking with tox
run: tox -e type

# test:
# name: Unit Tests
# runs-on: ubuntu-latest
# needs: [format, lint, type]
# strategy:
# matrix:
# python-version: ["3.10", "3.11", "3.12"]

# steps:
# - uses: actions/checkout@v4

# - name: Set up Python ${{ matrix.python-version }}
# uses: actions/setup-python@v5
# with:
# python-version: ${{ matrix.python-version }}

# - name: Install tox
# run: |
# python -m pip install --upgrade pip
# pip install tox

# - name: Run tests with tox
# run: tox -e test
test:
name: Unit Tests
runs-on: ubuntu-latest
needs: [format, lint, type]
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install tox
run: |
python -m pip install --upgrade pip
pip install tox

- name: Run tests with tox
run: tox -e test

smoke-test:
name: Smoke Tests
runs-on: ubuntu-latest
needs: [format, lint, type]
needs: [format, lint, type, coverage]
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12"]
Expand All @@ -116,3 +116,32 @@ jobs:
- name: Test vtk-prompt CLI
run: |
vtk-prompt --help

coverage:
name: Test Coverage
runs-on: ubuntu-latest
needs: [format, lint, type]
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .
pip install pytest pytest-cov

- name: Run tests with coverage (non-blocking when no tests)
run: |
pytest -q --cov=vtk_prompt --cov-report=term --cov-report=xml || true

- name: Upload coverage report
if: ${{ hashFiles('coverage.xml') != '' }}
uses: actions/upload-artifact@v4
with:
name: coverage-xml
path: coverage.xml
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ repos:
- monai
- nibabel
- vtk
- types-PyYAML

# Spelling
- repo: https://github.com/codespell-project/codespell
Expand Down
91 changes: 87 additions & 4 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,26 @@ pip install -e ".[all]"

## Running tests

### Test Suite

The project includes a comprehensive test suite focused on the prompt assembly
system:

```bash
# Lint and format
black src/
flake8 src/
# Run all tests with tox
tox -e test

# Run specific test file
python -m pytest tests/test_prompt_assembly.py -v

# Test installation
# Run specific test methods
python -m pytest tests/test_prompt_assembly.py::TestPromptAssembly::test_default_values -v
```

### Manual Testing

```bash
# Test CLI installation and basic functionality
vtk-prompt --help
vtk-prompt-ui --help
```
Expand Down Expand Up @@ -51,6 +65,75 @@ export VTK_PROMPT_LOG_FILE="vtk-prompt.log"
setup_logging(level="DEBUG", log_file="vtk-prompt.log")
```

## Component System Architecture

The VTK Prompt system uses a modular component-based architecture for prompt
assembly.

### Overview

The component system allows you to:

- **Compose prompts** from reusable YAML files
- **Inject variables** dynamically (`{{VAR_NAME}}`)
- **Configure model parameters** per component
- **Conditionally include** components based on context

### Component Structure

Components are YAML files stored in `src/vtk_prompt/prompts/components/`:

```yaml
# example_component.yml
role: system | user | assistant
content: |
Your prompt content here with {{VARIABLE}} substitution.
VTK Version: {{VTK_VERSION}}

# Optional: Merge with existing message instead of creating new one
append: true | false # Add content after existing user message (e.g., additional instructions)
prepend: true | false # Add content before existing user message (e.g., context injection)

# Optional: Model configuration
model: "openai/gpt-5"
modelParameters:
temperature: 0.5
max_tokens: 4000
```

### Updating Existing Components

When modifying components:

1. **Preserve backward compatibility** - existing variable names
2. **Test thoroughly** - run full test suite
3. **Document changes** - update component comments
4. **Version carefully** - consider impact on existing prompts

### Component Loading System

The system uses these key classes:

- **`PromptComponentLoader`**: Loads and caches YAML files
- **`VTKPromptAssembler`**: Chains components together
- **`YAMLPromptLoader`**: Handles variable substitution
- **`assemble_vtk_prompt()`**: High-level convenience function

### Variable Substitution

Components support these built-in variables:

- `{{VTK_VERSION}}` - Current VTK version (e.g., "9.5.0")
- `{{PYTHON_VERSION}}` - Python requirements (e.g., ">=3.10")

Custom variables can be passed via:

```python
assembler.substitute_variables(CUSTOM_VAR="value")
# or
assemble_vtk_prompt("request", CUSTOM_VAR="value")
```

## Developer Mode

The web UI includes a developer mode that enables hot reload and debug logging
Expand Down
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[![Build and Publish](https://github.com/vicentebolea/vtk-prompt/actions/workflows/publish.yml/badge.svg)](https://github.com/vicentebolea/vtk-prompt/actions/workflows/publish.yml)
[![PyPI version](https://badge.fury.io/py/vtk-prompt.svg)](https://badge.fury.io/py/vtk-prompt)
[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![Coverage](https://img.shields.io/badge/coverage-11.0%25-red.svg)](htmlcov/index.html)
[![codecov](https://codecov.io/github/Kitware/vtk-prompt/graph/badge.svg?token=gg8CHNeBKR)](https://codecov.io/github/Kitware/vtk-prompt)

A command-line interface and web-based UI for generating VTK visualization code
using Large Language Models (Anthropic Claude, OpenAI GPT, NVIDIA NIM, and local
Expand Down Expand Up @@ -99,7 +99,7 @@ vtk-prompt "Create a red sphere"
# Advanced options
vtk-prompt "Create a textured cone with 32 resolution" \
--provider anthropic \
--model claude-opus-4-1 \
--model claude-opus-4-6 \
--max-tokens 4000 \
--rag \
--verbose
Expand Down Expand Up @@ -141,6 +141,61 @@ code = client.generate_code("Create a red sphere")
print(code)
```

## Model Configuration

**Model configuration with YAML prompt files:**

```yaml
# Model and parameter configuration
model: anthropic/claude-opus-4-6
modelParameters:
temperature: 0.2
max_tokens: 6000
```

**Using custom prompt files:**

```bash
# CLI: Use your custom prompt file
vtk-prompt "Create a sphere" --prompt-file custom_vtk_prompt.yml

# CLI: Or with additional CLI overrides
vtk-prompt "Create a complex scene" --prompt-file custom_vtk_prompt.yml --retry-attempts 3

# UI: Use your custom prompt file
vtk-prompt-ui --server --prompt-file custom_vtk_prompt.yml
```

### Model Parameters Guide

**Temperature Settings:**

- `0.1-0.3`: More focused, deterministic code generation
- `0.4-0.7`: Balanced creativity and consistency (recommended)
- `0.8-1.0`: More creative but potentially less reliable

**Token Limits:** Token usage can vary significantly between models and
providers. These are general guidelines:

- `1000-2000`: Simple visualizations and basic VTK objects
- `3000-4000`: Complex scenes with multiple objects
- `5000+`: Detailed implementations with extensive documentation

_Note: Different models have different token limits and costs. Check your
provider's documentation for specific model capabilities._

## Testing

Run the test suite using the project's standard tools:

```bash
# Run all tests with tox
tox -e test

# Run pre-commit hooks (includes testing)
pre-commit run --all-files
```

## Configuration

### Environment Variables
Expand All @@ -152,7 +207,7 @@ print(code)

| Provider | Default Model | Base URL |
| ------------- | ------------------------ | ----------------------------------- |
| **anthropic** | claude-opus-4-1 | https://api.anthropic.com/v1 |
| **anthropic** | claude-opus-4-6 | https://api.anthropic.com/v1 |
| **openai** | gpt-5 | https://api.openai.com/v1 |
| **nim** | meta/llama3-70b-instruct | https://integrate.api.nvidia.com/v1 |
| **custom** | User-defined | User-defined (for local models) |
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ authors = [
{name = "Vicente Adolfo Bolea Sanchez", email = "vicente.bolea@kitware.com"},
]
dependencies = [
"PyYAML>=6.0",
"chromadb>=0.6.3",
"click>=8.0.0",
"importlib_resources>=5.0.0",
Expand Down Expand Up @@ -45,7 +46,6 @@ dev = [
"pre-commit",
"ruff",
"pytest >=6",
"pytest-cov >=3",
"tox",
"black>=23.0.0",
"isort>=5.12.0",
Expand All @@ -58,12 +58,12 @@ dev = [
"types-requests",
"types-click",
"types-setuptools",
"types-PyYAML",
]

# Testing dependencies
test = [
"pytest>=7.0.0",
"pytest-cov>=4.0.0",
]

# All optional dependencies
Expand Down
Loading
Loading