HEX
Server: Apache/2.4.58 (Ubuntu)
System: Linux ip-172-26-0-120 6.17.0-1009-aws #9~24.04.2-Ubuntu SMP Fri Mar 6 23:50:29 UTC 2026 x86_64
User: ubuntu (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/www/html/api.aianced.com/vendor/openai-php/client/src/Actions/Responses/ToolChoiceObjects.php
<?php

declare(strict_types=1);

namespace OpenAI\Actions\Responses;

use OpenAI\Responses\Responses\ToolChoice\FunctionToolChoice;
use OpenAI\Responses\Responses\ToolChoice\HostedToolChoice;

/**
 * @phpstan-import-type FunctionToolChoiceType from FunctionToolChoice
 * @phpstan-import-type HostedToolChoiceType from HostedToolChoice
 *
 * @phpstan-type ResponseToolChoiceTypes 'none'|'auto'|'required'|FunctionToolChoiceType|HostedToolChoiceType
 * @phpstan-type ResponseToolChoiceReturnType 'none'|'auto'|'required'|FunctionToolChoice|HostedToolChoice
 */
final class ToolChoiceObjects
{
    /**
     * @param  ResponseToolChoiceTypes  $toolChoice
     * @return ResponseToolChoiceReturnType
     */
    public static function parse(array|string $toolChoice): string|FunctionToolChoice|HostedToolChoice
    {
        return is_array($toolChoice)
            ? match ($toolChoice['type']) {
                'file_search', 'web_search', 'web_search_preview', 'computer_use_preview' => HostedToolChoice::from($toolChoice),
                'function' => FunctionToolChoice::from($toolChoice),
            }
        : $toolChoice;
    }
}