Skip to content

Commit

Permalink
typos
Browse files Browse the repository at this point in the history
  • Loading branch information
jxnl committed Aug 24, 2023
1 parent 6d0a1a0 commit 3ca4f9b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 43 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,14 @@ In this updated schema, we use the `Field` class from `pydantic` to add descript
```python hl_lines="2 3"
class UserDetails(OpenAISchema):
"Correctly extracted user information"

name: str = Field(..., description="User's full name")
age: int

UserDetails.openai_schema
```

```json hl_lines="3 8"
```json
{
"name": "UserDetails",
"description": "Correctly extracted user information",
Expand Down Expand Up @@ -204,7 +205,7 @@ Including **autocompletion**:
![autocomplete](docs/img/ide_support.png)

And even **inline errors**
d

![errors](docs/img/error2.png)

## OpenAI Schema and Pydantic
Expand Down
80 changes: 39 additions & 41 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,60 +146,57 @@ Note that if the `Field` contains a description for a parameter as well as the d
!!! note "Code, schema, and prompt"
We can run `openai_schema` to see exactly what the API will see, notice how the docstrings, attributes, types, and parameter descriptions are now part of the schema. This describes on this library's core philosophies.

```python hl_lines="3 5 7"
class UserDetails(OpenAISchema):
"""
Correctly extracted user information
:param name: the user's full name
:param age: age of the user
"""
name: str = Field(..., description="User's full name")
age: int

UserDetails.openai_schema
```
```python
class UserDetails(OpenAISchema):
"""
Correctly extracted user information
```json hl_lines="3 9 13"
{
"name": "UserDetails",
"description": "Correctly extracted user information",
"parameters": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "User's full name"
},
"age": {
"type": "integer"
"description": "age of the user"
}
},
"required": [
"age",
"name"
]
}
:param name: the user's full name
:param age: age of the user
"""
name: str = Field(..., description="User's full name")
age: int

UserDetails.openai_schema
```

```json hl_lines="3 9 13"
{
"name": "UserDetails",
"description": "Correctly extracted user information",
"parameters": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "User's full name"
},
"age": {
"type": "integer"
"description": "age of the user"
}
```
},
"required": [
"age",
"name"
]
}
}
```

### Section 3: Calling the ChatCompletion

With the schema defined, let's proceed with calling the `ChatCompletion` API using the defined schema and messages.

```python hl_lines="11 12 15"
```python hl_lines="11 12"
from instructor import OpenAISchema
from pydantic import Field

class UserDetails(OpenAISchema):
"""
Correctly extracted user information
:param name: the user's full name
:param age: age of the user
"""
name: str = Field(..., description="User's full name")
age: int


completion = openai.ChatCompletion.create(
model="gpt-3.5-turbo-0613",
functions=[UserDetails.openai_schema],
Expand All @@ -219,8 +216,9 @@ Note that we have omitted the additional parameters that can be included in the

To deserialize the response from the `ChatCompletion` API back into an instance of the `UserDetails` class, we can use the `from_response` method.

```python hl_lines="1"
```python
user = UserDetails.from_response(completion)

print(user.name) # Output: John Doe
print(user.age) # Output: 30
```
Expand Down

0 comments on commit 3ca4f9b

Please sign in to comment.