97e91a83f3
Ruff / Ruff (push) Has been cancelled
Test / Core Tests (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.10) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.11) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.12) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.13) (push) Has been cancelled
Test / Offline Coverage Tests (Python 3.9) (push) Has been cancelled
Test / Full Coverage (Python 3.11) (push) Has been cancelled
Test / Core Provider Tests (OpenAI) (push) Has been cancelled
Test / Core Provider Tests (Anthropic) (push) Has been cancelled
Test / Core Provider Tests (Google) (push) Has been cancelled
Test / Core Provider Tests (Other) (push) Has been cancelled
Test / Anthropic Tests (push) Has been cancelled
Test / Gemini Tests (push) Has been cancelled
Test / Google GenAI Tests (push) Has been cancelled
Test / Vertex AI Tests (push) Has been cancelled
Test / OpenAI Tests (push) Has been cancelled
Test / Writer Tests (push) Has been cancelled
Test / Auto Client Tests (push) Has been cancelled
ty / type-check (push) Has been cancelled
50 lines
1.2 KiB
Python
50 lines
1.2 KiB
Python
"""VertexAI-specific tests for mixed content types.
|
|
|
|
Tests VertexAI's ability to handle mixed content with gm.Part objects.
|
|
"""
|
|
|
|
from itertools import product
|
|
from pydantic import BaseModel
|
|
import vertexai.generative_models as gm # type: ignore
|
|
import pytest
|
|
import instructor
|
|
|
|
from .util import models, modes
|
|
|
|
|
|
class Item(BaseModel):
|
|
name: str
|
|
price: float
|
|
|
|
|
|
class Order(BaseModel):
|
|
items: list[Item]
|
|
customer: str
|
|
|
|
|
|
@pytest.mark.parametrize("model, mode", product(models, modes))
|
|
def test_mixed_content_types(model, mode):
|
|
client = instructor.from_vertexai(gm.GenerativeModel(model), mode)
|
|
content = [
|
|
"Order Details:",
|
|
gm.Part.from_text("Customer: Alice"),
|
|
gm.Part.from_text("Items:"),
|
|
"Name: Laptop, Price: 999.99",
|
|
"Name: Mouse, Price: 29.99",
|
|
]
|
|
|
|
resp = client.create(
|
|
response_model=Order,
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": content,
|
|
},
|
|
],
|
|
)
|
|
|
|
assert len(resp.items) == 2
|
|
assert {x.name.lower() for x in resp.items} == {"laptop", "mouse"}
|
|
assert {x.price for x in resp.items} == {999.99, 29.99}
|
|
assert resp.customer.lower() == "alice"
|