Test the n parameter with different values
(model=TEST_MODEL, n_values=[1, 2, 3])
| 15 | from test_utils import setup_test_env, get_test_client, TEST_MODEL |
| 16 | |
| 17 | def test_n_parameter(model=TEST_MODEL, n_values=[1, 2, 3]): |
| 18 | """ |
| 19 | Test the n parameter with different values |
| 20 | """ |
| 21 | # Set up test environment and get client |
| 22 | setup_test_env() |
| 23 | client = get_test_client() |
| 24 | |
| 25 | test_prompt = "Write a haiku about coding" |
| 26 | |
| 27 | for n in n_values: |
| 28 | print(f"\nTesting n={n} with model {model}") |
| 29 | print("-" * 50) |
| 30 | |
| 31 | try: |
| 32 | response = client.chat.completions.create( |
| 33 | model=model, |
| 34 | messages=[ |
| 35 | {"role": "system", "content": "You are a creative poet."}, |
| 36 | {"role": "user", "content": test_prompt} |
| 37 | ], |
| 38 | n=n, |
| 39 | temperature=0.8, |
| 40 | max_tokens=100 |
| 41 | ) |
| 42 | |
| 43 | # Check response structure |
| 44 | print(f"Response type: {type(response)}") |
| 45 | print(f"Number of choices: {len(response.choices)}") |
| 46 | |
| 47 | # Print all generated responses |
| 48 | for i, choice in enumerate(response.choices): |
| 49 | print(f"\nChoice {i+1}:") |
| 50 | print(choice.message.content) |
| 51 | |
| 52 | # Verify we got the expected number of responses |
| 53 | if len(response.choices) == n: |
| 54 | print(f"\n✅ SUCCESS: Got {n} responses as expected") |
| 55 | else: |
| 56 | print(f"\n❌ FAIL: Expected {n} responses, got {len(response.choices)}") |
| 57 | |
| 58 | except Exception as e: |
| 59 | print(f"\n❌ ERROR: {type(e).__name__}: {str(e)}") |
| 60 | |
| 61 | def main(): |
| 62 | """ |
no test coverage detected