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
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
env:
PREDICTIONGUARD_API_KEY: ${{ secrets.PREDICTIONGUARD_API_KEY }}
PREDICTIONGUARD_URL: ${{ vars.PREDICTIONGUARD_URL }}
TEST_COMPLETIONS_MODEL: ${{ vars.TEST_COMPLETIONS_MODEL }}
TEST_CHAT_MODEL: ${{ vars.TEST_CHAT_MODEL }}
TEST_RESPONSES_MODEL: ${{ vars.TEST_RESPONSES_MODEL }}
TEST_TEXT_EMBEDDINGS_MODEL: ${{ vars.TEST_TEXT_EMBEDDINGS_MODEL }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
env:
PREDICTIONGUARD_API_KEY: ${{ secrets.PREDICTIONGUARD_API_KEY }}
PREDICTIONGUARD_URL: ${{ vars.PREDICTIONGUARD_URL }}
TEST_COMPLETIONS_MODEL: ${{ vars.TEST_COMPLETIONS_MODEL }}
TEST_CHAT_MODEL: ${{ vars.TEST_CHAT_MODEL }}
TEST_RESPONSES_MODEL: ${{ vars.TEST_RESPONSES_MODEL }}
TEST_TEXT_EMBEDDINGS_MODEL: ${{ vars.TEST_TEXT_EMBEDDINGS_MODEL }}
Expand Down
8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ dependencies = [
]

[tool.uv]
exclude-newer = "2026-04-16T12:33:43.000+00:00"
exclude-newer = "2026-05-08T12:33:43.000+00:00"

[tool.uv.pip]
require-hashes = true
Expand All @@ -35,11 +35,11 @@ Issues = "https://github.com/predictionguard/python-client/issues"
[project.optional-dependencies]
dev = [
"pytest==9.0.3",
"ruff==0.15.10",
"ruff==0.15.12",
"sphinx==9.1",
"sphinx-autodoc-typehints==3.10.2",
"sphinx_rtd_theme>=3.1.0",
"black>=26.3.1",
"sphinx_rtd_theme==3.1.0",
"black==26.3.1",
]

[tool.hatch.version]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_completions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def test_completions_create():
test_client = PredictionGuard()

response = test_client.completions.create(
model=os.environ["TEST_CHAT_MODEL"], prompt="Tell me a joke"
model=os.environ["TEST_COMPLETIONS_MODEL"], prompt="Tell me a joke"
)

assert len(response["choices"][0]["text"]) > 0
Expand All @@ -19,7 +19,7 @@ def test_completions_create_batch():
test_client = PredictionGuard()

response = test_client.completions.create(
model=os.environ["TEST_CHAT_MODEL"],
model=os.environ["TEST_COMPLETIONS_MODEL"],
prompt=["Tell me a joke.", "Tell me a cool fact."],
)

Expand All @@ -42,7 +42,7 @@ def test_completions_create_stream():

response_list = []
for res in test_client.completions.create(
model=os.environ["TEST_CHAT_MODEL"],
model=os.environ["TEST_COMPLETIONS_MODEL"],
prompt="Tell me a joke.",
stream=True,
):
Expand All @@ -61,7 +61,7 @@ def test_completions_create_stream_output_fail():
response_list = []
with pytest.raises(ValueError, match=streaming_error):
for res in test_client.completions.create(
model=os.environ["TEST_CHAT_MODEL"],
model=os.environ["TEST_COMPLETIONS_MODEL"],
prompt="Tell me a joke.",
stream=True,
output={"toxicity": True},
Expand Down
2 changes: 1 addition & 1 deletion tests/test_detokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_detokenize_create():
test_client = PredictionGuard()

response = test_client.detokenize.create(
model=os.environ["TEST_CHAT_MODEL"],
model=os.environ["TEST_COMPLETIONS_MODEL"],
tokens=[896, 686, 77651, 419, 914, 13]
)

Expand Down
230 changes: 115 additions & 115 deletions tests/test_responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,121 +47,121 @@ def test_responses_create_string():
#
# assert len(response_list) > 1


def test_responses_create_vision_image_file():
test_client = PredictionGuard()

response = test_client.responses.create(
model=os.environ["TEST_VISION_MODEL"],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{
"type": "input_image",
"image_url": "fixtures/test_image1.jpeg",
},
],
}
],
)

assert len(response["output"][0]["content"]) > 0


def test_responses_create_vision_image_url():
test_client = PredictionGuard()

response = test_client.responses.create(
model=os.environ["TEST_VISION_MODEL"],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{
"type": "input_image",
"image_url": "https://farm4.staticflickr.com/3300/3497460990_11dfb95dd1_z.jpg"
},
],
}
],
)

assert len(response["output"][0]["content"]) > 0


def test_responses_create_vision_image_b64():
test_client = PredictionGuard()

with open("fixtures/test_image1.jpeg", "rb") as image_file:
b64_image = base64.b64encode(image_file.read()).decode("utf-8")

response = test_client.responses.create(
model=os.environ["TEST_VISION_MODEL"],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{"type": "input_image", "image_url": b64_image},
],
}
],
)

assert len(response["output"][0]["content"]) > 0


def test_responses_create_vision_data_uri():
test_client = PredictionGuard()

with open("fixtures/test_image1.jpeg", "rb") as image_file:
b64_image = base64.b64encode(image_file.read()).decode("utf-8")

data_uri = "data:image/jpeg;base64," + b64_image

response = test_client.responses.create(
model=os.environ["TEST_VISION_MODEL"],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{"type": "input_image", "image_url": data_uri},
],
}
],
)

assert len(response["output"][0]["content"]) > 0


def test_responses_create_vision_stream_fail():
test_client = PredictionGuard()

streaming_error = "Streaming is not currently supported when using vision."

response_list = []
with pytest.raises(ValueError, match=streaming_error):
for res in test_client.responses.create(
model=os.environ["TEST_VISION_MODEL"],
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{
"type": "input_image",
"image_url": "fixtures/test_image1.jpeg",
},
],
}
],
stream=True,
):
response_list.append(res)
# Currently no responses image models supported
# def test_responses_create_vision_image_file():
# test_client = PredictionGuard()
#
# response = test_client.responses.create(
# model=os.environ["TEST_VISION_MODEL"],
# input=[
# {
# "role": "user",
# "content": [
# {"type": "input_text", "text": "What is in this image?"},
# {
# "type": "input_image",
# "image_url": "fixtures/test_image1.jpeg",
# },
# ],
# }
# ],
# )
#
# assert len(response["output"][0]["content"]) > 0
#
#
# def test_responses_create_vision_image_url():
# test_client = PredictionGuard()
#
# response = test_client.responses.create(
# model=os.environ["TEST_VISION_MODEL"],
# input=[
# {
# "role": "user",
# "content": [
# {"type": "input_text", "text": "What is in this image?"},
# {
# "type": "input_image",
# "image_url": "https://farm4.staticflickr.com/3300/3497460990_11dfb95dd1_z.jpg"
# },
# ],
# }
# ],
# )
#
# assert len(response["output"][0]["content"]) > 0
#
#
# def test_responses_create_vision_image_b64():
# test_client = PredictionGuard()
#
# with open("fixtures/test_image1.jpeg", "rb") as image_file:
# b64_image = base64.b64encode(image_file.read()).decode("utf-8")
#
# response = test_client.responses.create(
# model=os.environ["TEST_VISION_MODEL"],
# input=[
# {
# "role": "user",
# "content": [
# {"type": "input_text", "text": "What is in this image?"},
# {"type": "input_image", "image_url": b64_image},
# ],
# }
# ],
# )
#
# assert len(response["output"][0]["content"]) > 0
#
#
# def test_responses_create_vision_data_uri():
# test_client = PredictionGuard()
#
# with open("fixtures/test_image1.jpeg", "rb") as image_file:
# b64_image = base64.b64encode(image_file.read()).decode("utf-8")
#
# data_uri = "data:image/jpeg;base64," + b64_image
#
# response = test_client.responses.create(
# model=os.environ["TEST_VISION_MODEL"],
# input=[
# {
# "role": "user",
# "content": [
# {"type": "input_text", "text": "What is in this image?"},
# {"type": "input_image", "image_url": data_uri},
# ],
# }
# ],
# )
#
# assert len(response["output"][0]["content"]) > 0
#
#
# def test_responses_create_vision_stream_fail():
# test_client = PredictionGuard()
#
# streaming_error = "Streaming is not currently supported when using vision."
#
# response_list = []
# with pytest.raises(ValueError, match=streaming_error):
# for res in test_client.responses.create(
# model=os.environ["TEST_VISION_MODEL"],
# input=[
# {
# "role": "user",
# "content": [
# {"type": "input_text", "text": "What is in this image?"},
# {
# "type": "input_image",
# "image_url": "fixtures/test_image1.jpeg",
# },
# ],
# }
# ],
# stream=True,
# ):
# response_list.append(res)


def test_responses_create_tool_call():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_tokenize.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def test_tokenize_create():
test_client = PredictionGuard()

response = test_client.tokenize.create(
model=os.environ["TEST_CHAT_MODEL"],
model=os.environ["TEST_COMPLETIONS_MODEL"],
input="Tokenize this please."
)

Expand Down
Loading