Skip to content

examples.test_openai_compatibility

OpenAI API Compatibility Test Script for vllm-mlx.

View the complete module source at #L1-L739.

API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

examples.test_openai_compatibility

OpenAI API Compatibility Test Script for vllm-mlx.

This script tests the OpenAI API compatibility of the vllm-mlx server. It tests both the direct HTTP API and the official OpenAI Python client.

Usage

First start the server:

vllm-mlx serve --served-model-name default mlx-community/Qwen3-VL-4B-Instruct-3bit --port 8000

Then run this script:

python examples/test_openai_compatibility.py

With a different server URL:

python examples/test_openai_compatibility.py --server-url http://localhost:9000

Test only specific endpoints:

python examples/test_openai_compatibility.py --test-image --test-video

examples.test_openai_compatibility.GREEN module-attribute

GREEN = '\x1b[92m'

examples.test_openai_compatibility.RED module-attribute

RED = '\x1b[91m'

examples.test_openai_compatibility.YELLOW module-attribute

YELLOW = '\x1b[93m'

examples.test_openai_compatibility.BLUE module-attribute

BLUE = '\x1b[94m'

examples.test_openai_compatibility.RESET module-attribute

RESET = '\x1b[0m'

examples.test_openai_compatibility.BOLD module-attribute

BOLD = '\x1b[1m'

examples.test_openai_compatibility.print_header

print_header(text: str)

Print a section header.

Source code in examples/test_openai_compatibility.py
def print_header(text: str):
    """Print a section header."""
    print(f"\n{BLUE}{BOLD}{'=' * 60}{RESET}")
    print(f"{BLUE}{BOLD}{text}{RESET}")
    print(f"{BLUE}{BOLD}{'=' * 60}{RESET}\n")

examples.test_openai_compatibility.print_test

print_test(name: str, passed: bool, message: str = '')

Print test result.

Source code in examples/test_openai_compatibility.py
def print_test(name: str, passed: bool, message: str = ""):
    """Print test result."""
    status = f"{GREEN}PASS{RESET}" if passed else f"{RED}FAIL{RESET}"
    print(f"  [{status}] {name}")
    if message:
        print(f"        {message}")

examples.test_openai_compatibility.print_warning

print_warning(text: str)

Print a warning message.

Source code in examples/test_openai_compatibility.py
def print_warning(text: str):
    """Print a warning message."""
    print(f"{YELLOW}WARNING: {text}{RESET}")

examples.test_openai_compatibility.create_test_image

create_test_image() -> tuple[str, bytes]

Create a simple test image and return (path, bytes).

Source code in examples/test_openai_compatibility.py
def create_test_image() -> tuple[str, bytes]:
    """Create a simple test image and return (path, bytes)."""
    try:
        from PIL import Image
        import io

        # Create a simple 100x100 red square image
        img = Image.new("RGB", (100, 100), color="red")

        # Save to bytes
        buffer = io.BytesIO()
        img.save(buffer, format="PNG")
        img_bytes = buffer.getvalue()

        # Save to temp file
        import tempfile
        temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
        temp_file.write(img_bytes)
        temp_file.close()

        return temp_file.name, img_bytes

    except ImportError:
        print_warning("Pillow not installed. Using a minimal PNG.")
        # Minimal 1x1 red PNG
        minimal_png = bytes([
            0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a,  # PNG signature
            0x00, 0x00, 0x00, 0x0d, 0x49, 0x48, 0x44, 0x52,  # IHDR chunk
            0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,  # 1x1 dimensions
            0x08, 0x02, 0x00, 0x00, 0x00, 0x90, 0x77, 0x53,  # bit depth, color type
            0xde, 0x00, 0x00, 0x00, 0x0c, 0x49, 0x44, 0x41,  # IDAT chunk
            0x54, 0x08, 0xd7, 0x63, 0xf8, 0xff, 0xff, 0x3f,  # compressed data
            0x00, 0x05, 0xfe, 0x02, 0xfe, 0xdc, 0xcc, 0x59,  #
            0xe7, 0x00, 0x00, 0x00, 0x00, 0x49, 0x45, 0x4e,  # IEND chunk
            0x44, 0xae, 0x42, 0x60, 0x82
        ])
        import tempfile
        temp_file = tempfile.NamedTemporaryFile(suffix=".png", delete=False)
        temp_file.write(minimal_png)
        temp_file.close()
        return temp_file.name, minimal_png

examples.test_openai_compatibility.test_health_endpoint

test_health_endpoint(server_url: str) -> bool

Test the /health endpoint.

Source code in examples/test_openai_compatibility.py
def test_health_endpoint(server_url: str) -> bool:
    """Test the /health endpoint."""
    import requests

    try:
        response = requests.get(f"{server_url}/health", timeout=10)
        return response.status_code == 200
    except Exception as e:
        print_warning(f"Health check failed: {e}")
        return False

examples.test_openai_compatibility.test_models_endpoint

test_models_endpoint(server_url: str) -> bool

Test the /v1/models endpoint.

Source code in examples/test_openai_compatibility.py
def test_models_endpoint(server_url: str) -> bool:
    """Test the /v1/models endpoint."""
    import requests

    try:
        response = requests.get(f"{server_url}/v1/models", timeout=10)
        if response.status_code != 200:
            return False

        data = response.json()
        # Should have "data" key with list of models
        return "data" in data and isinstance(data["data"], list)
    except Exception as e:
        print_warning(f"Models endpoint failed: {e}")
        return False

examples.test_openai_compatibility.test_chat_completions_http

test_chat_completions_http(server_url: str) -> tuple[bool, str]

Test /v1/chat/completions with direct HTTP.

Source code in examples/test_openai_compatibility.py
def test_chat_completions_http(server_url: str) -> tuple[bool, str]:
    """Test /v1/chat/completions with direct HTTP."""
    import requests

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {"role": "user", "content": "Say 'Hello' and nothing else."}
                ],
                "max_tokens": 50,
                "temperature": 0.1,
            },
            timeout=60,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}"

        data = response.json()

        # Validate response structure
        if "choices" not in data:
            return False, "Missing 'choices' in response"

        if len(data["choices"]) == 0:
            return False, "Empty choices array"

        choice = data["choices"][0]
        if "message" not in choice:
            return False, "Missing 'message' in choice"

        if "content" not in choice["message"]:
            return False, "Missing 'content' in message"

        content = choice["message"]["content"]
        return True, f"Response: {content[:50]}..."

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.test_chat_completions_openai

test_chat_completions_openai(server_url: str) -> tuple[bool, str]

Test /v1/chat/completions with OpenAI Python client.

Source code in examples/test_openai_compatibility.py
def test_chat_completions_openai(server_url: str) -> tuple[bool, str]:
    """Test /v1/chat/completions with OpenAI Python client."""
    try:
        from openai import OpenAI
    except ImportError:
        return False, "OpenAI package not installed. Run: pip install openai"

    try:
        client = OpenAI(
            base_url=f"{server_url}/v1",
            api_key="not-needed",  # vllm-mlx doesn't require API key
        )

        response = client.chat.completions.create(
            model="default",
            messages=[
                {"role": "user", "content": "Say 'World' and nothing else."}
            ],
            max_tokens=50,
            temperature=0.1,
        )

        content = response.choices[0].message.content
        return True, f"Response: {content[:50]}..."

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.test_completions_endpoint

test_completions_endpoint(server_url: str) -> tuple[bool, str]

Test /v1/completions endpoint (legacy).

Source code in examples/test_openai_compatibility.py
def test_completions_endpoint(server_url: str) -> tuple[bool, str]:
    """Test /v1/completions endpoint (legacy)."""
    import requests

    try:
        response = requests.post(
            f"{server_url}/v1/completions",
            json={
                "model": "default",
                "prompt": "The capital of France is",
                "max_tokens": 20,
                "temperature": 0.1,
            },
            timeout=60,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}"

        data = response.json()

        if "choices" not in data:
            return False, "Missing 'choices' in response"

        if len(data["choices"]) == 0:
            return False, "Empty choices array"

        text = data["choices"][0].get("text", "")
        return True, f"Response: {text[:50]}..."

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.test_image_chat_http

test_image_chat_http(server_url: str) -> tuple[bool, str]

Test multimodal image chat with direct HTTP.

Source code in examples/test_openai_compatibility.py
def test_image_chat_http(server_url: str) -> tuple[bool, str]:
    """Test multimodal image chat with direct HTTP."""
    import requests

    # Create test image
    image_path, image_bytes = create_test_image()
    image_base64 = base64.b64encode(image_bytes).decode("utf-8")

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {"type": "text", "text": "What color is this image? Answer in one word."},
                            {
                                "type": "image_url",
                                "image_url": {"url": f"data:image/png;base64,{image_base64}"}
                            }
                        ]
                    }
                ],
                "max_tokens": 50,
                "temperature": 0.1,
            },
            timeout=120,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}, Body: {response.text[:100]}"

        data = response.json()
        content = data["choices"][0]["message"]["content"]
        return True, f"Response: {content[:50]}..."

    except Exception as e:
        return False, str(e)
    finally:
        # Clean up temp file
        Path(image_path).unlink(missing_ok=True)

examples.test_openai_compatibility.test_image_chat_openai

test_image_chat_openai(server_url: str) -> tuple[bool, str]

Test multimodal image chat with OpenAI client.

Source code in examples/test_openai_compatibility.py
def test_image_chat_openai(server_url: str) -> tuple[bool, str]:
    """Test multimodal image chat with OpenAI client."""
    try:
        from openai import OpenAI
    except ImportError:
        return False, "OpenAI package not installed"

    # Create test image
    image_path, image_bytes = create_test_image()
    image_base64 = base64.b64encode(image_bytes).decode("utf-8")

    try:
        client = OpenAI(
            base_url=f"{server_url}/v1",
            api_key="not-needed",
        )

        response = client.chat.completions.create(
            model="default",
            messages=[
                {
                    "role": "user",
                    "content": [
                        {"type": "text", "text": "What color is this image? Answer briefly."},
                        {
                            "type": "image_url",
                            "image_url": {"url": f"data:image/png;base64,{image_base64}"}
                        }
                    ]
                }
            ],
            max_tokens=50,
            temperature=0.1,
        )

        content = response.choices[0].message.content
        return True, f"Response: {content[:50]}..."

    except Exception as e:
        return False, str(e)
    finally:
        Path(image_path).unlink(missing_ok=True)

examples.test_openai_compatibility.test_image_url_http

test_image_url_http(server_url: str) -> tuple[bool, str]

Test image from URL.

Source code in examples/test_openai_compatibility.py
def test_image_url_http(server_url: str) -> tuple[bool, str]:
    """Test image from URL."""
    import requests

    # Use a public test image
    test_image_url = "https://upload.wikimedia.org/wikipedia/commons/thumb/4/47/PNG_transparency_demonstration_1.png/200px-PNG_transparency_demonstration_1.png"

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {"type": "text", "text": "Describe this image briefly."},
                            {
                                "type": "image_url",
                                "image_url": {"url": test_image_url}
                            }
                        ]
                    }
                ],
                "max_tokens": 100,
                "temperature": 0.7,
            },
            timeout=120,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}"

        data = response.json()
        content = data["choices"][0]["message"]["content"]
        return True, f"Response: {content[:80]}..."

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.test_streaming_chat

test_streaming_chat(server_url: str) -> tuple[bool, str]

Test streaming chat completions.

Source code in examples/test_openai_compatibility.py
def test_streaming_chat(server_url: str) -> tuple[bool, str]:
    """Test streaming chat completions."""
    import requests

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {"role": "user", "content": "Count from 1 to 5."}
                ],
                "max_tokens": 50,
                "temperature": 0.1,
                "stream": True,
            },
            timeout=60,
            stream=True,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}"

        chunks = []
        for line in response.iter_lines():
            if line:
                line = line.decode("utf-8")
                if line.startswith("data: "):
                    data = line[6:]
                    if data == "[DONE]":
                        break
                    chunks.append(data)

        if len(chunks) == 0:
            return False, "No streaming chunks received"

        return True, f"Received {len(chunks)} streaming chunks"

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.create_test_video

create_test_video() -> tuple[str, bytes]

Create a simple test video with colored frames.

Returns (path, bytes) of a minimal MP4 video.

Source code in examples/test_openai_compatibility.py
def create_test_video() -> tuple[str, bytes]:
    """
    Create a simple test video with colored frames.

    Returns (path, bytes) of a minimal MP4 video.
    """
    try:
        import cv2
        import numpy as np
        import tempfile

        # Create a simple video with 3 colored frames (red, green, blue)
        colors = [
            (0, 0, 255),    # Red (BGR)
            (0, 255, 0),    # Green (BGR)
            (255, 0, 0),    # Blue (BGR)
        ]

        temp_file = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
        temp_path = temp_file.name
        temp_file.close()

        # Create video writer
        fourcc = cv2.VideoWriter_fourcc(*'mp4v')
        out = cv2.VideoWriter(temp_path, fourcc, 1.0, (100, 100))

        for color in colors:
            frame = np.zeros((100, 100, 3), dtype=np.uint8)
            frame[:] = color
            out.write(frame)

        out.release()

        # Read back the bytes
        with open(temp_path, "rb") as f:
            video_bytes = f.read()

        return temp_path, video_bytes

    except ImportError:
        print_warning("OpenCV not installed. Skipping video test.")
        return None, None

examples.test_openai_compatibility.test_video_chat_http

test_video_chat_http(server_url: str) -> tuple[bool, str]

Test multimodal video chat with direct HTTP.

Source code in examples/test_openai_compatibility.py
def test_video_chat_http(server_url: str) -> tuple[bool, str]:
    """Test multimodal video chat with direct HTTP."""
    import requests

    # Create test video
    video_path, video_bytes = create_test_video()
    if video_path is None:
        return False, "Could not create test video (OpenCV required)"

    video_base64 = base64.b64encode(video_bytes).decode("utf-8")

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {"type": "text", "text": "What colors appear in this video? List them briefly."},
                            {
                                "type": "video_url",
                                "video_url": {"url": f"data:video/mp4;base64,{video_base64}"}
                            }
                        ]
                    }
                ],
                "max_tokens": 100,
                "temperature": 0.3,
            },
            timeout=180,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}, Body: {response.text[:100]}"

        data = response.json()
        content = data["choices"][0]["message"]["content"]
        return True, f"Response: {content[:80]}..."

    except Exception as e:
        return False, str(e)
    finally:
        # Clean up temp file
        if video_path:
            Path(video_path).unlink(missing_ok=True)

examples.test_openai_compatibility.test_video_chat_openai

test_video_chat_openai(server_url: str) -> tuple[bool, str]

Test multimodal video chat with OpenAI client.

Source code in examples/test_openai_compatibility.py
def test_video_chat_openai(server_url: str) -> tuple[bool, str]:
    """Test multimodal video chat with OpenAI client."""
    try:
        from openai import OpenAI
    except ImportError:
        return False, "OpenAI package not installed"

    # Create test video
    video_path, video_bytes = create_test_video()
    if video_path is None:
        return False, "Could not create test video (OpenCV required)"

    video_base64 = base64.b64encode(video_bytes).decode("utf-8")

    try:
        client = OpenAI(
            base_url=f"{server_url}/v1",
            api_key="not-needed",
        )

        response = client.chat.completions.create(
            model="default",
            messages=[
                {
                    "role": "user",
                    "content": [
                        {"type": "text", "text": "Describe what you see in this video briefly."},
                        {
                            "type": "video_url",
                            "video_url": {"url": f"data:video/mp4;base64,{video_base64}"}
                        }
                    ]
                }
            ],
            max_tokens=100,
            temperature=0.3,
        )

        content = response.choices[0].message.content
        return True, f"Response: {content[:80]}..."

    except Exception as e:
        return False, str(e)
    finally:
        if video_path:
            Path(video_path).unlink(missing_ok=True)

examples.test_openai_compatibility.test_video_url_http

test_video_url_http(server_url: str) -> tuple[bool, str]

Test video from URL.

Source code in examples/test_openai_compatibility.py
def test_video_url_http(server_url: str) -> tuple[bool, str]:
    """Test video from URL."""
    import requests

    # Use a public test video (Big Buck Bunny - small clip)
    test_video_url = "https://test-videos.co.uk/vids/bigbuckbunny/mp4/h264/360/Big_Buck_Bunny_360_10s_1MB.mp4"

    try:
        response = requests.post(
            f"{server_url}/v1/chat/completions",
            json={
                "model": "default",
                "messages": [
                    {
                        "role": "user",
                        "content": [
                            {"type": "text", "text": "Describe what happens in this video briefly."},
                            {
                                "type": "video_url",
                                "video_url": {"url": test_video_url}
                            }
                        ]
                    }
                ],
                "max_tokens": 150,
                "temperature": 0.7,
            },
            timeout=180,
        )

        if response.status_code != 200:
            return False, f"Status code: {response.status_code}"

        data = response.json()
        content = data["choices"][0]["message"]["content"]
        return True, f"Response: {content[:80]}..."

    except Exception as e:
        return False, str(e)

examples.test_openai_compatibility.run_all_tests

run_all_tests(server_url: str, test_image: bool = True, test_video: bool = True)

Run all compatibility tests.

Source code in examples/test_openai_compatibility.py
def run_all_tests(server_url: str, test_image: bool = True, test_video: bool = True):
    """Run all compatibility tests."""
    results = {"passed": 0, "failed": 0}

    def record(passed: bool):
        if passed:
            results["passed"] += 1
        else:
            results["failed"] += 1

    print_header("vllm-mlx OpenAI API Compatibility Tests")
    print(f"Server URL: {server_url}\n")

    # Basic endpoint tests
    print_header("1. Basic Endpoints")

    passed = test_health_endpoint(server_url)
    print_test("/health endpoint", passed)
    record(passed)

    passed = test_models_endpoint(server_url)
    print_test("/v1/models endpoint", passed)
    record(passed)

    # Chat completions tests
    print_header("2. Chat Completions - Text Only (/v1/chat/completions)")

    passed, msg = test_chat_completions_http(server_url)
    print_test("Direct HTTP request", passed, msg)
    record(passed)

    passed, msg = test_chat_completions_openai(server_url)
    print_test("OpenAI Python client", passed, msg)
    record(passed)

    # Legacy completions test
    print_header("3. Legacy Completions (/v1/completions)")

    passed, msg = test_completions_endpoint(server_url)
    print_test("Direct HTTP request", passed, msg)
    record(passed)

    # Streaming test
    print_header("4. Streaming")

    passed, msg = test_streaming_chat(server_url)
    print_test("Streaming chat completions", passed, msg)
    record(passed)

    # Multimodal image tests
    if test_image:
        print_header("5. Multimodal - Images")

        passed, msg = test_image_chat_http(server_url)
        print_test("Base64 image (HTTP)", passed, msg)
        record(passed)

        passed, msg = test_image_chat_openai(server_url)
        print_test("Base64 image (OpenAI client)", passed, msg)
        record(passed)

        passed, msg = test_image_url_http(server_url)
        print_test("Image from URL", passed, msg)
        record(passed)

    # Multimodal video tests
    if test_video:
        print_header("6. Multimodal - Video")

        passed, msg = test_video_chat_http(server_url)
        print_test("Base64 video (HTTP)", passed, msg)
        record(passed)

        passed, msg = test_video_chat_openai(server_url)
        print_test("Base64 video (OpenAI client)", passed, msg)
        record(passed)

        passed, msg = test_video_url_http(server_url)
        print_test("Video from URL", passed, msg)
        record(passed)

    # Summary
    print_header("Test Summary")

    total = results["passed"] + results["failed"]
    print(f"  Total tests: {total}")
    print(f"  {GREEN}Passed: {results['passed']}{RESET}")
    print(f"  {RED}Failed: {results['failed']}{RESET}")

    if results["failed"] == 0:
        print(f"\n{GREEN}{BOLD}All tests passed! API is OpenAI-compatible.{RESET}")
        return 0
    else:
        print(f"\n{RED}{BOLD}Some tests failed. Check the output above.{RESET}")
        return 1

examples.test_openai_compatibility.main

main()
Source code in examples/test_openai_compatibility.py
def main():
    parser = argparse.ArgumentParser(
        description="Test OpenAI API compatibility of vllm-mlx server",
        formatter_class=argparse.RawDescriptionHelpFormatter,
        epilog="""
Examples:
    # Test with default server (localhost:8000)
    python test_openai_compatibility.py

    # Test with custom server
    python test_openai_compatibility.py --server-url http://myserver:9000

    # Skip image tests (for text-only models)
    python test_openai_compatibility.py --no-image
        """,
    )
    parser.add_argument(
        "--server-url",
        type=str,
        default="http://localhost:8000",
        help="URL of the vllm-mlx server (default: http://localhost:8000)",
    )
    parser.add_argument(
        "--no-image",
        action="store_true",
        help="Skip image tests",
    )
    parser.add_argument(
        "--no-video",
        action="store_true",
        help="Skip video tests",
    )
    args = parser.parse_args()

    # Check if server is reachable
    print(f"Checking server at {args.server_url}...")
    if not test_health_endpoint(args.server_url):
        print(f"{RED}ERROR: Cannot connect to server at {args.server_url}{RESET}")
        print("Make sure the vllm-mlx server is running. Tests assume model name is served as 'default':")
        print("  vllm-mlx serve --served-model-name default mlx-community/Qwen3-VL-4B-Instruct-3bit --port 8000")
        sys.exit(1)

    print(f"{GREEN}Server is reachable!{RESET}")

    return run_all_tests(
        server_url=args.server_url,
        test_image=not args.no_image,
        test_video=not args.no_video,
    )

Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

examples.test_openai_compatibility.print_header · function
examples.test_openai_compatibility.print_header(text: str) -> not annotated

Print a section header.

Parameters

Name Type Required Default Description
text str yes none Required positional or keyword input.

Returns

  • Type: not annotated

Exceptions and behavior

Function print_header calls print. No direct raise statement appears in this definition.

View source #L37-L41.

examples.test_openai_compatibility.print_test · function
examples.test_openai_compatibility.print_test(name: str, passed: bool, message: str = '') -> not annotated

Print test result.

Parameters

Name Type Required Default Description
name str yes none Required positional or keyword input.
passed bool yes none Required positional or keyword input.
message str no '' Optional positional or keyword input; defaults to ''.

Returns

  • Type: not annotated

Exceptions and behavior

Function print_test calls print. No direct raise statement appears in this definition.

View source #L44-L49.

examples.test_openai_compatibility.print_warning · function
examples.test_openai_compatibility.print_warning(text: str) -> not annotated

Print a warning message.

Parameters

Name Type Required Default Description
text str yes none Required positional or keyword input.

Returns

  • Type: not annotated

Exceptions and behavior

Function print_warning calls print. No direct raise statement appears in this definition.

View source #L52-L54.

examples.test_openai_compatibility.create_test_image · function
examples.test_openai_compatibility.create_test_image() -> tuple[str, bytes]

Create a simple test image and return (path, bytes).

Parameters

This callable has no explicit inputs.

Returns

  • Type: tuple[str, bytes]
  • Direct return expressions: (temp_file.name, img_bytes); (temp_file.name, minimal_png)

Exceptions and behavior

Function create_test_image calls Image.new, io.BytesIO, img.save, buffer.getvalue; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L57-L97.

examples.test_openai_compatibility.test_health_endpoint · function
examples.test_openai_compatibility.test_health_endpoint(server_url: str) -> bool

Test the /health endpoint.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: bool
  • Direct return expressions: response.status_code == 200; False

Exceptions and behavior

Function test_health_endpoint calls requests.get, print_warning; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L100-L109.

examples.test_openai_compatibility.test_models_endpoint · function
examples.test_openai_compatibility.test_models_endpoint(server_url: str) -> bool

Test the /v1/models endpoint.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: bool
  • Direct return expressions: False; 'data' in data and isinstance(data['data'], list)

Exceptions and behavior

Function test_models_endpoint calls requests.get, response.json, isinstance, print_warning; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L112-L126.

examples.test_openai_compatibility.test_chat_completions_http · function
examples.test_openai_compatibility.test_chat_completions_http(server_url: str) -> tuple[bool, str]

Test /v1/chat/completions with direct HTTP.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}'); (False, "Missing 'choices' in response"); (False, 'Empty choices array'); (False, "Missing 'message' in choice"); (False, "Missing 'content' in message"); (True, f'Response: {content[:50]}...'); (False, str(e))

Exceptions and behavior

Function test_chat_completions_http calls requests.post, response.json, len, str; has 7 explicit return paths. No direct raise statement appears in this definition.

View source #L129-L170.

examples.test_openai_compatibility.test_chat_completions_openai · function
examples.test_openai_compatibility.test_chat_completions_openai(server_url: str) -> tuple[bool, str]

Test /v1/chat/completions with OpenAI Python client.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, 'OpenAI package not installed. Run: pip install openai'); (True, f'Response: {content[:50]}...'); (False, str(e))

Exceptions and behavior

Function test_chat_completions_openai calls OpenAI, client.chat.completions.create, str; has 3 explicit return paths. No direct raise statement appears in this definition.

View source #L173-L199.

examples.test_openai_compatibility.test_completions_endpoint · function
examples.test_openai_compatibility.test_completions_endpoint(server_url: str) -> tuple[bool, str]

Test /v1/completions endpoint (legacy).

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}'); (False, "Missing 'choices' in response"); (False, 'Empty choices array'); (True, f'Response: {text[:50]}...'); (False, str(e))

Exceptions and behavior

Function test_completions_endpoint calls requests.post, response.json, len, data['choices'][0].get; has 5 explicit return paths. No direct raise statement appears in this definition.

View source #L202-L233.

examples.test_openai_compatibility.test_image_chat_http · function
examples.test_openai_compatibility.test_image_chat_http(server_url: str) -> tuple[bool, str]

Test multimodal image chat with direct HTTP.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}, Body: {response.text[:100]}'); (True, f'Response: {content[:50]}...'); (False, str(e))

Exceptions and behavior

Function test_image_chat_http calls create_test_image, base64.b64encode(image_bytes).decode, base64.b64encode, requests.post; has 3 explicit return paths. No direct raise statement appears in this definition.

View source #L236-L278.

examples.test_openai_compatibility.test_image_chat_openai · function
examples.test_openai_compatibility.test_image_chat_openai(server_url: str) -> tuple[bool, str]

Test multimodal image chat with OpenAI client.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, 'OpenAI package not installed'); (True, f'Response: {content[:50]}...'); (False, str(e))

Exceptions and behavior

Function test_image_chat_openai calls create_test_image, base64.b64encode(image_bytes).decode, base64.b64encode, OpenAI; has 3 explicit return paths. No direct raise statement appears in this definition.

View source #L281-L322.

examples.test_openai_compatibility.test_image_url_http · function
examples.test_openai_compatibility.test_image_url_http(server_url: str) -> tuple[bool, str]

Test image from URL.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}'); (True, f'Response: {content[:80]}...'); (False, str(e))

Exceptions and behavior

Function test_image_url_http calls requests.post, response.json, str; has 3 explicit return paths. No direct raise statement appears in this definition.

View source #L325-L363.

examples.test_openai_compatibility.test_streaming_chat · function
examples.test_openai_compatibility.test_streaming_chat(server_url: str) -> tuple[bool, str]

Test streaming chat completions.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}'); (False, 'No streaming chunks received'); (True, f'Received {len(chunks)} streaming chunks'); (False, str(e))

Exceptions and behavior

Function test_streaming_chat calls requests.post, response.iter_lines, line.decode, line.startswith; has 4 explicit return paths. No direct raise statement appears in this definition.

View source #L366-L405.

examples.test_openai_compatibility.create_test_video · function
examples.test_openai_compatibility.create_test_video() -> tuple[str, bytes]

Create a simple test video with colored frames.

Parameters

This callable has no explicit inputs.

Returns

  • Type: tuple[str, bytes]
  • Direct return expressions: (temp_path, video_bytes); (None, None)

Exceptions and behavior

Function create_test_video calls tempfile.NamedTemporaryFile, temp_file.close, cv2.VideoWriter_fourcc, cv2.VideoWriter; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L408-L449.

examples.test_openai_compatibility.test_video_chat_http · function
examples.test_openai_compatibility.test_video_chat_http(server_url: str) -> tuple[bool, str]

Test multimodal video chat with direct HTTP.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, 'Could not create test video (OpenCV required)'); (False, f'Status code: {response.status_code}, Body: {response.text[:100]}'); (True, f'Response: {content[:80]}...'); (False, str(e))

Exceptions and behavior

Function test_video_chat_http calls create_test_video, base64.b64encode(video_bytes).decode, base64.b64encode, requests.post; has 4 explicit return paths. No direct raise statement appears in this definition.

View source #L452-L498.

examples.test_openai_compatibility.test_video_chat_openai · function
examples.test_openai_compatibility.test_video_chat_openai(server_url: str) -> tuple[bool, str]

Test multimodal video chat with OpenAI client.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, 'OpenAI package not installed'); (False, 'Could not create test video (OpenCV required)'); (True, f'Response: {content[:80]}...'); (False, str(e))

Exceptions and behavior

Function test_video_chat_openai calls create_test_video, base64.b64encode(video_bytes).decode, base64.b64encode, OpenAI; has 4 explicit return paths. No direct raise statement appears in this definition.

View source #L501-L546.

examples.test_openai_compatibility.test_video_url_http · function
examples.test_openai_compatibility.test_video_url_http(server_url: str) -> tuple[bool, str]

Test video from URL.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.

Returns

  • Type: tuple[bool, str]
  • Direct return expressions: (False, f'Status code: {response.status_code}'); (True, f'Response: {content[:80]}...'); (False, str(e))

Exceptions and behavior

Function test_video_url_http calls requests.post, response.json, str; has 3 explicit return paths. No direct raise statement appears in this definition.

View source #L549-L587.

examples.test_openai_compatibility.run_all_tests · function
examples.test_openai_compatibility.run_all_tests(server_url: str, test_image: bool = True, test_video: bool = True) -> not annotated

Run all compatibility tests.

Parameters

Name Type Required Default Description
server_url str yes none Required positional or keyword input.
test_image bool no True Optional positional or keyword input; defaults to True.
test_video bool no True Optional positional or keyword input; defaults to True.

Returns

  • Type: not annotated
  • Direct return expressions: 0; 1

Exceptions and behavior

Function run_all_tests calls print_header, print, test_health_endpoint, print_test; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L590-L684.

examples.test_openai_compatibility.run_all_tests.record · nested function
examples.test_openai_compatibility.run_all_tests.record(passed: bool) -> not annotated

Nested Function run_all_tests.record contains no state mutation, call, raise, return, await, or yield.

Parameters

Name Type Required Default Description
passed bool yes none Required positional or keyword input.

Returns

  • Type: not annotated

Exceptions and behavior

Nested Function run_all_tests.record contains no state mutation, call, raise, return, await, or yield. No direct raise statement appears in this definition.

View source #L594-L598.

examples.test_openai_compatibility.main · function
examples.test_openai_compatibility.main() -> not annotated

Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; returns run_all_tests(server_url=args.server_url, test_image=not args.no_image, test_video=not args.no_video).

Parameters

This callable has no explicit inputs.

Returns

  • Type: not annotated
  • Direct return expressions: run_all_tests(server_url=args.server_url, test_image=not args.no_image, test_video=not args.no_video)

Exceptions and behavior

Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; returns run_all_tests(server_url=args.server_url, test_image=not args.no_image, test_video=not args.no_video). No direct raise statement appears in this definition.

View source #L687-L735.

Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

Symbol Kind Signature and inputs What it does Source
print_header function print_header(text: str) -> not annotated Print a section header. #L37-L41
print_test function print_test(name: str, passed: bool, message: str = '') -> not annotated Print test result. #L44-L49
print_warning function print_warning(text: str) -> not annotated Print a warning message. #L52-L54
create_test_image function create_test_image() -> tuple[str, bytes] Create a simple test image and return (path, bytes). #L57-L97
test_health_endpoint function test_health_endpoint(server_url: str) -> bool Test the /health endpoint. #L100-L109
test_models_endpoint function test_models_endpoint(server_url: str) -> bool Test the /v1/models endpoint. #L112-L126
test_chat_completions_http function test_chat_completions_http(server_url: str) -> tuple[bool, str] Test /v1/chat/completions with direct HTTP. #L129-L170
test_chat_completions_openai function test_chat_completions_openai(server_url: str) -> tuple[bool, str] Test /v1/chat/completions with OpenAI Python client. #L173-L199
test_completions_endpoint function test_completions_endpoint(server_url: str) -> tuple[bool, str] Test /v1/completions endpoint (legacy). #L202-L233
test_image_chat_http function test_image_chat_http(server_url: str) -> tuple[bool, str] Test multimodal image chat with direct HTTP. #L236-L278
test_image_chat_openai function test_image_chat_openai(server_url: str) -> tuple[bool, str] Test multimodal image chat with OpenAI client. #L281-L322
test_image_url_http function test_image_url_http(server_url: str) -> tuple[bool, str] Test image from URL. #L325-L363
test_streaming_chat function test_streaming_chat(server_url: str) -> tuple[bool, str] Test streaming chat completions. #L366-L405
create_test_video function create_test_video() -> tuple[str, bytes] Create a simple test video with colored frames. #L408-L449
test_video_chat_http function test_video_chat_http(server_url: str) -> tuple[bool, str] Test multimodal video chat with direct HTTP. #L452-L498
test_video_chat_openai function test_video_chat_openai(server_url: str) -> tuple[bool, str] Test multimodal video chat with OpenAI client. #L501-L546
test_video_url_http function test_video_url_http(server_url: str) -> tuple[bool, str] Test video from URL. #L549-L587
run_all_tests function run_all_tests(server_url: str, test_image: bool = True, test_video: bool = True) -> not annotated Run all compatibility tests. #L590-L684
run_all_tests.record nested function run_all_tests.record(passed: bool) -> not annotated Nested Function run_all_tests.record contains no state mutation, call, raise, return, await, or yield. #L594-L598
main function main() -> not annotated Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, print; returns run_all_tests(server_url=args.server_url, test_image=not args.no_image, test_video=not args.no_video). #L687-L735