Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
njhill committed Jul 26, 2024
1 parent be83571 commit ba95f35
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tests/entrypoints/openai/test_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,28 @@ async def test_logits_bias(client: openai.AsyncOpenAI):
assert first_response != completion.choices[0].text


@pytest.mark.asyncio
async def test_allowed_token_ids(client: openai.AsyncOpenAI):
prompt = "Hello, my name is"
max_tokens = 1
tokenizer = get_tokenizer(tokenizer_name=MODEL_NAME)

# Test exclusive selection
allowed_ids = [1000, 1001, 1002]
completion = await client.completions.create(
model=MODEL_NAME,
prompt=prompt,
max_tokens=max_tokens,
temperature=0.0,
seed=42,
extra_body=dict(allowed_token_ids=allowed_ids, ),
)
response_tokens = tokenizer(completion.choices[0].text,
add_special_tokens=False)["input_ids"]
assert len(response_tokens) == 1
assert response_tokens[0] in allowed_ids


@pytest.mark.asyncio
@pytest.mark.parametrize("guided_decoding_backend",
["outlines", "lm-format-enforcer"])
Expand Down

0 comments on commit ba95f35

Please sign in to comment.