Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions instructor/providers/anthropic/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from textwrap import dedent
from typing import Any, TypedDict, Union

from pydantic import ValidationError

Check failure on line 12 in instructor/providers/anthropic/utils.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (F401)

instructor/providers/anthropic/utils.py:12:22: F401 `pydantic.ValidationError` imported but unused

Check failure on line 12 in instructor/providers/anthropic/utils.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (F401)

instructor/providers/anthropic/utils.py:12:22: F401 `pydantic.ValidationError` imported but unused
from ...core.exceptions import ValidationError as InstructorValidationError

Check failure on line 13 in instructor/providers/anthropic/utils.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (F401)

instructor/providers/anthropic/utils.py:13:51: F401 `...core.exceptions.ValidationError` imported but unused

Check failure on line 13 in instructor/providers/anthropic/utils.py

View workflow job for this annotation

GitHub Actions / Ruff

Ruff (F401)

instructor/providers/anthropic/utils.py:13:51: F401 `...core.exceptions.ValidationError` imported but unused

from ...mode import Mode
from ...processing.schema import generate_anthropic_schema
Expand Down Expand Up @@ -156,11 +156,7 @@
tool_use_id = None
for content in response.content:
assistant_content.append(content.model_dump()) # type: ignore
if (
content.type == "tool_use"
and isinstance(exception, (ValidationError, InstructorValidationError))
and content.name == exception.title
):
if content.type == "tool_use":
tool_use_id = content.id

reask_msgs = [{"role": "assistant", "content": assistant_content}] # type: ignore
Expand Down
7 changes: 6 additions & 1 deletion instructor/providers/gemini/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,15 @@ def update_genai_kwargs(

# Filter out image related harm categories which are not
# supported for text based models
# Exclude JAILBREAK category as it's only for Vertex AI, not google.genai
excluded_categories = {HarmCategory.HARM_CATEGORY_UNSPECIFIED}
if hasattr(HarmCategory, 'HARM_CATEGORY_JAILBREAK'):
excluded_categories.add(HarmCategory.HARM_CATEGORY_JAILBREAK)

supported_categories = [
c
for c in HarmCategory
if c != HarmCategory.HARM_CATEGORY_UNSPECIFIED
if c not in excluded_categories
and not c.name.startswith("HARM_CATEGORY_IMAGE_")
]

Expand Down
14 changes: 12 additions & 2 deletions tests/llm/test_genai/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ def test_update_genai_kwargs_safety_settings():
"""Test that safety settings are properly configured."""
from google.genai.types import HarmCategory, HarmBlockThreshold

# Exclude JAILBREAK category as it's only for Vertex AI, not google.genai
excluded_categories = {HarmCategory.HARM_CATEGORY_UNSPECIFIED}
if hasattr(HarmCategory, 'HARM_CATEGORY_JAILBREAK'):
excluded_categories.add(HarmCategory.HARM_CATEGORY_JAILBREAK)

supported_categories = [
c
for c in HarmCategory
if c != HarmCategory.HARM_CATEGORY_UNSPECIFIED
if c not in excluded_categories
and not c.name.startswith("HARM_CATEGORY_IMAGE_")
]

Expand Down Expand Up @@ -65,10 +70,15 @@ def test_update_genai_kwargs_with_custom_safety_settings():
"""Test that custom safety settings are properly handled."""
from google.genai.types import HarmCategory, HarmBlockThreshold

# Exclude JAILBREAK category as it's only for Vertex AI, not google.genai
excluded_categories = {HarmCategory.HARM_CATEGORY_UNSPECIFIED}
if hasattr(HarmCategory, 'HARM_CATEGORY_JAILBREAK'):
excluded_categories.add(HarmCategory.HARM_CATEGORY_JAILBREAK)

supported_categories = [
c
for c in HarmCategory
if c != HarmCategory.HARM_CATEGORY_UNSPECIFIED
if c not in excluded_categories
and not c.name.startswith("HARM_CATEGORY_IMAGE_")
]

Expand Down
Loading