test_prompt_validation.py 771 Bytes
Newer Older
1
2
3
4
5
6
# imports for guided decoding tests
import re

import openai
import pytest

7
from ...utils import RemoteOpenAIServer, models_path_prefix
8
9
10
11


@pytest.mark.asyncio
async def test_empty_prompt():
12
    model_name = os.path.join(models_path_prefix, "gpt2")
13
14
15
16
17
18
19
20
21
22
    server_args = ["--enforce-eager"]
    with RemoteOpenAIServer(model_name, server_args) as remote_server:
        client = remote_server.get_async_client()

        with pytest.raises(openai.BadRequestError,
                           match=re.compile('.+Prompt cannot be empty.+')):
            await client.completions.create(model=model_name,
                                            prompt="",
                                            max_tokens=5,
                                            temperature=0.0)