Tags:
- Platform Sections:
evaluation,finetuning,dataset - Complexity:
advanced - Domain:
safety
- Completed the Web Synthetic Safety Dataset tutorial
- A deployed fine-tuned model from that tutorial
- Project ID where the model and dataset reside
- Prem API key exported as
API_KEY - Python 3.8+ or Node.js 18+ installed
# Navigate to the Python directory from the repository root
cd tutorials/continuous-finetuning/python
# Create a virtual environment
python -m venv venv
# Activate the virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt# Navigate to the TypeScript directory from the repository root
cd tutorials/continuous-finetuning/typescript
# Install dependencies using bun
bun installBy the end of this tutorial, you will:
- Establish an automated evaluation pipeline using a judge model
- Create traces in Prem Studio to track model performance
- Automatically expand your training dataset with corrected examples
- Launch a new fine-tuning job that incorporates learnings from previous errors
You need the Project ID and the Model Alias (or ID) of your fine-tuned model. You can find these in the Prem Studio dashboard.
Generate responses from your fine-tuned model using test prompts matching your domain.
API Endpoint: POST /api/v1/chat/completions
Use a judge model (Claude 4.5 Sonnet) to score the safety classification (0-1) and provide feedback.
API Endpoint: POST /api/v1/chat/completions
Log the interaction as a "Trace" in Prem Studio, attaching the score and feedback.
API Endpoint: POST /api/v1/traces
Add these traces to your original dataset. Prem Studio handles the logic: high-quality traces are added as-is; low-quality traces are corrected before addition.
API Endpoint: POST /api/v1/traces/{trace_id}/addToDataset
Create a new snapshot of the augmented dataset.
API Endpoint: POST /api/v1/public/snapshots/create
Analyze the new snapshot and launch a fine-tuning job.
API Endpoints:
See typescript/script.ts for the complete implementation.
To run the TypeScript script:
# Navigate to the TypeScript directory from the repository root
cd tutorials/continuous-finetuning/typescript
# Replace placeholders with your actual values
bun script.ts --project-id <YOUR_PROJECT_ID> --model-alias <YOUR_MODEL_ALIAS>See python/script.py for the complete implementation.
To run the Python script:
# Navigate to the Python directory from the repository root
cd tutorials/continuous-finetuning/python
# Replace placeholders with your actual values
python script.py --project-id <YOUR_PROJECT_ID> --model-alias <YOUR_MODEL_ALIAS>- test_examples.json - Sample prompts for testing safety classification
- Monitor the new fine-tuning job in the Prem Studio dashboard
- Repeat this cycle periodically with new, challenging prompts to continuously refine your model
- Customize the
judge_promptin the script to enforce stricter or different evaluation criteria