mirror of
https://github.com/K-Dense-AI/claude-scientific-skills.git
synced 2026-01-26 16:58:56 +08:00
Enhance citation management and literature review guidelines
- Updated SKILL.md in citation management to include best practices for identifying seminal and high-impact papers, emphasizing citation count thresholds, venue quality tiers, and author reputation indicators. - Expanded literature review SKILL.md to prioritize high-impact papers, detailing citation metrics, journal tiers, and author reputation assessment. - Added comprehensive evaluation strategies for paper impact and quality in literature_search_strategies.md, including citation count significance and journal impact factor guidance. - Improved research lookup scripts to prioritize results based on citation count, venue prestige, and author reputation, enhancing the quality of research outputs.
This commit is contained in:
@@ -0,0 +1,207 @@
|
||||
# Scientific Schematics - Quick Reference
|
||||
|
||||
**How it works:** Describe your diagram → Nano Banana Pro generates it automatically
|
||||
|
||||
## Setup (One-Time)
|
||||
|
||||
```bash
|
||||
# Get API key from https://openrouter.ai/keys
|
||||
export OPENROUTER_API_KEY='sk-or-v1-your_key_here'
|
||||
|
||||
# Add to shell profile for persistence
|
||||
echo 'export OPENROUTER_API_KEY="sk-or-v1-your_key"' >> ~/.bashrc # or ~/.zshrc
|
||||
```
|
||||
|
||||
## Basic Usage
|
||||
|
||||
```bash
|
||||
# Describe your diagram, Nano Banana Pro creates it
|
||||
python scripts/generate_schematic.py "your diagram description" -o output.png
|
||||
|
||||
# That's it! Automatic:
|
||||
# - Iterative refinement (3 rounds)
|
||||
# - Quality review and improvement
|
||||
# - Publication-ready output
|
||||
```
|
||||
|
||||
## Common Examples
|
||||
|
||||
### CONSORT Flowchart
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"CONSORT flow: screened n=500, excluded n=150, randomized n=350" \
|
||||
-o consort.png
|
||||
```
|
||||
|
||||
### Neural Network
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"Transformer architecture with encoder and decoder stacks" \
|
||||
-o transformer.png
|
||||
```
|
||||
|
||||
### Biological Pathway
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"MAPK pathway: EGFR → RAS → RAF → MEK → ERK" \
|
||||
-o mapk.png
|
||||
```
|
||||
|
||||
### Circuit Diagram
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"Op-amp circuit with 1kΩ resistor and 10µF capacitor" \
|
||||
-o circuit.png
|
||||
```
|
||||
|
||||
## Command Options
|
||||
|
||||
| Option | Description | Example |
|
||||
|--------|-------------|---------|
|
||||
| `-o, --output` | Output file path | `-o figures/diagram.png` |
|
||||
| `--iterations N` | Number of refinements (1-2) | `--iterations 2` |
|
||||
| `-v, --verbose` | Show detailed output | `-v` |
|
||||
| `--api-key KEY` | Provide API key | `--api-key sk-or-v1-...` |
|
||||
|
||||
## Prompt Tips
|
||||
|
||||
### ✓ Good Prompts (Specific)
|
||||
- "CONSORT flowchart with screening (n=500), exclusion (n=150), randomization (n=350)"
|
||||
- "Transformer architecture: encoder on left with 6 layers, decoder on right, cross-attention connections"
|
||||
- "MAPK signaling: receptor → RAS → RAF → MEK → ERK → nucleus, label each phosphorylation"
|
||||
|
||||
### ✗ Avoid (Too Vague)
|
||||
- "Make a flowchart"
|
||||
- "Neural network"
|
||||
- "Pathway diagram"
|
||||
|
||||
## Output Files
|
||||
|
||||
For input `diagram.png`, you get:
|
||||
- `diagram_v1.png` - First iteration
|
||||
- `diagram_v2.png` - Second iteration
|
||||
- `diagram_v3.png` - Final iteration
|
||||
- `diagram.png` - Copy of final
|
||||
- `diagram_review_log.json` - Quality scores and critiques
|
||||
|
||||
## Review Log
|
||||
|
||||
```json
|
||||
{
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"score": 7.0,
|
||||
"critique": "Good start. Font too small..."
|
||||
},
|
||||
{
|
||||
"iteration": 2,
|
||||
"score": 8.5,
|
||||
"critique": "Much improved. Minor spacing issues..."
|
||||
},
|
||||
{
|
||||
"iteration": 3,
|
||||
"score": 9.5,
|
||||
"critique": "Excellent. Publication ready."
|
||||
}
|
||||
],
|
||||
"final_score": 9.5
|
||||
}
|
||||
```
|
||||
|
||||
## Python API
|
||||
|
||||
```python
|
||||
from scripts.generate_schematic_ai import ScientificSchematicGenerator
|
||||
|
||||
# Initialize
|
||||
gen = ScientificSchematicGenerator(api_key="your_key")
|
||||
|
||||
# Generate
|
||||
results = gen.generate_iterative(
|
||||
user_prompt="diagram description",
|
||||
output_path="output.png",
|
||||
iterations=2
|
||||
)
|
||||
|
||||
# Check quality
|
||||
print(f"Score: {results['final_score']}/10")
|
||||
```
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### API Key Not Found
|
||||
```bash
|
||||
# Check if set
|
||||
echo $OPENROUTER_API_KEY
|
||||
|
||||
# Set it
|
||||
export OPENROUTER_API_KEY='your_key'
|
||||
```
|
||||
|
||||
### Import Error
|
||||
```bash
|
||||
# Install requests
|
||||
pip install requests
|
||||
```
|
||||
|
||||
### Low Quality Score
|
||||
- Make prompt more specific
|
||||
- Include layout details (left-to-right, top-to-bottom)
|
||||
- Specify label requirements
|
||||
- Increase iterations: `--iterations 2`
|
||||
|
||||
## Testing
|
||||
|
||||
```bash
|
||||
# Verify installation
|
||||
python test_ai_generation.py
|
||||
|
||||
# Should show: "6/6 tests passed"
|
||||
```
|
||||
|
||||
## Cost
|
||||
|
||||
Typical cost per diagram (max 2 iterations):
|
||||
- Simple (1 iteration): $0.05-0.15
|
||||
- Complex (2 iterations): $0.10-0.30
|
||||
|
||||
## How Nano Banana Pro Works
|
||||
|
||||
**Simply describe your diagram in natural language:**
|
||||
- ✓ No coding required
|
||||
- ✓ No templates needed
|
||||
- ✓ No manual drawing
|
||||
- ✓ Automatic quality review
|
||||
- ✓ Publication-ready output
|
||||
- ✓ Works for any diagram type
|
||||
|
||||
**Just describe what you want, and it's generated automatically.**
|
||||
|
||||
## Getting Help
|
||||
|
||||
```bash
|
||||
# Show help
|
||||
python scripts/generate_schematic.py --help
|
||||
|
||||
# Verbose mode for debugging
|
||||
python scripts/generate_schematic.py "diagram" -o out.png -v
|
||||
```
|
||||
|
||||
## Quick Start Checklist
|
||||
|
||||
- [ ] Set `OPENROUTER_API_KEY` environment variable
|
||||
- [ ] Run `python test_ai_generation.py` (should pass 6/6)
|
||||
- [ ] Try: `python scripts/generate_schematic.py "test diagram" -o test.png`
|
||||
- [ ] Review output files (test_v1.png, v2, v3, review_log.json)
|
||||
- [ ] Read SKILL.md for detailed documentation
|
||||
- [ ] Check README.md for examples
|
||||
|
||||
## Resources
|
||||
|
||||
- Full documentation: `SKILL.md`
|
||||
- Detailed guide: `README.md`
|
||||
- Implementation details: `IMPLEMENTATION_SUMMARY.md`
|
||||
- Example script: `example_usage.sh`
|
||||
- Get API key: https://openrouter.ai/keys
|
||||
|
||||
327
scientific-skills/scientific-schematics/references/README.md
Normal file
327
scientific-skills/scientific-schematics/references/README.md
Normal file
@@ -0,0 +1,327 @@
|
||||
# Scientific Schematics - Nano Banana Pro
|
||||
|
||||
**Generate any scientific diagram by describing it in natural language.**
|
||||
|
||||
Nano Banana Pro creates publication-quality diagrams automatically - no coding, no templates, no manual drawing required.
|
||||
|
||||
## Quick Start
|
||||
|
||||
### Generate Any Diagram
|
||||
|
||||
```bash
|
||||
# Set your OpenRouter API key
|
||||
export OPENROUTER_API_KEY='your_api_key_here'
|
||||
|
||||
# Generate any scientific diagram
|
||||
python scripts/generate_schematic.py "CONSORT participant flow diagram" -o figures/consort.png
|
||||
|
||||
# Neural network architecture
|
||||
python scripts/generate_schematic.py "Transformer encoder-decoder architecture" -o figures/transformer.png
|
||||
|
||||
# Biological pathway
|
||||
python scripts/generate_schematic.py "MAPK signaling pathway" -o figures/pathway.png
|
||||
```
|
||||
|
||||
### What You Get
|
||||
|
||||
- **Up to two iterations** (v1, v2) with progressive refinement
|
||||
- **Automatic quality review** after each iteration
|
||||
- **Detailed review log** with scores and critiques (JSON format)
|
||||
- **Publication-ready images** following scientific standards
|
||||
|
||||
## Features
|
||||
|
||||
### Iterative Refinement Process
|
||||
|
||||
1. **Generation 1**: Create initial diagram from your description
|
||||
2. **Review 1**: AI evaluates clarity, labels, accuracy, accessibility
|
||||
3. **Generation 2**: Improve based on critique
|
||||
4. **Review 2**: Second evaluation with specific feedback
|
||||
5. **Generation 3**: Final polished version
|
||||
|
||||
### Automatic Quality Standards
|
||||
|
||||
All diagrams automatically follow:
|
||||
- Clean white/light background
|
||||
- High contrast for readability
|
||||
- Clear labels (minimum 10pt font)
|
||||
- Professional typography
|
||||
- Colorblind-friendly colors
|
||||
- Proper spacing between elements
|
||||
- Scale bars, legends, axes where appropriate
|
||||
|
||||
## Installation
|
||||
|
||||
### For AI Generation
|
||||
|
||||
```bash
|
||||
# Get OpenRouter API key
|
||||
# Visit: https://openrouter.ai/keys
|
||||
|
||||
# Set environment variable
|
||||
export OPENROUTER_API_KEY='sk-or-v1-...'
|
||||
|
||||
# Or add to .env file
|
||||
echo "OPENROUTER_API_KEY=sk-or-v1-..." >> .env
|
||||
|
||||
# Install Python dependencies (if not already installed)
|
||||
pip install requests
|
||||
```
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Example 1: CONSORT Flowchart
|
||||
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"CONSORT participant flow diagram for RCT. \
|
||||
Assessed for eligibility (n=500). \
|
||||
Excluded (n=150): age<18 (n=80), declined (n=50), other (n=20). \
|
||||
Randomized (n=350) into Treatment (n=175) and Control (n=175). \
|
||||
Lost to follow-up: 15 and 10 respectively. \
|
||||
Final analysis: 160 and 165." \
|
||||
-o figures/consort.png
|
||||
```
|
||||
|
||||
**Output:**
|
||||
- `figures/consort_v1.png` - Initial generation
|
||||
- `figures/consort_v2.png` - After first review
|
||||
- `figures/consort_v3.png` - Final version
|
||||
- `figures/consort.png` - Copy of final version
|
||||
- `figures/consort_review_log.json` - Detailed review log
|
||||
|
||||
### Example 2: Neural Network Architecture
|
||||
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"Transformer architecture with encoder on left (input embedding, \
|
||||
positional encoding, multi-head attention, feed-forward) and \
|
||||
decoder on right (masked attention, cross-attention, feed-forward). \
|
||||
Show cross-attention connection from encoder to decoder." \
|
||||
-o figures/transformer.png \
|
||||
--iterations 2
|
||||
```
|
||||
|
||||
### Example 3: Biological Pathway
|
||||
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"MAPK signaling pathway: EGFR receptor → RAS → RAF → MEK → ERK → nucleus. \
|
||||
Label each step with phosphorylation. Use different colors for each kinase." \
|
||||
-o figures/mapk.png
|
||||
```
|
||||
|
||||
### Example 4: System Architecture
|
||||
|
||||
```bash
|
||||
python scripts/generate_schematic.py \
|
||||
"IoT system block diagram: sensors (bottom) → microcontroller → \
|
||||
WiFi module and display (middle) → cloud server → mobile app (top). \
|
||||
Label all connections with protocols." \
|
||||
-o figures/iot_system.png
|
||||
```
|
||||
|
||||
## Command-Line Options
|
||||
|
||||
```bash
|
||||
python scripts/generate_schematic.py [OPTIONS] "description" -o output.png
|
||||
|
||||
Options:
|
||||
--iterations N Number of AI refinement iterations (default: 2, max: 2)
|
||||
--api-key KEY OpenRouter API key (or use env var)
|
||||
-v, --verbose Verbose output
|
||||
-h, --help Show help message
|
||||
```
|
||||
|
||||
## Python API
|
||||
|
||||
```python
|
||||
from scripts.generate_schematic_ai import ScientificSchematicGenerator
|
||||
|
||||
# Initialize
|
||||
generator = ScientificSchematicGenerator(
|
||||
api_key="your_key",
|
||||
verbose=True
|
||||
)
|
||||
|
||||
# Generate with iterative refinement
|
||||
results = generator.generate_iterative(
|
||||
user_prompt="CONSORT flowchart",
|
||||
output_path="figures/consort.png",
|
||||
iterations=2
|
||||
)
|
||||
|
||||
# Access results
|
||||
print(f"Final score: {results['final_score']}/10")
|
||||
print(f"Final image: {results['final_image']}")
|
||||
|
||||
# Review iterations
|
||||
for iteration in results['iterations']:
|
||||
print(f"Iteration {iteration['iteration']}: {iteration['score']}/10")
|
||||
print(f"Critique: {iteration['critique']}")
|
||||
```
|
||||
|
||||
## Prompt Engineering Tips
|
||||
|
||||
### Be Specific About Layout
|
||||
✓ "Flowchart with vertical flow, top to bottom"
|
||||
✓ "Architecture diagram with encoder on left, decoder on right"
|
||||
✗ "Make a diagram" (too vague)
|
||||
|
||||
### Include Quantitative Details
|
||||
✓ "Neural network: input (784), hidden (128), output (10)"
|
||||
✓ "Flowchart: n=500 screened, n=150 excluded, n=350 randomized"
|
||||
✗ "Some numbers" (not specific)
|
||||
|
||||
### Specify Visual Style
|
||||
✓ "Minimalist block diagram with clean lines"
|
||||
✓ "Detailed biological pathway with protein structures"
|
||||
✓ "Technical schematic with engineering notation"
|
||||
|
||||
### Request Specific Labels
|
||||
✓ "Label all arrows with activation/inhibition"
|
||||
✓ "Include layer dimensions in each box"
|
||||
✓ "Show time progression with timestamps"
|
||||
|
||||
### Mention Color Requirements
|
||||
✓ "Use colorblind-friendly colors"
|
||||
✓ "Grayscale-compatible design"
|
||||
✓ "Color-code by function: blue=input, green=processing, red=output"
|
||||
|
||||
## Review Log Format
|
||||
|
||||
Each generation produces a JSON review log:
|
||||
|
||||
```json
|
||||
{
|
||||
"user_prompt": "CONSORT participant flow diagram...",
|
||||
"iterations": [
|
||||
{
|
||||
"iteration": 1,
|
||||
"image_path": "figures/consort_v1.png",
|
||||
"prompt": "Full generation prompt...",
|
||||
"critique": "Score: 7/10. Issues: font too small...",
|
||||
"score": 7.0,
|
||||
"success": true
|
||||
},
|
||||
{
|
||||
"iteration": 2,
|
||||
"image_path": "figures/consort_v2.png",
|
||||
"score": 8.5,
|
||||
"critique": "Much improved. Remaining issues..."
|
||||
},
|
||||
{
|
||||
"iteration": 3,
|
||||
"image_path": "figures/consort_v3.png",
|
||||
"score": 9.5,
|
||||
"critique": "Excellent. Publication ready."
|
||||
}
|
||||
],
|
||||
"final_image": "figures/consort_v3.png",
|
||||
"final_score": 9.5,
|
||||
"success": true
|
||||
}
|
||||
```
|
||||
|
||||
## Why Use Nano Banana Pro
|
||||
|
||||
**Simply describe what you want - Nano Banana Pro creates it:**
|
||||
|
||||
- ✓ **Fast**: Results in minutes
|
||||
- ✓ **Easy**: Natural language descriptions (no coding)
|
||||
- ✓ **Quality**: Automatic review and refinement
|
||||
- ✓ **Universal**: Works for all diagram types
|
||||
- ✓ **Publication-ready**: High-quality output immediately
|
||||
|
||||
**Just describe your diagram, and it's generated automatically.**
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### API Key Issues
|
||||
|
||||
```bash
|
||||
# Check if key is set
|
||||
echo $OPENROUTER_API_KEY
|
||||
|
||||
# Set temporarily
|
||||
export OPENROUTER_API_KEY='your_key'
|
||||
|
||||
# Set permanently (add to ~/.bashrc or ~/.zshrc)
|
||||
echo 'export OPENROUTER_API_KEY="your_key"' >> ~/.bashrc
|
||||
```
|
||||
|
||||
### Import Errors
|
||||
|
||||
```bash
|
||||
# Install requests library
|
||||
pip install requests
|
||||
|
||||
# Or use the package manager
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
### Generation Fails
|
||||
|
||||
```bash
|
||||
# Use verbose mode to see detailed errors
|
||||
python scripts/generate_schematic.py "diagram" -o out.png -v
|
||||
|
||||
# Check API status
|
||||
curl https://openrouter.ai/api/v1/models
|
||||
```
|
||||
|
||||
### Low Quality Scores
|
||||
|
||||
If iterations consistently score below 7/10:
|
||||
1. Make your prompt more specific
|
||||
2. Include more details about layout and labels
|
||||
3. Specify visual requirements explicitly
|
||||
4. Increase iterations: `--iterations 2`
|
||||
|
||||
## Testing
|
||||
|
||||
Run verification tests:
|
||||
|
||||
```bash
|
||||
python test_ai_generation.py
|
||||
```
|
||||
|
||||
This tests:
|
||||
- File structure
|
||||
- Module imports
|
||||
- Class initialization
|
||||
- Error handling
|
||||
- Prompt engineering
|
||||
- Wrapper script
|
||||
|
||||
## Cost Considerations
|
||||
|
||||
OpenRouter pricing for models used:
|
||||
- **Nano Banana Pro**: ~$2/M input tokens, ~$12/M output tokens
|
||||
|
||||
Typical costs per diagram:
|
||||
- Simple diagram (1 iteration): ~$0.05-0.15
|
||||
- Complex diagram (2 iterations): ~$0.10-0.30
|
||||
|
||||
## Examples Gallery
|
||||
|
||||
See the full SKILL.md for extensive examples including:
|
||||
- CONSORT flowcharts
|
||||
- Neural network architectures (Transformers, CNNs, RNNs)
|
||||
- Biological pathways
|
||||
- Circuit diagrams
|
||||
- System architectures
|
||||
- Block diagrams
|
||||
|
||||
## Support
|
||||
|
||||
For issues or questions:
|
||||
1. Check SKILL.md for detailed documentation
|
||||
2. Run test_ai_generation.py to verify setup
|
||||
3. Use verbose mode (-v) to see detailed errors
|
||||
4. Review the review_log.json for quality feedback
|
||||
|
||||
## License
|
||||
|
||||
Part of the scientific-writer package. See main repository for license information.
|
||||
|
||||
89
scientific-skills/scientific-schematics/scripts/example_usage.sh
Executable file
89
scientific-skills/scientific-schematics/scripts/example_usage.sh
Executable file
@@ -0,0 +1,89 @@
|
||||
#!/bin/bash
|
||||
# Example usage of AI-powered scientific schematic generation
|
||||
#
|
||||
# Prerequisites:
|
||||
# 1. Set OPENROUTER_API_KEY environment variable
|
||||
# 2. Ensure Python 3.10+ is installed
|
||||
# 3. Install requests: pip install requests
|
||||
|
||||
set -e
|
||||
|
||||
echo "=========================================="
|
||||
echo "Scientific Schematics - AI Generation"
|
||||
echo "Example Usage Demonstrations"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
|
||||
# Check for API key
|
||||
if [ -z "$OPENROUTER_API_KEY" ]; then
|
||||
echo "❌ Error: OPENROUTER_API_KEY environment variable not set"
|
||||
echo ""
|
||||
echo "Get an API key at: https://openrouter.ai/keys"
|
||||
echo "Then set it with: export OPENROUTER_API_KEY='your_key'"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✓ OPENROUTER_API_KEY is set"
|
||||
echo ""
|
||||
|
||||
# Create output directory
|
||||
mkdir -p figures
|
||||
echo "✓ Created figures/ directory"
|
||||
echo ""
|
||||
|
||||
# Example 1: Simple flowchart
|
||||
echo "Example 1: CONSORT Flowchart"
|
||||
echo "----------------------------"
|
||||
python scripts/generate_schematic.py \
|
||||
"CONSORT participant flow diagram. Assessed for eligibility (n=500). Excluded (n=150) with reasons: age<18 (n=80), declined (n=50), other (n=20). Randomized (n=350) into Treatment (n=175) and Control (n=175). Lost to follow-up: 15 and 10. Final analysis: 160 and 165." \
|
||||
-o figures/consort_example.png \
|
||||
--iterations 2
|
||||
|
||||
echo ""
|
||||
echo "✓ Generated: figures/consort_example.png"
|
||||
echo " - Also created: consort_example_v1.png, v2.png, v3.png"
|
||||
echo " - Review log: consort_example_review_log.json"
|
||||
echo ""
|
||||
|
||||
# Example 2: Neural network (shorter for demo)
|
||||
echo "Example 2: Simple Neural Network"
|
||||
echo "--------------------------------"
|
||||
python scripts/generate_schematic.py \
|
||||
"Simple feedforward neural network diagram. Input layer with 4 nodes, hidden layer with 6 nodes, output layer with 2 nodes. Show all connections. Label layers clearly." \
|
||||
-o figures/neural_net_example.png \
|
||||
--iterations 2
|
||||
|
||||
echo ""
|
||||
echo "✓ Generated: figures/neural_net_example.png"
|
||||
echo ""
|
||||
|
||||
# Example 3: Biological pathway (minimal)
|
||||
echo "Example 3: Signaling Pathway"
|
||||
echo "---------------------------"
|
||||
python scripts/generate_schematic.py \
|
||||
"Simple signaling pathway: Receptor → Kinase A → Kinase B → Transcription Factor → Gene. Show arrows with 'activation' labels. Use different colors for each component." \
|
||||
-o figures/pathway_example.png \
|
||||
--iterations 2
|
||||
|
||||
echo ""
|
||||
echo "✓ Generated: figures/pathway_example.png"
|
||||
echo ""
|
||||
|
||||
echo "=========================================="
|
||||
echo "All examples completed successfully!"
|
||||
echo "=========================================="
|
||||
echo ""
|
||||
echo "Generated files in figures/:"
|
||||
ls -lh figures/*example*.png 2>/dev/null || echo " (Files will appear after running with valid API key)"
|
||||
echo ""
|
||||
echo "Review the review_log.json files to see:"
|
||||
echo " - Quality scores for each iteration"
|
||||
echo " - Detailed critiques and suggestions"
|
||||
echo " - Improvement progression"
|
||||
echo ""
|
||||
echo "Next steps:"
|
||||
echo " 1. View the generated images"
|
||||
echo " 2. Review the quality scores in *_review_log.json"
|
||||
echo " 3. Try your own prompts!"
|
||||
echo ""
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Test script to verify AI generation implementation.
|
||||
|
||||
This script performs dry-run tests without making actual API calls.
|
||||
It verifies:
|
||||
1. Script structure and imports
|
||||
2. Class initialization
|
||||
3. Method signatures
|
||||
4. Error handling
|
||||
5. Command-line interface
|
||||
|
||||
Usage:
|
||||
python test_ai_generation.py
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
# Add scripts directory to path
|
||||
scripts_dir = Path(__file__).parent / "scripts"
|
||||
sys.path.insert(0, str(scripts_dir))
|
||||
|
||||
def test_imports():
|
||||
"""Test that all required modules can be imported."""
|
||||
print("Testing imports...")
|
||||
try:
|
||||
from generate_schematic_ai import ScientificSchematicGenerator
|
||||
print("✓ generate_schematic_ai imports successfully")
|
||||
return True
|
||||
except ImportError as e:
|
||||
print(f"✗ Import failed: {e}")
|
||||
return False
|
||||
|
||||
def test_class_structure():
|
||||
"""Test class initialization and structure."""
|
||||
print("\nTesting class structure...")
|
||||
try:
|
||||
from generate_schematic_ai import ScientificSchematicGenerator
|
||||
|
||||
# Test initialization with dummy key
|
||||
generator = ScientificSchematicGenerator(api_key="test_key", verbose=False)
|
||||
print("✓ Class initializes successfully")
|
||||
|
||||
# Check required methods exist
|
||||
required_methods = [
|
||||
'generate_image',
|
||||
'review_image',
|
||||
'improve_prompt',
|
||||
'generate_iterative'
|
||||
]
|
||||
|
||||
for method in required_methods:
|
||||
if not hasattr(generator, method):
|
||||
print(f"✗ Missing method: {method}")
|
||||
return False
|
||||
print(f"✓ Method exists: {method}")
|
||||
|
||||
# Check attributes
|
||||
if not hasattr(generator, 'api_key'):
|
||||
print("✗ Missing attribute: api_key")
|
||||
return False
|
||||
print("✓ Attribute exists: api_key")
|
||||
|
||||
if not hasattr(generator, 'image_model'):
|
||||
print("✗ Missing attribute: image_model")
|
||||
return False
|
||||
print(f"✓ Image model: {generator.image_model}")
|
||||
|
||||
if not hasattr(generator, 'review_model'):
|
||||
print("✗ Missing attribute: review_model")
|
||||
return False
|
||||
print(f"✓ Review model: {generator.review_model}")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Class structure test failed: {e}")
|
||||
return False
|
||||
|
||||
def test_error_handling():
|
||||
"""Test error handling for missing API key."""
|
||||
print("\nTesting error handling...")
|
||||
try:
|
||||
from generate_schematic_ai import ScientificSchematicGenerator
|
||||
|
||||
# Clear environment variable
|
||||
old_key = os.environ.get("OPENROUTER_API_KEY")
|
||||
if old_key:
|
||||
del os.environ["OPENROUTER_API_KEY"]
|
||||
|
||||
# Try to initialize without key
|
||||
try:
|
||||
generator = ScientificSchematicGenerator()
|
||||
print("✗ Should have raised ValueError for missing API key")
|
||||
return False
|
||||
except ValueError as e:
|
||||
if "OPENROUTER_API_KEY" in str(e):
|
||||
print("✓ Correctly raises ValueError for missing API key")
|
||||
else:
|
||||
print(f"✗ Wrong error message: {e}")
|
||||
return False
|
||||
|
||||
# Restore environment variable
|
||||
if old_key:
|
||||
os.environ["OPENROUTER_API_KEY"] = old_key
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Error handling test failed: {e}")
|
||||
return False
|
||||
|
||||
def test_wrapper_script():
|
||||
"""Test wrapper script structure."""
|
||||
print("\nTesting wrapper script...")
|
||||
try:
|
||||
import generate_schematic
|
||||
print("✓ generate_schematic imports successfully")
|
||||
|
||||
# Check main functions exist
|
||||
if not hasattr(generate_schematic, 'main'):
|
||||
print("✗ Missing function: main")
|
||||
return False
|
||||
print("✓ Function exists: main")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Wrapper script test failed: {e}")
|
||||
return False
|
||||
|
||||
def test_prompt_engineering():
|
||||
"""Test prompt construction."""
|
||||
print("\nTesting prompt engineering...")
|
||||
try:
|
||||
from generate_schematic_ai import ScientificSchematicGenerator
|
||||
|
||||
generator = ScientificSchematicGenerator(api_key="test_key", verbose=False)
|
||||
|
||||
# Test improve_prompt method
|
||||
original = "Create a flowchart"
|
||||
critique = "Add more spacing between boxes"
|
||||
improved = generator.improve_prompt(original, critique, 2)
|
||||
|
||||
if not improved:
|
||||
print("✗ improve_prompt returned empty string")
|
||||
return False
|
||||
|
||||
if original not in improved:
|
||||
print("✗ Improved prompt doesn't include original")
|
||||
return False
|
||||
|
||||
if critique not in improved:
|
||||
print("✗ Improved prompt doesn't include critique")
|
||||
return False
|
||||
|
||||
if "ITERATION 2" not in improved:
|
||||
print("✗ Improved prompt doesn't include iteration number")
|
||||
return False
|
||||
|
||||
print("✓ Prompt engineering works correctly")
|
||||
print(f" Original length: {len(original)} chars")
|
||||
print(f" Improved length: {len(improved)} chars")
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
print(f"✗ Prompt engineering test failed: {e}")
|
||||
return False
|
||||
|
||||
def test_file_paths():
|
||||
"""Test that all required files exist."""
|
||||
print("\nTesting file structure...")
|
||||
|
||||
base_dir = Path(__file__).parent
|
||||
required_files = [
|
||||
"scripts/generate_schematic_ai.py",
|
||||
"scripts/generate_schematic.py",
|
||||
"SKILL.md",
|
||||
"README.md"
|
||||
]
|
||||
|
||||
all_exist = True
|
||||
for file_path in required_files:
|
||||
full_path = base_dir / file_path
|
||||
if full_path.exists():
|
||||
print(f"✓ {file_path}")
|
||||
else:
|
||||
print(f"✗ Missing: {file_path}")
|
||||
all_exist = False
|
||||
|
||||
return all_exist
|
||||
|
||||
def main():
|
||||
"""Run all tests."""
|
||||
print("="*60)
|
||||
print("Scientific Schematics AI Generation - Verification Tests")
|
||||
print("="*60)
|
||||
|
||||
tests = [
|
||||
("File Structure", test_file_paths),
|
||||
("Imports", test_imports),
|
||||
("Class Structure", test_class_structure),
|
||||
("Error Handling", test_error_handling),
|
||||
("Wrapper Script", test_wrapper_script),
|
||||
("Prompt Engineering", test_prompt_engineering),
|
||||
]
|
||||
|
||||
results = []
|
||||
for test_name, test_func in tests:
|
||||
try:
|
||||
result = test_func()
|
||||
results.append((test_name, result))
|
||||
except Exception as e:
|
||||
print(f"\n✗ Test '{test_name}' crashed: {e}")
|
||||
results.append((test_name, False))
|
||||
|
||||
# Summary
|
||||
print("\n" + "="*60)
|
||||
print("Test Summary")
|
||||
print("="*60)
|
||||
|
||||
passed = sum(1 for _, result in results if result)
|
||||
total = len(results)
|
||||
|
||||
for test_name, result in results:
|
||||
status = "✓ PASS" if result else "✗ FAIL"
|
||||
print(f"{status}: {test_name}")
|
||||
|
||||
print(f"\nTotal: {passed}/{total} tests passed")
|
||||
|
||||
if passed == total:
|
||||
print("\n✓ All tests passed! Implementation verified.")
|
||||
print("\nNext steps:")
|
||||
print("1. Set OPENROUTER_API_KEY environment variable")
|
||||
print("2. Test with actual API call:")
|
||||
print(" python scripts/generate_schematic.py 'test diagram' -o test.png")
|
||||
return 0
|
||||
else:
|
||||
print(f"\n✗ {total - passed} test(s) failed. Please review errors above.")
|
||||
return 1
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
|
||||
Reference in New Issue
Block a user