You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Instructor, The Most Popular Library for Simple Structured Outputs
2
2
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!
@@ -23,10 +26,18 @@ If your company uses Instructor a lot, we'd love to have your logo on our websit
23
26
24
27
Install Instructor with a single command:
25
28
29
+
**Recommended (using uv):**
30
+
```bash
31
+
uv add instructor
32
+
```
33
+
34
+
**Alternative (using pip):**
26
35
```bash
27
36
pip install -U instructor
28
37
```
29
38
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
+
30
41
Now, let's see Instructor in action with a simple example:
31
42
32
43
```python
@@ -207,7 +218,11 @@ assert resp.age == 25
207
218
208
219
Make sure to install `cohere` and set your system environment variable with `export CO_API_KEY=<YOUR_COHERE_API_KEY>`.
209
220
210
-
```
221
+
```bash
222
+
# Using uv (recommended)
223
+
uv add cohere
224
+
225
+
# Using pip
211
226
pip install cohere
212
227
```
213
228
@@ -247,7 +262,11 @@ assert resp.age == 25
247
262
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.
248
263
Gemini tool calling also requires `jsonref` to be installed.
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.
275
294
276
-
```sh
295
+
```bash
296
+
# Using uv (recommended)
297
+
uv add google-auth
298
+
299
+
# Using pip
277
300
pip install google-auth
278
301
```
279
302
@@ -593,170 +616,4 @@ If you're new to the project, check out issues marked as [`good-first-issue`](ht
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**
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},
Copy file name to clipboardExpand all lines: docs/concepts/models.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ Note that fields can also be omitted entirely from being sent to the language mo
55
55
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:
56
56
57
57
```python
58
-
from pydantic import BaseModel, create_model
58
+
from pydantic import BaseModel, create_model, Field
0 commit comments