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

make test_openai generation tests skip if no OAI API key set #491

Merged
merged 1 commit into from
Feb 20, 2024
Merged
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
26 changes: 24 additions & 2 deletions tests/generators/test_openai.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: Copyright (c) 2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import os
import pytest

import openai

from garak.generators.openai import OpenAIGenerator

DEFAULT_GENERATIONS_QTY = 10


def test_completion():
def test_openai_version():
assert openai.__version__.split(".")[0] == "1" # expect openai module v1.x


@pytest.mark.skipif(
os.getenv("OPENAI_API_KEY", None) is None,
reason="OpenAI API key is not set in OPENAI_API_KEY",
)
def test_openai_completion():
generator = OpenAIGenerator(name="gpt-3.5-turbo-instruct")
assert generator.name == "gpt-3.5-turbo-instruct"
assert generator.generations == DEFAULT_GENERATIONS_QTY
Expand All @@ -19,7 +37,11 @@ def test_completion():
print("test passed!")


def test_chat():
@pytest.mark.skipif(
os.getenv("OPENAI_API_KEY", None) is None,
reason="OpenAI API key is not set in OPENAI_API_KEY",
)
def test_openai_chat():
generator = OpenAIGenerator(name="gpt-3.5-turbo")
assert generator.name == "gpt-3.5-turbo"
assert generator.generations == DEFAULT_GENERATIONS_QTY
Expand Down
Loading