Skip to content

Commit

Permalink
Merge branch 'main' into tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl authored Nov 18, 2023
2 parents 9774df5 + c48f8e7 commit 90d8a8c
Show file tree
Hide file tree
Showing 39 changed files with 1,876 additions and 761 deletions.
74 changes: 43 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,37 @@
# Getting Started with Instructor
# Welcome to Instructor - Your Gateway to Structured Outputs with OpenAI

_Structured extraction in Python, powered by OpenAI's function calling api, designed for simplicity, transparency, and control._

---

[Star us on Github!](https://jxnl.github.io/instructor).
[Star us on Github!](www.github.com/jxnl/instructor).

[![Buy Me a Coffee](https://img.shields.io/badge/Buy%20Me%20a%20Coffee-Donate-yellow)](https://www.buymeacoffee.com/jxnlco)
[![Pydantic v2](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/pydantic/pydantic/main/docs/badge/v2.json)](https://pydantic.dev)
[![Downloads](https://img.shields.io/pypi/dm/instructor.svg)](https://pypi.python.org/pypi/instructor)
[![GitHub stars](https://img.shields.io/github/stars/jxnl/instructor.svg)](https://github.com/jxnl/instructor/stargazers)
[![Documentation](https://img.shields.io/badge/docs-available-brightgreen)](https://jxnl.github.io/instructor)
[![Twitter Follow](https://img.shields.io/twitter/follow/jxnlco?style=social)](https://twitter.com/jxnlco)
[![GitHub issues](https://img.shields.io/github/issues/jxnl/instructor.svg)](https://github.com/jxnl/instructor/issues)
[![GitHub license](https://img.shields.io/github/license/jxnl/instructor.svg)](https://github.com/jxnl/instructor/blob/main/LICENSE)
[![Github discussions](https://img.shields.io/github/discussions/jxnl/instructor)](https:github.com/jxnl/instructor/discussions)
[![PyPI version](https://img.shields.io/pypi/v/instructor.svg)](https://pypi.python.org/pypi/instructor)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/instructor.svg)](https://pypi.python.org/pypi/instructor)

Built to interact solely with openai's function calling api from python. It's designed to be intuitive, easy to use, and provide great visibility into your prompts.
Dive into the world of Python-based structured extraction, empowered by OpenAI's cutting-edge function calling API. Instructor stands out for its simplicity, transparency, and user-centric design. Whether you're a seasoned developer or just starting out, you'll find Instructor's approach intuitive and its results insightful.

## Get Started in Moments

Installing Instructor is a breeze. Just run `pip install instructor` in your terminal and you're on your way to a smoother data handling experience.

## How Instructor Enhances Your Workflow

Our `instructor.patch` for the `OpenAI` class introduces three key enhancements:

- **Response Mode:** Specify a Pydantic model to streamline data extraction.
- **Max Retries:** Set your desired number of retry attempts for requests.
- **Validation Context:** Provide a context object for enhanced validator access.
A Glimpse into Instructor's Capabilities

!!! note "Using Validators"

Learn more about validators checkout our blog post [Good llm validation is just good validation](https://jxnl.github.io/instructor/blog/2023/10/23/good-llm-validation-is-just-good-validation/)

With Instructor, your code becomes more efficient and readable. Here’s a quick peek:

## Usage

Expand Down Expand Up @@ -87,27 +101,6 @@ model = await aclient.chat.completions.create(
assert isinstance(model, UserExtract)
```

## Installation

To get started you need to install it using `pip`. Run the following command in your terminal:

```sh
$ pip install instructor
```

## Quick Start

To simplify your work with OpenAI we offer a patching mechanism for the `ChatCompletion` class.
The patch introduces 3 features to the `ChatCompletion` class:

1. The `response_model` parameter, which allows you to specify a Pydantic model to extract data into.
2. The `max_retries` parameter, which allows you to specify the number of times to retry the request if it fails.
3. The `validation_context` parameter, which allows you to specify a context object that validators have access to.

!!! note "Using Validators"

Learn more about validators checkout our blog post [Good llm validation is just good validation](https://jxnl.github.io/instructor/blog/2023/10/23/good-llm-validation-is-just-good-validation/)

### Step 1: Patch the client

First, import the required libraries and apply the patch function to the OpenAI module. This exposes new functionality with the response_model parameter.
Expand Down Expand Up @@ -190,9 +183,9 @@ answer
Here, the `UserDetails` model is passed as the `response_model`, and `max_retries` is set to 2.

```python
from openai import OpenAI
import instructor

from openai import OpenAI
from pydantic import BaseModel, field_validator

# Apply the patch to the OpenAI client
Expand Down Expand Up @@ -221,6 +214,25 @@ model = client.chat.completions.create(
assert model.name == "JASON"
```

## Contributing

If you want to help out checkout some of the issues marked as `good-first-issue` or `help-wanted`. Found [here](https://github.com/jxnl/instructor/labels/good%20first%20issue). They could be anything from code improvements, a guest blog post, or a new cook book.

## License

This project is licensed under the terms of the MIT License.

# Contributors

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->

<a href="https://github.com/jxnl/instructor/graphs/contributors">
<img src="https://contrib.rocks/image?repo=jxnl/instructor" />
</a>
102 changes: 0 additions & 102 deletions blog.md

This file was deleted.

18 changes: 18 additions & 0 deletions docs/blog/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Welcome to the Instructor Blog

The goal of the blog is to capture some content that does not neatly fit within documentation or the cookbooks.

## Advanced Topics

- [Query Understanding and Expansion for RAG](posts/rag-and-beyond.md)
- [GPT-4 Level summarization with GPT3.5 Finetuning](posts/chain-of-density.md)
- [Deepdive on LLM Guardrails / Validation](posts/validation-part1.md)
- [A Guide to Fine-Tuning and Distillation](posts/distilation-part1.md)

## Learning Python

- [Understanding Batch Processing with async](posts/learn-async.md)

## Talks

- [AI Engineering Summit 2023](posts/aisummit-2023.md)
Loading

0 comments on commit 90d8a8c

Please sign in to comment.