#!/usr/bin/env php instance->modelConfig = new stdClass(); $aiTest->instance->modelConfig->type = 'openai-gpt35'; // 5. 构造测试数据 $openaiResponseData = json_encode((object)array( 'choices' => array( (object)array( 'message' => (object)array( 'function_call' => (object)array( 'arguments' => '{"key": "value"}' ) ) ), (object)array( 'message' => (object)array( 'function_call' => (object)array( 'arguments' => '{"key2": "value2"}' ) ) ) ) )); $ernieResponseData = json_encode((object)array( 'function_call' => (object)array( 'arguments' => '{"ernie_key": "ernie_value"}' ) )); $noFunctionCallResponseData = json_encode((object)array( 'choices' => array( (object)array( 'message' => (object)array( 'content' => 'normal text response' ) ) ) )); // 构造符合decodeResponse要求的响应对象 $openaiResponse = (object)array('result' => 'success', 'content' => $openaiResponseData); $ernieResponse = (object)array('result' => 'success', 'content' => $ernieResponseData); $emptyResponse = (object)array('result' => 'success', 'content' => ''); $invalidJsonResponse = (object)array('result' => 'success', 'content' => 'invalid json string'); $noFunctionCallResponse = (object)array('result' => 'success', 'content' => $noFunctionCallResponseData); $failedResponse = (object)array('result' => 'fail', 'message' => 'API request failed'); // 6. 🔴 强制要求:必须包含至少5个测试步骤 // 步骤1:测试OpenAI模型正常function call响应解析 r($aiTest->parseFunctionCallResponseTest($openaiResponse)) && p('0') && e('{"key": "value"}'); // 步骤2:测试Ernie模型正常function call响应解析 $aiTest->instance->modelConfig->type = 'baidu-ernie'; r($aiTest->parseFunctionCallResponseTest($ernieResponse)) && p('0') && e('{"ernie_key": "ernie_value"}'); // 步骤3:测试空content响应处理 r($aiTest->parseFunctionCallResponseTest($emptyResponse)) && p() && e('0'); // 步骤4:测试API失败响应处理 r($aiTest->parseFunctionCallResponseTest($failedResponse)) && p() && e('0'); // 步骤5:测试无function_call的响应处理 $aiTest->instance->modelConfig->type = 'openai-gpt35'; r(count($aiTest->parseFunctionCallResponseTest($noFunctionCallResponse))) && p() && e(0);