+ [misc] Add unit tests for aiModel::complete() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
Executable
+46
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 aiModel::complete();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 执行aiTest模块的completeTest方法,参数是1, 'Hello, world!', 512 @0
|
||||
- 执行aiTest模块的completeTest方法,参数是2, 'Complete this text:', 256, array @0
|
||||
- 执行aiTest模块的completeTest方法,参数是1, '', 512 @0
|
||||
- 执行aiTest模块的completeTest方法,参数是999, 'Hello, world!', 512 @0
|
||||
- 执行aiTest模块的completeTest方法,参数是1, 'Hello, world!', 10000 @0
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/ai.unittest.class.php';
|
||||
|
||||
$ai_model = zenData('ai_model');
|
||||
$ai_model->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');
|
||||
Reference in New Issue
Block a user