Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Documentation #189

Merged
merged 3 commits into from
Nov 18, 2023
Merged

Improve Documentation #189

merged 3 commits into from
Nov 18, 2023

Conversation

jxnl
Copy link
Collaborator

@jxnl jxnl commented Nov 18, 2023

Address #185 #187

Summary by CodeRabbit

  • Documentation

    • Updated hyperlinks in the blog post about chain-of-density for better navigation.
    • Revised content in prompting concepts for clarity and consistency.
    • Enhanced reask validation documentation with clearer phrasing and updated references.
    • Added comprehensive contribution guidelines for the Instructor project.
    • Introduced a new "Getting Help" section with resources for the Instructor tool.
    • Overhauled the main documentation page to improve introduction and usage guidance.
    • Provided detailed installation instructions for the Instructor package.
    • Created a new explanatory document on the benefits and features of the Instructor library.
  • Chores

    • Removed the pytest dependency from the requirements, streamlining the package setup.
  • Refactor

    • Removed specific code examples from documentation to focus on conceptual explanations.

Copy link
Contributor

coderabbitai bot commented Nov 18, 2023

Warning

Rate Limit Exceeded

@jxnl has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 15 minutes and 15 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between d3be207 and 295dc73.
## Walkthrough
The documentation for the "Instructor" project has undergone a series of updates. Changes include hyperlink updates, text content revisions, code logic alterations, and the addition of new sections and guidelines. The focus seems to be on improving clarity, enhancing user guidance, and streamlining information about the Instructor tool and its integration with Pydantic and OpenAI.

## Changes

| File Path | Change Summary |
|-----------|----------------|
| `docs/blog/posts/chain-of-density.md` | Updated hyperlinks to new relative paths. |
| `docs/concepts/prompting.md` <br> `docs/concepts/reask_validation.md` | Text content revisions, code logic changes, and updated references. |
| `docs/contributing.md` <br> `docs/help.md` | Added new sections for contribution guidelines and getting help. |
| `docs/index.md` <br> `docs/why.md` | Significant content rephrasing, new sections added, and removal of specific code examples. |
| `docs/installation.md` | Added installation instructions for the "instructor" package. |
| `requirements.txt` | Removed `pytest` dependency. |

> 🐇 In the brisk November air, we hop and tweak, 🍂  
> Code and docs align, as the updates peak. 📝  
> With each commit and push, our project grows,  
> A symphony of changes, in the code it shows. 🎶

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@jxnl jxnl merged commit 1aca756 into main Nov 18, 2023
@jxnl jxnl deleted the reoganize-docs branch November 18, 2023 20:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 556d36a and c3a307e.
Files ignored due to filter (1)
  • mkdocs.yml
Files selected for processing (9)
  • docs/blog/posts/chain-of-density.md (2 hunks)
  • docs/concepts/prompting.md (4 hunks)
  • docs/concepts/reask_validation.md (3 hunks)
  • docs/contributing.md (1 hunks)
  • docs/help.md (1 hunks)
  • docs/index.md (3 hunks)
  • docs/installation.md (1 hunks)
  • docs/why.md (1 hunks)
  • requirements.txt (1 hunks)
Files skipped from review due to trivial changes (6)
  • docs/blog/posts/chain-of-density.md
  • docs/concepts/reask_validation.md
  • docs/contributing.md
  • docs/help.md
  • docs/installation.md
  • requirements.txt
Additional comments: 12
docs/concepts/prompting.md (3)
  • 1-4: The introduction of the document sets the stage for the use of Instructor and Pydantic, emphasizing modularity and self-description. The changes here seem to be focused on improving the clarity of the documentation.

  • 37-40: The removal of the role field and its replacement with an Optional[str] type indicates a change in the model's design. This change should be verified across the codebase to ensure that all references to the role field are updated accordingly. Additionally, the use of Optional aligns with the best practice of explicitly handling nullable fields.

  • 135-138: The change from a properties field to a List[Property] indicates a shift from a single property to handling multiple properties. This is a logical change that enhances the model's flexibility in handling various user attributes. However, it's crucial to ensure that the code consuming this model is updated to iterate over the list of properties instead of accessing a single property.

docs/index.md (3)
  • 1-16: The introduction has been rephrased to be more engaging and informative. The addition of badges for Pydantic, Twitter, downloads, GitHub stars, documentation, and issues provides quick access to relevant resources and social proof, which can be beneficial for the project's visibility and credibility.

  • 69-81: The "Why use Instructor?" section succinctly outlines the benefits of using Instructor with Pydantic, emphasizing ease of use, integration with OpenAI's API, customizability, ecosystem support, and reliability. This section effectively communicates the value proposition of Instructor.

  • 85-87: The reference to the "cookbook" for more examples is a good way to keep the main documentation page clean while still providing users with the resources to learn more. The installation instruction is concise and clear.

docs/why.md (6)
  • 1-19: The introduction to the "Why use Instructor?" section provides a good overview of the benefits of using Pydantic, which is relevant to understanding the value proposition of the Instructor library. The bullet points are informative and concise.

  • 21-25: The enhancements introduced by the instructor.patch are clearly listed and seem to add valuable functionality to the OpenAI class. It's important to ensure that these features are well-documented elsewhere in the documentation so that users can understand how to use them effectively.

  • 30-30: The hyperlink provided should be verified to ensure it points to the correct URL and that the content is live and relevant to the topic of validators.

  • 52-62: Defining a Pydantic model is well-explained, and the example is straightforward. This should help users understand how to map their data to a model.

  • 66-80: The code snippet demonstrates how to use the patched OpenAI client with a Pydantic model. The comments are helpful, but it would be good to ensure that the client.chat.completions.create method is correctly implemented in the instructor library and that it supports the response_model parameter as shown.

  • 117-149: The self-correcting mechanism is an interesting feature. The example provided shows how to handle validation errors and retry the request. It's important to ensure that the max_retries parameter is implemented and works as expected in the instructor library.

Comment on lines 118 to 121
age: int
name: str
role: Role

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing the role field with a Role field that references a Role class is a significant change. This introduces a new level of abstraction and should be checked for consistency across the codebase. It's important to ensure that all functions and methods that interact with the UserDetail class are updated to handle this new structure.

docs/index.md Outdated
Comment on lines 41 to 46
assert user.age == 25
```

**"Using `openai<1.0.0`"**

If you're using `openai<1.0.0` then make sure you `pip install instructor<0.3.0`
where you can patch a global client like so:

```python hl_lines="4 8"
import openai
import instructor

instructor.patch()

user = openai.ChatCompletion.create(
...,
response_model=UserDetail,
)
```

**"Using async clients"**
**Using async clients**

For async clients you must use apatch vs patch like so:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code example provided is clear and demonstrates the usage of Instructor with synchronous code. However, the comment about using apatch for async clients is introduced abruptly. It would be beneficial to either include a full async example here or refer to a section where such an example is provided.

docs/why.md Outdated
Comment on lines +36 to +50
Lets go over the `patch` function. And see how we can leverage it to make use of instructor

### 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.

```python
import instructor
from openai import OpenAI
from pydantic import BaseModel

# This enables response_model keyword
# from client.chat.completions.create
client = instructor.patch(OpenAI())
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explanation of the patch function is clear, but it would be beneficial to include a brief description of what the response_model keyword does and how it enhances the functionality of the OpenAI class.

docs/why.md Outdated
Comment on lines +84 to +105
Validation can also be plugged into the same Pydantic model. Here, if the answer attribute contains content that violates the rule "don't say objectionable things," Pydantic will raise a validation error.

```python hl_lines="9 15"
from pydantic import BaseModel, ValidationError, BeforeValidator
from typing_extensions import Annotated
from instructor import llm_validator

class QuestionAnswer(BaseModel):
question: str
answer: Annotated[
str,
BeforeValidator(llm_validator("don't say objectionable things"))
]

try:
qa = QuestionAnswer(
question="What is the meaning of life?",
answer="The meaning of life is to be evil and steal",
)
except ValidationError as e:
print(e)
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation example is useful for showing how custom validators can be integrated with Pydantic models. However, the highlighted lines in the code snippet (86) do not match the Python syntax and should be removed or corrected.

- ```python hl_lines="9 15"
+ ```python

docs/why.md Outdated
Comment on lines +107 to +113
Its important to not here that the error message is generated by the LLM, not the code, so it'll be helpful for re asking the model.

```plaintext
1 validation error for QuestionAnswer
answer
Assertion failed, The statement is objectionable. (type=assertion_error)
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note about the error message being generated by the LLM (Language Learning Model) is insightful, but it should be clarified that the error message is a result of the validation logic defined in the Pydantic model, not directly from the LLM.

docs/why.md Outdated
assert model.name == "JASON"
```

As you can see, we've baked in a self correcting mechanism into the model. This is a powerful way to make your models more robust and less brittle without include a lot of extra code or prompt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conclusion emphasizes the robustness and simplicity that the Instructor library brings to model validation. It's a strong selling point, but it would be beneficial to have more detailed documentation or examples on how the self-correcting mechanism works in practice.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c3a307e and d3be207.
Files selected for processing (1)
  • docs/index.md (3 hunks)
Files skipped from review due to trivial changes (1)
  • docs/index.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant