Skip to content

Commit

Permalink
Fix documentation formatting issues:
Browse files Browse the repository at this point in the history
- Add spaces after comment markers in chain-of-density.md
- Fix string formatting in multimodal-gemini.md
- Standardize comment markers to '# >' in introducing-structured-outputs.md
- Update type annotation syntax for Python 3.7 compatibility in version-1.md
  • Loading branch information
devin-ai-integration[bot] committed Nov 24, 2024
1 parent 9b16a21 commit e2575b8
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 51 deletions.
15 changes: 7 additions & 8 deletions docs/blog/posts/chain-of-density.md
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,18 @@ In order to prevent any contamination of data during testing, we randomly sample

```py hl_lines="2 9 11 13-21 40 43"
from typing import List
from chain_of_density import summarize_article #(1)!
from chain_of_density import summarize_article # (1)!
import csv
import logging
import instructor
from pydantic import BaseModel
from openai import OpenAI

client = instructor.from_openai(OpenAI()) # (2)!
client = instructor.from_openai(OpenAI()) # (2)!

logging.basicConfig(level=logging.INFO) #(3)!
logging.basicConfig(level=logging.INFO) # (3)!

instructions = instructor.Instructions( #(4)!
instructions = instructor.Instructions( # (4)!
name="Chain Of Density",
finetune_format="messages",
# log handler is used to save the data to a file
Expand All @@ -432,18 +432,17 @@ class GeneratedSummary(BaseModel):
description="This represents the final summary generated that captures the meaning of the original article which is as concise as possible. ",
)

@instructions.distil #(4)!
@instructions.distil # (4)!
def distil_summarization(text: str) -> GeneratedSummary:
summary_chain: List[str] = summarize_article(text)
return GeneratedSummary(summary=summary_chain[-1]) #(5)!
return GeneratedSummary(summary=summary_chain[-1]) # (5)!

with open("train.csv", "r") as file:
reader = csv.reader(file)
next(reader) # Skip the header
for article, summary in reader:
# Run Distillisation to generate the values
distil_summarization(article)
```

1. In this example, we're using the summarize_article that we defined up above. We saved it in a local file called `chain_of_density.py`,
hence the import
Expand Down Expand Up @@ -547,4 +546,4 @@ Interestingly, the model finetuned with the least examples seems to outperform t

Finetuning this iterative method was 20-40x faster while improving overall performance, resulting in massive efficiency gains by finetuning and distilling capabilities into specialized models.

We've seen how `Instructor` can make your life easier, from data modeling to distillation and finetuning. If you enjoy the content or want to try out `instructor` check out the [github](https://github.com/jxnl/instructor) and don't forget to give us a star!
We've seen how `Instructor` can make your life easier, from data modeling to distillation and finetuning. If you enjoy the content or want to try out `instructor` check out the [github](https://github.com/jxnl/instructor) and don't forget to give us a star!
39 changes: 18 additions & 21 deletions docs/blog/posts/introducing-structured-outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,24 @@ with client.beta.chat.completions.stream(
for event in stream:
if event.type == "content.delta":
print(event.snapshot, flush=True, end="\n")
#>
#> {"
#> {"name
#> {"name":"
#> {"name":"Jason
#> {"name":"Jason","
#> {"name":"Jason","age
#> {"name":"Jason","age":
#> {"name":"Jason","age":25
#> {"name":"Jason","age":25}
# >
#> {"
#> {"name
#> {"name":"
#> {"name":"Jason
#> {"name":"Jason","
#> {"name":"Jason","age
#> {"name":"Jason","age":
#> {"name":"Jason","age":25
#> {"name":"Jason","age":25}
```
# > {"
# > {"name
# > {"name":"
# > {"name":"Jason
# > {"name":"Jason","
# > {"name":"Jason","age
# > {"name":"Jason","age":
# > {"name":"Jason","age":25
# > {"name":"Jason","age":25}
# > {"
# > {"name
# > {"name":"
# > {"name":"Jason
# > {"name":"Jason","
# > {"name":"Jason","age
# > {"name":"Jason","age":
# > {"name":"Jason","age":25
# > {"name":"Jason","age":25}

### Unpredictable Latency Spikes

Expand Down
27 changes: 15 additions & 12 deletions docs/blog/posts/multimodal-gemini.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,21 +87,24 @@ print(resp)

```python
Recomendations(
chain_of_thought='The video recommends visiting Takayama city, in the Hida Region, Gifu Prefecture. The
video suggests visiting the Miyagawa Morning Market, to try the Sarubobo good luck charms, and to enjoy the
cookie cup espresso, made by Koma Coffee. Then, the video suggests visiting a traditional Japanese Cafe,
called Kissako Katsure, and try their matcha and sweets. Afterwards, the video suggests to visit the Sanmachi
Historic District, where you can find local crafts and delicious foods. The video recommends trying Hida Wagyu
beef, at the Kin no Kotte Ushi shop, or to have a sit-down meal at the Kitchen Hida. Finally, the video
recommends visiting Shirakawa-go, a World Heritage Site in Gifu Prefecture.',
description='This video recommends a number of places to visit in Takayama city, in the Hida Region, Gifu
Prefecture. It shows some of the local street food and highlights some of the unique shops and restaurants in
the area.',
chain_of_thought=(
"The video recommends visiting Takayama city, in the Hida Region, Gifu Prefecture. "
"The video suggests visiting the Miyagawa Morning Market, to try the Sarubobo good luck charms, "
"and to enjoy the cookie cup espresso, made by Koma Coffee. Then, the video suggests visiting "
"a traditional Japanese Cafe, called Kissako Katsure, and try their matcha and sweets. "
"Afterwards, the video suggests to visit the Sanmachi Historic District, where you can find "
"local crafts and delicious foods. The video recommends trying Hida Wagyu beef, at the Kin "
"no Kotte Ushi shop, or to have a sit-down meal at the Kitchen Hida. Finally, the video "
"recommends visiting Shirakawa-go, a World Heritage Site in Gifu Prefecture."
),
description='This video recommends a number of places to visit in Takayama city, in the Hida Region, Gifu '
'Prefecture. It shows some of the local street food and highlights some of the unique shops and restaurants in '
'the area.',
destinations=[
TouristDestination(
name='Takayama',
description='Takayama is a city at the base of the Japan Alps, located in the Hida Region of
Gifu.',
description='Takayama is a city at the base of the Japan Alps, located in the Hida Region of '
'Gifu.',
location='Hida Region, Gifu Prefecture'
),
TouristDestination(
Expand Down
18 changes: 8 additions & 10 deletions docs/blog/posts/version-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ client = instructor.from_litellm(litellm.completion)

# all of these will route to the same underlying create function
# allow you to add instructor to try it out, while easily removing it
client.create(model="gpt-4", response_model=type[T]) -> T
client.chat.completions.create(model="gpt-4", response_model=type[T]) -> T
client.messages.create(model="gpt-4", response_model=type[T]) -> T
```
client.create(model="gpt-4", response_model=Type[T]) -> T
client.chat.completions.create(model="gpt-4", response_model=Type[T]) -> T
client.messages.create(model="gpt-4", response_model=Type[T]) -> T

## Type are infered correctly

Expand Down Expand Up @@ -214,12 +213,11 @@ for user in user_stream:
#> name='John' age=25
#> name='John Smith' age=25
#> name='John Smith' age=25
# name=None age=None
# name='' age=None
# name='John' age=None
# name='John Doe' age=None
# name='John Doe' age=30
```
#> name=None age=None
#> name='' age=None
#> name='John' age=None
#> name='John Doe' age=None
#> name='John Doe' age=30

Notice now that the type infered is `Generator[User, None]`

Expand Down

0 comments on commit e2575b8

Please sign in to comment.