From e2a2fdae4afc65e4cbeb0887bcc4d367564031cd Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 6 Sep 2025 16:11:52 +0800 Subject: [PATCH] + [misc] Add unit tests for aiModel::complete() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/ai/test/lib/ai.unittest.class.php | 18 ++++++++++ module/ai/test/model/complete.php | 46 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100755 module/ai/test/model/complete.php diff --git a/module/ai/test/lib/ai.unittest.class.php b/module/ai/test/lib/ai.unittest.class.php index 4ec3c41c88..36008fb551 100644 --- a/module/ai/test/lib/ai.unittest.class.php +++ b/module/ai/test/lib/ai.unittest.class.php @@ -423,4 +423,22 @@ class aiTest return $result; } + + /** + * Test complete method. + * + * @param mixed $model + * @param string $prompt + * @param int $maxTokens + * @param array $options + * @access public + * @return mixed + */ + public function completeTest($model = null, $prompt = '', $maxTokens = 512, $options = array()) + { + $result = $this->objectModel->complete($model, $prompt, $maxTokens, $options); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/ai/test/model/complete.php b/module/ai/test/model/complete.php new file mode 100755 index 0000000000..163fa91882 --- /dev/null +++ b/module/ai/test/model/complete.php @@ -0,0 +1,46 @@ +#!/usr/bin/env php +id->range('1-5'); +$ai_model->type->range('openai{2},ernie{2},claude{1}'); +$ai_model->vendor->range('openai{2},baidu{2},anthropic{1}'); +$ai_model->credentials->range('{"api_key":"test_key_1"},{"api_key":"test_key_2"},{"api_key":"test_key_3"},{"api_key":"test_key_4"},{"api_key":"test_key_5"}'); +$ai_model->name->range('GPT-3.5,GPT-4,ERNIE-Bot,ERNIE-Turbo,Claude-3'); +$ai_model->createdBy->range('admin{5}'); +$ai_model->createdDate->range('`2024-01-01`{5}'); +$ai_model->enabled->range('1{5}'); +$ai_model->deleted->range('0{5}'); +$ai_model->gen(5); + +su('admin'); + +$aiTest = new aiTest(); + +// 设置模型配置以避免配置错误 +$config = new stdclass(); +$config->type = 'openai-gpt35'; +$aiTest->setModelConfigTest($config); + +r($aiTest->completeTest(1, 'Hello, world!', 512)) && p() && e('0'); +r($aiTest->completeTest(2, 'Complete this text:', 256, array('temperature' => 0.7))) && p() && e('0'); +r($aiTest->completeTest(1, '', 512)) && p() && e('0'); +r($aiTest->completeTest(999, 'Hello, world!', 512)) && p() && e('0'); +r($aiTest->completeTest(1, 'Hello, world!', 10000)) && p() && e('0'); \ No newline at end of file