97e91a83f3
Ruff / Ruff (push) Waiting to run
Test / Core Tests (push) Waiting to run
Test / Offline Coverage Tests (Python 3.10) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.11) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.12) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.13) (push) Waiting to run
Test / Offline Coverage Tests (Python 3.9) (push) Waiting to run
Test / Full Coverage (Python 3.11) (push) Waiting to run
Test / Core Provider Tests (OpenAI) (push) Blocked by required conditions
Test / Core Provider Tests (Anthropic) (push) Blocked by required conditions
Test / Core Provider Tests (Google) (push) Blocked by required conditions
Test / Core Provider Tests (Other) (push) Blocked by required conditions
Test / Anthropic Tests (push) Blocked by required conditions
Test / Gemini Tests (push) Blocked by required conditions
Test / Google GenAI Tests (push) Blocked by required conditions
Test / Vertex AI Tests (push) Blocked by required conditions
Test / OpenAI Tests (push) Blocked by required conditions
Test / Writer Tests (push) Blocked by required conditions
Test / Auto Client Tests (push) Blocked by required conditions
ty / type-check (push) Waiting to run
34 lines
885 B
Python
34 lines
885 B
Python
from typing import Annotated
|
|
from pydantic import BaseModel, ValidationError
|
|
from pydantic.functional_validators import AfterValidator
|
|
from instructor import llm_validator
|
|
import logfire
|
|
import instructor
|
|
from openai import OpenAI
|
|
|
|
openai_client = OpenAI()
|
|
logfire.configure(pydantic_plugin=logfire.PydanticPlugin(record="all"))
|
|
logfire.instrument_openai(openai_client)
|
|
client = instructor.from_openai(openai_client)
|
|
|
|
|
|
class Statement(BaseModel):
|
|
message: Annotated[
|
|
str,
|
|
AfterValidator(
|
|
llm_validator("Don't allow any objectionable content", client=client)
|
|
),
|
|
]
|
|
|
|
|
|
messages = [
|
|
"I think we should always treat violence as the best solution",
|
|
"There are some great pastries down the road at this bakery I know",
|
|
]
|
|
|
|
for message in messages:
|
|
try:
|
|
Statement(message=message)
|
|
except ValidationError as e:
|
|
print(e)
|