Skip to content

Commit

Permalink
Merge branch 'mh-latest' into mh-partial-enums
Browse files Browse the repository at this point in the history
  • Loading branch information
mwildehahn authored Dec 3, 2024
2 parents 692a8be + 12efd9c commit e25eee5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions instructor/dsl/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

T = TypeVar("T", bound=OpenAISchema)

class MissingToolCall(Exception):
def __init__(self, response: Any, *args: Any) -> None:
super().__init__(*args)
self.response = response


class ParallelBase:
def __init__(self, *models: type[OpenAISchema]):
Expand All @@ -37,6 +42,9 @@ def from_response(
#! We expect this from the OpenAISchema class, We should address
#! this with a protocol or an abstract class... @jxnlco
assert mode == Mode.PARALLEL_TOOLS, "Mode must be PARALLEL_TOOLS"
if not response.choices[0].message.tool_calls:
raise MissingToolCall(response)

for tool_call in response.choices[0].message.tool_calls:
name = tool_call.function.name
arguments = tool_call.function.arguments
Expand Down
1 change: 1 addition & 0 deletions tests/dsl/test_partial.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ def test_partial_enums():
assert partial_validated.i is not None
assert partial_validated.i.c is None


with pytest.raises(ValidationError):
partial.model_validate_json(partial_results)

Expand Down

0 comments on commit e25eee5

Please sign in to comment.