0.3.0
Upgrading to openai 1.1.0
Usage
from openai import OpenAI()
import instructor
# Enables `response_model`
client = instructor.patch(OpenAI())
class UserDetail(BaseModel):
name: str
age: int
user = client.chat.completions.create(
model="gpt-3.5-turbo",
response_model=UserDetail,
messages=[
{"role": "user", "content": "Extract Jason is 25 years old"},
]
)
assert isinstance(user, UserDetail)
assert user.name == "Jason"
assert user.age == 25
note "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:
import openai
import instructor
instructor.patch()
user = openai.ChatCompletion.create(
...,
response_model=UserDetail,
)
What's Changed
- Migration to OpenAI 1.1.0 by @grit-app in #152
New Contributors
- @grit-app made their first contribution in #152
Full Changelog: 0.2.11...0.3.0