Support patching openai (#78)

* update docs

* add patch

* bump version
This commit is contained in:
Jason Liu
2023-08-17 01:25:29 +08:00
committed by GitHub
parent 0cb80886fa
commit 944366847f
7 changed files with 215 additions and 5 deletions
+23
View File
@@ -0,0 +1,23 @@
import openai
from pydantic import BaseModel
from openai_function_call import patch
# By default, the patch function will patch the ChatCompletion.create and ChatCompletion.acreate methods. to support response_model parameter
patch()
# Now, we can use the response_model parameter using only a base model
# rather than having to use the OpenAISchema class
class UserExtract(BaseModel):
name: str
age: int
user: UserExtract = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
response_model=UserExtract,
messages=[
{"role": "user", "content": "Extract jason is 25 years old"},
],
) # type: ignore
print(user)