From d61dcaf033f1244a7452788f7a7fefb8da3fdf37 Mon Sep 17 00:00:00 2001 From: Jason Liu Date: Fri, 9 Feb 2024 14:54:25 -0500 Subject: [PATCH 1/3] bump --- instructor/dsl/parallel.py | 3 ++- tests/openai/test_parallel.py | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/instructor/dsl/parallel.py b/instructor/dsl/parallel.py index c1756c75b..831c1c097 100644 --- a/instructor/dsl/parallel.py +++ b/instructor/dsl/parallel.py @@ -46,7 +46,8 @@ def from_response( def get_types_array(typehint: Type[Iterable[Union[T]]]) -> Tuple[Type[T], ...]: should_be_iterable = get_origin(typehint) - assert should_be_iterable is Iterable + if should_be_iterable is not Iterable: + raise TypeError(f"Model should be with Iterable instead if {typehint}") if get_origin(get_args(typehint)[0]) is Union: # works for Iterable[Union[int, str]] diff --git a/tests/openai/test_parallel.py b/tests/openai/test_parallel.py index 6f4b17b31..16e901503 100644 --- a/tests/openai/test_parallel.py +++ b/tests/openai/test_parallel.py @@ -14,6 +14,23 @@ class GoogleSearch(BaseModel): query: str +def test_sync_parallel_tools__error(client): + client = instructor.patch(client, mode=instructor.Mode.PARALLEL_TOOLS) + + with pytest.raises(TypeError): + resp = client.chat.completions.create( + model="gpt-4-turbo-preview", + messages=[ + {"role": "system", "content": "You must always use tools"}, + { + "role": "user", + "content": "What is the weather in toronto and dallas and who won the super bowl?", + }, + ], + response_model=Weather, + ) + + def test_sync_parallel_tools_or(client): client = instructor.patch(client, mode=instructor.Mode.PARALLEL_TOOLS) resp = client.chat.completions.create( From 59d987273321cbed28274240e65f734689bb0573 Mon Sep 17 00:00:00 2001 From: Jason Liu Date: Fri, 9 Feb 2024 15:00:42 -0500 Subject: [PATCH 2/3] bump config --- ellipsis.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ellipsis.yaml b/ellipsis.yaml index fdc51af6e..fbe251ea3 100644 --- a/ellipsis.yaml +++ b/ellipsis.yaml @@ -3,7 +3,7 @@ version: 1.1 pr_review: auto_review_enabled: true auto_summarize_pr: true - confidence_threshold: 0.9 + confidence_threshold: 0.85 rules: # Control what gets flagged during PR review with custom rules. Here are some to get you started: - "Code should be DRY (Dont Repeat Yourself)" @@ -13,3 +13,4 @@ pr_review: - "If library code changes, expect documentation to be updated" - "If library code changes, check if tests are updated" - "If a new `md` file is created in `docs` make sure its added to mkdocs.yml" + - "Assertions should always have an error message that is formatted well. " From 8ee5b5f3d4376485c373cba041007d806a36be86 Mon Sep 17 00:00:00 2001 From: Jason Liu Date: Fri, 9 Feb 2024 16:23:32 -0500 Subject: [PATCH 3/3] support better reasking --- instructor/patch.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/instructor/patch.py b/instructor/patch.py index e000d38e2..29c8a1ebd 100644 --- a/instructor/patch.py +++ b/instructor/patch.py @@ -339,9 +339,10 @@ async def retry_async( "name": response.choices[0] .message.tool_calls[0] .function.name, - "content": "failure", + "content": "Exceptions found\n{e}\nRecall the function correctly.", } ) + kwargs["messages"].append( { "role": "user",