Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add LangSmith @unit test tracking #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ idna==3.7
iniconfig==2.0.0
inline-snapshot==0.8.0
instructor==1.2.0
langsmith==0.1.48
langsmith>=0.1.50,<0.2
markdown-it-py==3.0.0
mdurl==0.1.2
multidict==6.0.5
Expand Down
6 changes: 6 additions & 0 deletions tests/test_classification_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pydantic import BaseModel

import pytest
from langsmith import unit


class ClassifySpam(BaseModel):
Expand All @@ -19,6 +20,11 @@ class ClassifySpam(BaseModel):
@pytest.mark.asyncio_cooperative
@pytest.mark.parametrize("client, data", product(clients, data))
async def test_classification(client, data):
await check_classification(client, data)


@unit
async def check_classification(client, data):
input, expected = data
prediction = await client.create(
response_model=ClassifySpam,
Expand Down
5 changes: 5 additions & 0 deletions tests/test_retries.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pydantic import AfterValidator, BaseModel, Field
from typing import Annotated
from util import clients
from langsmith import unit


def uppercase_validator(v):
Expand Down Expand Up @@ -37,6 +38,10 @@ class UserDetail(BaseModel):
@pytest.mark.asyncio_cooperative
@pytest.mark.parametrize("client, data", product(clients, data))
async def test_retries(client, data):
await check_retries(client, data)

@unit
async def check_retries(client, data):
query, expected = data
response = await client.create(
response_model=UserDetail,
Expand Down
8 changes: 7 additions & 1 deletion tests/test_simple_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from openai import OpenAI
from pydantic import BaseModel, BeforeValidator, ValidationError

from langsmith import unit
import instructor
from instructor import llm_validator
from util import clients
Expand Down Expand Up @@ -36,6 +36,11 @@ class QuestionAnswerNoEvil(BaseModel):
@pytest.mark.asyncio_cooperative
@pytest.mark.parametrize("client, data", product(clients, data))
async def test_simple_validation(client, data):
await check_simple_validation(client, data)


@unit
async def check_simple_validation(client, data):
question, context = data

with pytest.raises(ValidationError):
Expand All @@ -53,3 +58,4 @@ async def test_simple_validation(client, data):
response_model=QuestionAnswerNoEvil,
max_retries=0,
)
return resp
6 changes: 6 additions & 0 deletions tests/test_vision_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from itertools import product
from util import clients
from instructor import AsyncInstructor
from langsmith import unit


def md_to_df(data: Any) -> Any:
Expand Down Expand Up @@ -63,6 +64,11 @@ class MultipleTables(BaseModel):
@pytest.mark.asyncio_cooperative
@pytest.mark.parametrize("client, url", product(clients, urls))
async def test_extract(client: AsyncInstructor, url: str):
await check_extract(client, url)


@unit
async def check_extract(client: AsyncInstructor, url: str):
if client.kwargs["model"] != "gpt-4-turbo":
pytest.skip("Only OpenAI supported for now, we need to support images for both")

Expand Down