def convert_gpt4v_to_gpt4_choice()

in aidial_adapter_openai/gpt4_multi_modal/gpt4_vision.py [0:0]


def convert_gpt4v_to_gpt4_choice(choice: dict) -> dict:
    """GPT4 Vision choice is slightly different from the vanilla GPT4 choice
    in how it reports finish reason."""

    ret = choice.copy()

    if "finish_details" in ret:
        gpt4v_finish_type: Optional[str] = ret["finish_details"].get("type")
        gpt4_finish_reason: Optional[str] = convert_to_finish_reason(
            gpt4v_finish_type
        )

        if gpt4_finish_reason is not None:
            ret["finish_reason"] = gpt4_finish_reason

        del ret["finish_details"]

    if "content_filter_results" in ret:
        del ret["content_filter_results"]

    return ret