Skip to content

Commit 7069a8e

Browse files
authored
Merge branch 'main' into feat/writer-json-mode
2 parents bd91ce9 + 58c3744 commit 7069a8e

18 files changed

Lines changed: 593 additions & 319 deletions

File tree

.github/workflows/claude.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude:
15+
if: |
16+
(contains(fromJSON('["jxnl","ivanleomk"]'), github.actor)) &&
17+
((github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
19+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
20+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))))
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
pull-requests: read
25+
issues: read
26+
id-token: write
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
32+
33+
- name: Run Claude Code
34+
id: claude
35+
uses: anthropics/claude-code-action@beta
36+
with:
37+
anthropic_api_key: ${{ secrets.CLAUDE_API_KEY }}

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,21 @@ repos:
88
files: ^(instructor|tests|examples)/
99
- id: ruff-format # Run the formatter.
1010
name: Run Formatter (Ruff)
11+
12+
- repo: local
13+
hooks:
14+
- id: uv-lock-check
15+
name: Check uv.lock is up-to-date
16+
entry: uv
17+
args: [lock, --check]
18+
language: system
19+
files: ^(pyproject\.toml|uv\.lock)$
20+
pass_filenames: false
21+
22+
- id: uv-sync-check
23+
name: Verify dependencies can be installed
24+
entry: uv
25+
args: [sync, --check]
26+
language: system
27+
files: ^(pyproject\.toml|uv\.lock)$
28+
pass_filenames: false

README.md

Lines changed: 31 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
# Instructor, The Most Popular Library for Simple Structured Outputs
22

3-
Instructor is the most popular Python library for working with structured outputs from large language models (LLMs), boasting over 1 million monthly downloads. Built on top of Pydantic, it provides a simple, transparent, and user-friendly API to manage validation, retries, and streaming responses. Get ready to supercharge your LLM workflows with the community's top choice!
3+
Instructor is the most popular Python library for working with structured outputs from large language models (LLMs), boasting over 3 million monthly downloads. Built on top of Pydantic, it provides a simple, transparent, and user-friendly API to manage validation, retries, and streaming responses. Get ready to supercharge your LLM workflows with the community's top choice!
44

5-
[![Twitter Follow](https://img.shields.io/twitter/follow/jxnlco?style=social)](https://twitter.com/jxnlco)
6-
[![Discord](https://img.shields.io/discord/1192334452110659664?label=discord)](https://discord.gg/bD9YE9JArw)
7-
[![Downloads](https://img.shields.io/pypi/dm/instructor.svg)](https://pypi.python.org/pypi/instructor)
5+
[![PyPI - Version](https://img.shields.io/pypi/v/instructor?style=flat-square&logo=pypi&logoColor=white&label=PyPI)](https://pypi.org/project/instructor/)
6+
[![License](https://img.shields.io/github/license/instructor-ai/instructor?style=flat-square&color=blue)](https://github.com/instructor-ai/instructor/blob/main/LICENSE)
7+
[![GitHub Repo stars](https://img.shields.io/github/stars/instructor-ai/instructor?style=flat-square&logo=github&logoColor=white)](https://github.com/instructor-ai/instructor)
8+
[![Downloads](https://img.shields.io/pypi/dm/instructor?style=flat-square&logo=pypi&logoColor=white&label=Downloads)](https://pypi.org/project/instructor/)
9+
[![Discord](https://img.shields.io/discord/1192334452110659664?style=flat-square&logo=discord&logoColor=white&label=Discord)](https://discord.gg/bD9YE9JArw)
10+
[![Twitter Follow](https://img.shields.io/twitter/follow/jxnlco?style=flat-square&logo=twitter&logoColor=white)](https://twitter.com/jxnlco)
811

912
## Want your logo on our website?
1013

@@ -23,10 +26,18 @@ If your company uses Instructor a lot, we'd love to have your logo on our websit
2326

2427
Install Instructor with a single command:
2528

29+
**Recommended (using uv):**
30+
```bash
31+
uv add instructor
32+
```
33+
34+
**Alternative (using pip):**
2635
```bash
2736
pip install -U instructor
2837
```
2938

39+
> **Note:** We recommend using [uv](https://github.com/astral-sh/uv) for faster package installation and better dependency resolution. If you're contributing to the project, uv is required for development.
40+
3041
Now, let's see Instructor in action with a simple example:
3142

3243
```python
@@ -207,7 +218,11 @@ assert resp.age == 25
207218

208219
Make sure to install `cohere` and set your system environment variable with `export CO_API_KEY=<YOUR_COHERE_API_KEY>`.
209220

210-
```
221+
```bash
222+
# Using uv (recommended)
223+
uv add cohere
224+
225+
# Using pip
211226
pip install cohere
212227
```
213228

@@ -247,7 +262,11 @@ assert resp.age == 25
247262
Make sure you [install](https://ai.google.dev/api/python/google/generativeai#setup) the Google AI Python SDK. You should set a `GOOGLE_API_KEY` environment variable with your API key.
248263
Gemini tool calling also requires `jsonref` to be installed.
249264

250-
```
265+
```bash
266+
# Using uv (recommended)
267+
uv add google-generativeai jsonref
268+
269+
# Using pip
251270
pip install google-generativeai jsonref
252271
```
253272

@@ -273,7 +292,11 @@ client = instructor.from_gemini(
273292

274293
Alternatively, you can [call Gemini from the OpenAI client](https://cloud.google.com/vertex-ai/generative-ai/docs/multimodal/call-gemini-using-openai-library#python). You'll have to setup [`gcloud`](https://cloud.google.com/docs/authentication/provide-credentials-adc#local-dev), get setup on Vertex AI, and install the Google Auth library.
275294

276-
```sh
295+
```bash
296+
# Using uv (recommended)
297+
uv add google-auth
298+
299+
# Using pip
277300
pip install google-auth
278301
```
279302

@@ -593,170 +616,4 @@ If you're new to the project, check out issues marked as [`good-first-issue`](ht
593616
```bash
594617
git clone https://github.com/YOUR-USERNAME/instructor.git
595618
cd instructor
596-
```
597-
598-
2. **Set up the development environment**
599-
600-
We use `uv` to manage dependencies, which provides faster package installation and dependency resolution than traditional tools. If you don't have `uv` installed, [install it first](https://github.com/astral-sh/uv).
601-
602-
```bash
603-
# Create and activate a virtual environment
604-
uv venv .venv
605-
source .venv/bin/activate # On Windows: .venv\Scripts\activate
606-
607-
# Install dependencies with all extras
608-
# You can specify specific groups if needed
609-
uv sync --all-extras --group dev
610-
611-
# Or for a specific integration
612-
# uv sync --all-extras --group dev,anthropic
613-
```
614-
615-
3. **Install pre-commit hooks**
616-
617-
We use pre-commit hooks to ensure code quality:
618-
619-
```bash
620-
uv pip install pre-commit
621-
pre-commit install
622-
```
623-
624-
This will automatically run Ruff formatters and linting checks before each commit, ensuring your code meets our style guidelines.
625-
626-
### Running Tests
627-
628-
Tests help ensure that your contributions don't break existing functionality:
629-
630-
```bash
631-
# Run all tests
632-
uv run pytest
633-
634-
# Run specific tests
635-
uv run pytest tests/path/to/test_file.py
636-
637-
# Run tests with coverage reporting
638-
uv run pytest --cov=instructor
639-
```
640-
641-
When submitting a PR, make sure to write tests for any new functionality and verify that all tests pass locally.
642-
643-
### Code Style and Quality Requirements
644-
645-
We maintain high code quality standards to keep the codebase maintainable and consistent:
646-
647-
- **Formatting and Linting**: We use `ruff` for code formatting and linting, and `pyright` for type checking.
648-
```bash
649-
# Check code formatting
650-
uv run ruff format --check
651-
652-
# Apply formatting
653-
uv run ruff format
654-
655-
# Run linter
656-
uv run ruff check
657-
658-
# Fix auto-fixable linting issues
659-
uv run ruff check --fix
660-
```
661-
662-
- **Type Hints**: All new code should include proper type hints.
663-
664-
- **Documentation**: Code should be well-documented with docstrings and comments where appropriate.
665-
666-
Make sure these checks pass when you submit a PR:
667-
- Linting: `uv run ruff check`
668-
- Formatting: `uv run ruff format`
669-
- Type checking: `uv run pyright`
670-
671-
### Development Workflow
672-
673-
1. **Create a branch for your changes**
674-
```bash
675-
git checkout -b feature/your-feature-name
676-
```
677-
678-
2. **Make your changes and commit them**
679-
```bash
680-
git add .
681-
git commit -m "Your descriptive commit message"
682-
```
683-
684-
3. **Keep your branch updated with the main repository**
685-
```bash
686-
git remote add upstream https://github.com/instructor-ai/instructor.git
687-
git fetch upstream
688-
git rebase upstream/main
689-
```
690-
691-
4. **Push your changes**
692-
```bash
693-
git push origin feature/your-feature-name
694-
```
695-
696-
### Pull Request Process
697-
698-
1. **Create a Pull Request** from your fork to the main repository.
699-
700-
2. **Fill out the PR template** with a description of your changes, relevant issue numbers, and any other information that would help reviewers understand your contribution.
701-
702-
3. **Address review feedback** and make any requested changes.
703-
704-
4. **Wait for CI checks** to pass. The PR will be reviewed by maintainers once all checks are green.
705-
706-
5. **Merge**: Once approved, a maintainer will merge your PR.
707-
708-
### Contributing to Evals
709-
710-
We encourage contributions to our evaluation tests. See the [Evals documentation](https://github.com/jxnl/instructor/tree/main/tests/llm/test_openai/evals#how-to-contribute-writing-and-running-evaluation-tests) for details on writing and running evaluation tests.
711-
712-
### Pre-commit Hooks
713-
714-
We use pre-commit hooks to ensure code quality. To set up pre-commit hooks:
715-
716-
1. Install pre-commit: `pip install pre-commit`
717-
2. Set up the hooks: `pre-commit install`
718-
719-
This will automatically run Ruff formatters and linting checks before each commit, ensuring your code meets our style guidelines.
720-
721-
## CLI
722-
723-
We also provide some added CLI functionality for easy convenience:
724-
725-
- `instructor jobs` : This helps with the creation of fine-tuning jobs with OpenAI. Simple use `instructor jobs create-from-file --help` to get started creating your first fine-tuned GPT-3.5 model
726-
727-
- `instructor files` : Manage your uploaded files with ease. You'll be able to create, delete and upload files all from the command line
728-
729-
- `instructor usage` : Instead of heading to the OpenAI site each time, you can monitor your usage from the CLI and filter by date and time period. Note that usage often takes ~5-10 minutes to update from OpenAI's side
730-
731-
## License
732-
733-
This project is licensed under the terms of the MIT License.
734-
735-
## Citation
736-
737-
If you use Instructor in your research, please cite it using the following BibTeX:
738-
739-
```bibtex
740-
@software{liu2024instructor,
741-
author = {Jason Liu and Contributors},
742-
title = {Instructor: A library for structured outputs from large language models},
743-
url = {https://github.com/instructor-ai/instructor},
744-
year = {2024},
745-
month = {3}
746-
}
747-
```
748-
749-
# Contributors
750-
751-
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
752-
<!-- prettier-ignore-start -->
753-
<!-- markdownlint-disable -->
754-
755-
<!-- markdownlint-restore -->
756-
<!-- prettier-ignore-end -->
757-
758-
<!-- ALL-CONTRIBUTORS-LIST:END -->
759-
760-
<a href="https://github.com/instructor-ai/instructor/graphs/contributors">
761-
<img src="https://contrib.rocks/image?repo=instructor-ai/instructor" />
762-
</a>
619+
```

docs/concepts/models.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Note that fields can also be omitted entirely from being sent to the language mo
5555
There are some occasions where it is desirable to create a model using runtime information to specify the fields. For this, Pydantic provides the create_model function to allow models to be created on the fly:
5656

5757
```python
58-
from pydantic import BaseModel, create_model
58+
from pydantic import BaseModel, create_model, Field
5959

6060

6161
class FooModel(BaseModel):
@@ -89,7 +89,7 @@ print(BarModel.model_fields.keys())
8989
We can then use this information to create the model.
9090

9191
```python
92-
from pydantic import BaseModel, create_model
92+
from pydantic import BaseModel, create_model, Field
9393
from typing import List
9494

9595
types = {
@@ -110,7 +110,7 @@ print(BarModel.model_fields.keys())
110110
BarModel = create_model(
111111
'User',
112112
**{
113-
property_name: (types[property_type], description)
113+
property_name: (types[property_type], Field(description=description))
114114
for property_name, property_type, description in cursor
115115
},
116116
__base__=BaseModel,
@@ -120,10 +120,10 @@ print(BarModel.model_fields.keys())
120120
"""
121121
{
122122
'properties': {
123-
'name': {'default': 'The name of the user.', 'title': 'Name', 'type': 'string'},
124-
'age': {'default': 'The age of the user.', 'title': 'Age', 'type': 'integer'},
123+
'name': {'description': 'The name of the user.', 'title': 'Name', 'type': 'string'},
124+
'age': {'description': 'The age of the user.', 'title': 'Age', 'type': 'integer'},
125125
'email': {
126-
'default': 'The email of the user.',
126+
'description': 'The email of the user.',
127127
'title': 'Email',
128128
'type': 'string',
129129
},

0 commit comments

Comments
 (0)