mirror of
https://github.com/kennethreitz/instructor.git
synced 2026-06-05 22:50:18 +00:00
hotfix
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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
@@ -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
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user