Usage
py hl_lines="5 13"
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:
python hl_lines="4 8"
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 https://github.com/jxnl/instructor/pull/152
New Contributors
* grit-app made their first contribution in https://github.com/jxnl/instructor/pull/152
**Full Changelog**: https://github.com/jxnl/instructor/compare/0.2.11...0.3.0