This commit is contained in:
Jason Liu
2023-11-25 19:56:40 -05:00
parent 767b88c786
commit d3a567f2ff
10 changed files with 91 additions and 33 deletions
+8 -4
View File
@@ -8,11 +8,14 @@ from pydantic import BaseModel
client = instructor.patch(OpenAI())
class UserDetail(BaseModel):
name: str
age: int
cache = diskcache.Cache('./my_cache_directory')
cache = diskcache.Cache("./my_cache_directory")
def instructor_cache(func):
"""Cache a function that returns a Pydantic model"""
@@ -38,6 +41,7 @@ def instructor_cache(func):
return wrapper
@instructor_cache
def extract(data) -> UserDetail:
return client.chat.completions.create(
@@ -45,12 +49,12 @@ def extract(data) -> UserDetail:
response_model=UserDetail,
messages=[
{"role": "user", "content": data},
]
],
)
def test_extract():
import time
import time
start = time.perf_counter()
model = extract("Extract jason is 25 years old")
@@ -68,4 +72,4 @@ def test_extract():
if __name__ == "__main__":
test_extract()
# Time taken: 0.7285366660216823
# Time taken: 9.841693099588156e-05
# Time taken: 9.841693099588156e-05