This commit is contained in:
Jason Liu
2023-11-09 09:22:47 -05:00
parent 669aea8ef1
commit 877f57a2ba
5 changed files with 6 additions and 17 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ Built to interact solely with openai's function calling api from python. It's de
## Usage
```py hl_lines="5 13"
from openai import OpenAI()
from openai import OpenAI
import instructor
# Enables `response_model`
+2 -8
View File
@@ -191,16 +191,10 @@ class OpenAISchema(BaseModel):
Returns:
cls (OpenAISchema): An instance of the class
"""
message = completion["choices"][0]["message"]
if throw_error:
assert "function_call" in message, "No function call detected"
assert (
message["function_call"]["name"] == cls.openai_schema["name"]
), "Function name does not match"
message = completion.choices[0].message
return cls.model_validate_json(
message["function_call"]["arguments"],
message.function_call.arguments,
context=validation_context,
strict=strict,
)
+2 -4
View File
@@ -122,7 +122,7 @@ def retry_sync(
None,
)
except (ValidationError, JSONDecodeError) as e:
kwargs["messages"].append(dict(**response.choices[0].message)) # type: ignore
kwargs["messages"].append(response.choices[0].message) # type: ignore
kwargs["messages"].append(
{
"role": "user",
@@ -139,7 +139,6 @@ def wrap_chatcompletion(func: Callable) -> Callable:
@wraps(func)
async def new_chatcompletion_async(
cls,
response_model=None,
validation_context=None,
max_retries=1,
@@ -161,7 +160,6 @@ def wrap_chatcompletion(func: Callable) -> Callable:
@wraps(func)
def new_chatcompletion_sync(
cls,
response_model=None,
validation_context=None,
max_retries=1,
@@ -183,7 +181,7 @@ def wrap_chatcompletion(func: Callable) -> Callable:
wrapper_function = new_chatcompletion_async if is_async else new_chatcompletion_sync
wrapper_function.__doc__ = OVERRIDE_DOCS
return classmethod(wrapper_function)
return wrapper_function
def patch(client):
+1 -1
View File
@@ -1,6 +1,6 @@
[tool.poetry]
name = "instructor"
version = "0.3.0"
version = "0.3.1"
description = "Helper functions that allow us to improve openai's function_call ergonomics"
authors = ["Jason Liu <jason@jxnl.co>"]
license = "MIT"
-3
View File
@@ -1,13 +1,11 @@
from pydantic import BaseModel
from openai import OpenAI
import pytest
import instructor
client = instructor.patch(OpenAI())
@pytest.mark.skip("Not implemented")
def test_runmodel():
class UserExtract(BaseModel):
name: str
@@ -27,7 +25,6 @@ def test_runmodel():
), "The raw response should be available from OpenAI"
@pytest.mark.skip("Not implemented")
def test_runmodel_validator():
from pydantic import field_validator