From 4bed9e72c2c0183e33b347bd9765ffb15e984022 Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 6 Sep 2025 16:27:41 +0800 Subject: [PATCH] + [misc] Add unit tests for aiModel::converseForJSON() 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/converseforjson.php | 47 ++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 module/ai/test/model/converseforjson.php diff --git a/module/ai/test/lib/ai.unittest.class.php b/module/ai/test/lib/ai.unittest.class.php index af3a9dd790..1b4861464f 100644 --- a/module/ai/test/lib/ai.unittest.class.php +++ b/module/ai/test/lib/ai.unittest.class.php @@ -476,4 +476,22 @@ class aiTest return $result; } + + /** + * Test converseForJSON method. + * + * @param mixed $model + * @param array $messages + * @param object $schema + * @param array $options + * @access public + * @return mixed + */ + public function converseForJSONTest($model = null, $messages = array(), $schema = null, $options = array()) + { + $result = $this->objectModel->converseForJSON($model, $messages, $schema, $options); + if(dao::isError()) return dao::getError(); + + return $result; + } } \ No newline at end of file diff --git a/module/ai/test/model/converseforjson.php b/module/ai/test/model/converseforjson.php new file mode 100755 index 0000000000..d37d4bbcbe --- /dev/null +++ b/module/ai/test/model/converseforjson.php @@ -0,0 +1,47 @@ +#!/usr/bin/env php + 'user', 'content' => 'Generate a user profile with name and age') +); + +$validSchema = (object)array( + 'type' => 'object', + 'properties' => (object)array( + 'name' => (object)array('type' => 'string'), + 'age' => (object)array('type' => 'integer') + ), + 'required' => array('name', 'age') +); + +$invalidSchema = array(); + +$options = array('temperature' => 0.7, 'max_tokens' => 100); + +r($aiTest->converseForJSONTest(1, $validMessages, $validSchema)) && p() && e('0'); +r($aiTest->converseForJSONTest(999, $validMessages, $validSchema)) && p() && e('0'); +r($aiTest->converseForJSONTest(1, array(), $validSchema)) && p() && e('0'); +r($aiTest->converseForJSONTest(1, $validMessages, $invalidSchema)) && p() && e('0'); +r($aiTest->converseForJSONTest(1, $validMessages, $validSchema, $options)) && p() && e('0'); \ No newline at end of file