mirror of
https://github.com/kennethreitz/instructor.git
synced 2026-06-05 22:50:18 +00:00
Migration to OpenAI 1.1.0 (#152)
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import openai
|
||||
import instructor
|
||||
|
||||
from openai import OpenAI
|
||||
from pydantic import BaseModel
|
||||
from instructor import patch
|
||||
|
||||
|
||||
# By default, the patch function will patch the ChatCompletion.create and ChatCompletion.acreate methods. to support response_model parameter
|
||||
patch()
|
||||
client = instructor.patch(OpenAI())
|
||||
|
||||
|
||||
# Now, we can use the response_model parameter using only a base model
|
||||
@@ -13,7 +15,7 @@ class UserExtract(BaseModel):
|
||||
age: int
|
||||
|
||||
|
||||
user: UserExtract = openai.ChatCompletion.create(
|
||||
user: UserExtract = client.chat.completions.create(
|
||||
model="gpt-3.5-turbo",
|
||||
response_model=UserExtract,
|
||||
messages=[
|
||||
@@ -22,3 +24,7 @@ user: UserExtract = openai.ChatCompletion.create(
|
||||
) # type: ignore
|
||||
|
||||
print(user)
|
||||
{
|
||||
"name": "Jason",
|
||||
"age": 25,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user