HEX
Server: LiteSpeed
System: Linux server232.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64
User: heatxmsi (538)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/hc_python/lib64/python3.12/site-packages/sentry_sdk/ai/_openai_responses_api.py
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from typing import Union

    from openai.types.responses import ResponseInputItemParam, ResponseInputParam


def _is_system_instruction(message: "ResponseInputItemParam") -> bool:
    if not isinstance(message, dict) or not message.get("role") == "system":
        return False

    return "type" not in message or message["type"] == "message"


def _get_system_instructions(
    messages: "Union[str, ResponseInputParam]",
) -> "list[ResponseInputItemParam]":
    if not isinstance(messages, list):
        return []

    return [message for message in messages if _is_system_instruction(message)]