Skip to content

Commit cbcc709

Browse files
authored
Lint + Format all cookbooks/scripts (#305)
* lint/format * docs: add Claude development guide and project documentation * chore: remove ruff from project dependencies
1 parent f2de38e commit cbcc709

File tree

95 files changed

+1270
-1821
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1270
-1821
lines changed

.github/scripts/verify_registry.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@
1717
schema Verify YAML files match their JSON schemas
1818
"""
1919

20-
import yaml
21-
import requests
22-
import sys
2320
import json
21+
import sys
2422
from pathlib import Path
2523

24+
import requests
25+
import yaml
26+
2627
try:
27-
from jsonschema import validate, ValidationError
28+
from jsonschema import ValidationError, validate
2829

2930
HAS_JSONSCHEMA = True
3031
except ImportError:
@@ -172,7 +173,7 @@ def verify_schemas(repo_root, authors, registry):
172173
if authors_schema_path.exists():
173174
print("Checking authors.yaml against schema...")
174175
try:
175-
with open(authors_schema_path, "r") as f:
176+
with open(authors_schema_path) as f:
176177
authors_schema = json.load(f)
177178
validate(instance=authors, schema=authors_schema)
178179
print(" ✓ authors.yaml matches schema")
@@ -190,7 +191,7 @@ def verify_schemas(repo_root, authors, registry):
190191
if registry_schema_path.exists():
191192
print("\nChecking registry.yaml against schema...")
192193
try:
193-
with open(registry_schema_path, "r") as f:
194+
with open(registry_schema_path) as f:
194195
registry_schema = json.load(f)
195196
validate(instance=registry, schema=registry_schema)
196197
print(" ✓ registry.yaml matches schema")
@@ -227,11 +228,11 @@ def main():
227228
registry = None
228229

229230
if command in ["all", "authors", "registry", "schema"]:
230-
with open(authors_path, "r") as f:
231+
with open(authors_path) as f:
231232
authors = yaml.safe_load(f)
232233

233234
if command in ["all", "paths", "registry", "schema"]:
234-
with open(registry_path, "r") as f:
235+
with open(registry_path) as f:
235236
registry = yaml.safe_load(f)
236237

237238
# Run verifications based on command

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.12.12
3+
rev: v0.14.6
44
hooks:
5-
- id: ruff
5+
- id: ruff-check
66
types_or: [python, pyi, jupyter]
77
args: ['--fix']
88
- id: ruff-format

CLAUDE.md

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Claude Cookbooks
2+
3+
A collection of Jupyter notebooks and Python examples for building with the Claude API.
4+
5+
## Quick Start
6+
7+
```bash
8+
# Install dependencies
9+
uv sync --all-extras
10+
11+
# Install pre-commit hooks
12+
uv run pre-commit install
13+
14+
# Set up API key
15+
cp .env.example .env
16+
# Edit .env and add your ANTHROPIC_API_KEY
17+
```
18+
19+
## Development Commands
20+
21+
```bash
22+
make format # Format code with ruff
23+
make lint # Run linting
24+
make check # Run format-check + lint
25+
make fix # Auto-fix issues + format
26+
make test # Run pytest
27+
```
28+
29+
Or directly with uv:
30+
31+
```bash
32+
uv run ruff format . # Format
33+
uv run ruff check . # Lint
34+
uv run ruff check --fix . # Auto-fix
35+
uv run pre-commit run --all-files
36+
```
37+
38+
## Code Style
39+
40+
- **Line length:** 100 characters
41+
- **Quotes:** Double quotes
42+
- **Formatter:** Ruff
43+
44+
Notebooks have relaxed rules for mid-file imports (E402), redefinitions (F811), and variable naming (N803, N806).
45+
46+
## Git Workflow
47+
48+
**Branch naming:** `<username>/<feature-description>`
49+
50+
**Commit format (conventional commits):**
51+
```
52+
feat(scope): add new feature
53+
fix(scope): fix bug
54+
docs(scope): update documentation
55+
style: lint/format
56+
```
57+
58+
## Key Rules
59+
60+
1. **API Keys:** Never commit `.env` files. Always use `os.environ.get("ANTHROPIC_API_KEY")`
61+
62+
2. **Dependencies:** Use `uv add <package>` or `uv add --dev <package>`. Never edit pyproject.toml directly.
63+
64+
3. **Models:** Use current Claude models. Check docs.anthropic.com for latest versions.
65+
- Sonnet: `claude-sonnet-4-5-20250929`
66+
- Haiku: `claude-haiku-4-5-20251001`
67+
68+
4. **Notebooks:**
69+
- Keep outputs in notebooks (intentional for demonstration)
70+
- One concept per notebook
71+
- Test that notebooks run top-to-bottom without errors
72+
73+
5. **Quality checks:** Run `make check` before committing. Pre-commit hooks validate formatting and notebook structure.
74+
75+
## Slash Commands
76+
77+
These commands are available in Claude Code and CI:
78+
79+
- `/notebook-review` - Review notebook quality
80+
- `/model-check` - Validate Claude model references
81+
- `/link-review` - Check links in changed files
82+
83+
## Project Structure
84+
85+
```
86+
capabilities/ # Core Claude capabilities (RAG, classification, etc.)
87+
skills/ # Advanced skill-based notebooks
88+
tool_use/ # Tool use and integration patterns
89+
multimodal/ # Vision and image processing
90+
misc/ # Batch processing, caching, utilities
91+
third_party/ # Pinecone, Voyage, Wikipedia integrations
92+
extended_thinking/ # Extended reasoning patterns
93+
scripts/ # Validation scripts
94+
.claude/ # Claude Code commands and skills
95+
```
96+
97+
## Adding a New Cookbook
98+
99+
1. Create notebook in the appropriate directory
100+
2. Add entry to `registry.yaml` with title, description, path, authors, categories
101+
3. Add author info to `authors.yaml` if new contributor
102+
4. Run quality checks and submit PR

capabilities/classification/evaluation/prompts.py

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,60 @@
1-
from vectordb import VectorDB
21
import textwrap
32

3+
from vectordb import VectorDB
4+
45
vectordb = VectorDB()
56
# Load the vector database
67
vectordb.load_db()
78

8-
categories = """<category>
9+
categories = """<category>
910
<label>Billing Inquiries</label>
10-
<content> Questions about invoices, charges, fees, and premiums Requests for clarification on billing statements Inquiries about payment methods and due dates
11-
</content>
12-
</category>
13-
<category>
11+
<content> Questions about invoices, charges, fees, and premiums Requests for clarification on billing statements Inquiries about payment methods and due dates
12+
</content>
13+
</category>
14+
<category>
1415
<label>Policy Administration</label>
15-
<content> Requests for policy changes, updates, or cancellations Questions about policy renewals and reinstatements Inquiries about adding or removing coverage options
16-
</content>
17-
</category>
18-
<category>
19-
<label>Claims Assistance</label>
20-
<content> Questions about the claims process and filing procedures Requests for help with submitting claim documentation Inquiries about claim status and payout timelines
21-
</content>
22-
</category>
23-
<category>
24-
<label>Coverage Explanations</label>
25-
<content> Questions about what is covered under specific policy types Requests for clarification on coverage limits and exclusions Inquiries about deductibles and out-of-pocket expenses
26-
</content>
27-
</category>
28-
<category>
29-
<label>Quotes and Proposals</label>
30-
<content> Requests for new policy quotes and price comparisons Questions about available discounts and bundling options Inquiries about switching from another insurer
31-
</content>
32-
</category>
33-
<category>
34-
<label>Account Management</label>
35-
<content> Requests for login credentials or password resets Questions about online account features and functionality Inquiries about updating contact or personal information
36-
</content>
37-
</category>
38-
<category>
39-
<label>Billing Disputes</label>
40-
<content> Complaints about unexpected or incorrect charges Requests for refunds or premium adjustments Inquiries about late fees or collection notices
41-
</content>
42-
</category>
43-
<category>
44-
<label>Claims Disputes</label>
45-
<content> Complaints about denied or underpaid claims Requests for reconsideration of claim decisions Inquiries about appealing a claim outcome
46-
</content>
47-
</category>
48-
<category>
49-
<label>Policy Comparisons</label>
50-
<content> Questions about the differences between policy options Requests for help deciding between coverage levels Inquiries about how policies compare to competitors' offerings
51-
</content>
52-
</category>
53-
<category>
54-
<label>General Inquiries</label>
55-
<content> Questions about company contact information or hours of operation Requests for general information about products or services Inquiries that don't fit neatly into other categories
56-
</content>
16+
<content> Requests for policy changes, updates, or cancellations Questions about policy renewals and reinstatements Inquiries about adding or removing coverage options
17+
</content>
18+
</category>
19+
<category>
20+
<label>Claims Assistance</label>
21+
<content> Questions about the claims process and filing procedures Requests for help with submitting claim documentation Inquiries about claim status and payout timelines
22+
</content>
23+
</category>
24+
<category>
25+
<label>Coverage Explanations</label>
26+
<content> Questions about what is covered under specific policy types Requests for clarification on coverage limits and exclusions Inquiries about deductibles and out-of-pocket expenses
27+
</content>
28+
</category>
29+
<category>
30+
<label>Quotes and Proposals</label>
31+
<content> Requests for new policy quotes and price comparisons Questions about available discounts and bundling options Inquiries about switching from another insurer
32+
</content>
33+
</category>
34+
<category>
35+
<label>Account Management</label>
36+
<content> Requests for login credentials or password resets Questions about online account features and functionality Inquiries about updating contact or personal information
37+
</content>
38+
</category>
39+
<category>
40+
<label>Billing Disputes</label>
41+
<content> Complaints about unexpected or incorrect charges Requests for refunds or premium adjustments Inquiries about late fees or collection notices
42+
</content>
43+
</category>
44+
<category>
45+
<label>Claims Disputes</label>
46+
<content> Complaints about denied or underpaid claims Requests for reconsideration of claim decisions Inquiries about appealing a claim outcome
47+
</content>
48+
</category>
49+
<category>
50+
<label>Policy Comparisons</label>
51+
<content> Questions about the differences between policy options Requests for help deciding between coverage levels Inquiries about how policies compare to competitors' offerings
52+
</content>
53+
</category>
54+
<category>
55+
<label>General Inquiries</label>
56+
<content> Questions about company contact information or hours of operation Requests for general information about products or services Inquiries that don't fit neatly into other categories
57+
</content>
5758
</category>"""
5859

5960

@@ -154,7 +155,7 @@ def rag_chain_of_thought_classify(context: dict):
154155
155156
First you will think step-by-step about the problem in scratchpad tags.
156157
You should consider all the information provided and create a concrete argument for your classification.
157-
158+
158159
Respond using this format:
159160
<response>
160161
<scratchpad>Your thoughts and analysis go here</scratchpad>

capabilities/classification/evaluation/vectordb.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import json
12
import os
3+
import pickle
4+
25
import numpy as np
36
import voyageai
4-
import pickle
5-
import json
67

78

89
class VectorDB:

0 commit comments

Comments
 (0)