Skip to content

Commit 02f26ee

Browse files
committed
优化:更新注释
1 parent 54e687a commit 02f26ee

File tree

135 files changed

+1500
-164
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

135 files changed

+1500
-164
lines changed

README.md

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,25 @@ AdminMenu::register(function () {
309309

310310
## ✉️ 使用交流
311311

312-
### QQ交流群
313-
314-
<img width="400" src="https://modstart.com/contact/ContactQQGroup" />
315-
316-
### 微信交流群
317-
318-
<img width="400" src="https://modstart.com/contact/ContactWechatGroup" />
312+
> 添加好友请备注 ModStartBlog
313+
314+
<table width="100%">
315+
<thead>
316+
<tr>
317+
<th width="50%">微信交流群</th>
318+
<th>QQ交流群</th>
319+
</tr>
320+
</thead>
321+
<tbody>
322+
<tr>
323+
<td>
324+
<img style="width:100%;"
325+
src="https://modstart.com/code_dynamic/modstart_wx" />
326+
</td>
327+
<td>
328+
<img style="width:100%;"
329+
src="https://modstart.com/code_dynamic/modstart_qq" />
330+
</td>
331+
</tr>
332+
</tbody>
333+
</table>

config/module.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737
'AigcBase' => [
3838
'enable' => true,
3939
],
40+
'CensorImageTecmz' => [
41+
'enable' => true,
42+
],
43+
'CensorTextTecmz' => [
44+
'enable' => true,
45+
],
46+
'EmailSmtp' => [
47+
'enable' => true,
48+
],
49+
'NotifierEmail' => [
50+
'enable' => true,
51+
],
4052
// 'BlogAdminApi' => [
4153
// 'enable' => true,
4254
// ],

module/AigcBase/Admin/Controller/AigcChatController.php

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
use ModStart\Core\Input\InputPackage;
88
use ModStart\Core\Input\Response;
99
use ModStart\Core\Util\LogUtil;
10+
use ModStart\Core\Util\RandomUtil;
11+
use ModStart\Core\Util\SerializeUtil;
1012
use ModStart\Core\Util\SessionUtil;
11-
use Module\Aicc\Model\BizUser;
1213
use Module\AigcBase\Provider\AigcChatProvider;
1314

1415
class AigcChatController extends Controller
@@ -47,10 +48,47 @@ public function index($type)
4748
BizException::throws($ret['msg']);
4849
}
4950
}
50-
LogUtil::info('xxxx', $ret);
51+
LogUtil::info('AigcBase.admin.chat', $ret);
5152
} catch (BizException $e) {
5253
call_user_func($sendCallback, 'error', $e->getMessage());
5354
}
5455
});
5556
}
57+
58+
public function quick()
59+
{
60+
$input = InputPackage::buildFromInput();
61+
$prompt = $input->getTrimString('prompt');
62+
$sessionId = $input->getTrimString('sessionId');
63+
$driver = $input->getTrimString('driver');
64+
if (empty($sessionId)) {
65+
$sessionId = 'Admin_' . RandomUtil::string(16);
66+
}
67+
if (empty($driver)) {
68+
$driver = modstart_config('AigcBase_AdminDefaultChatDriver');
69+
}
70+
if (!$driver) {
71+
BizException::throws('机器人没有配置,请在 后台→系统设置→AI平台对接→功能设置 中配置');
72+
}
73+
$provider = AigcChatProvider::getByFullName($driver);
74+
if (empty($provider)) {
75+
BizException::throws('机器人没有配置');
76+
}
77+
$option = [
78+
'markdown' => true,
79+
];
80+
$ret = $provider->chat($sessionId, [
81+
'type' => 'text',
82+
'content' => $prompt,
83+
], $option);
84+
if (Response::isError($ret)) {
85+
BizException::throws($ret['msg']);
86+
}
87+
$content = isset($ret['data']['msg']['content'])
88+
? $ret['data']['msg']['content']
89+
: SerializeUtil::jsonEncode($ret['data']['msg']);
90+
return Response::generateSuccessData([
91+
'content' => $content,
92+
]);
93+
}
5694
}

module/AigcBase/Admin/Controller/AigcKeyPoolController.php

Lines changed: 64 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,26 @@
55

66

77
use Illuminate\Routing\Controller;
8+
use ModStart\Admin\Auth\AdminPermission;
89
use ModStart\Admin\Concern\HasAdminQuickCRUD;
910
use ModStart\Admin\Layout\AdminConfigBuilder;
1011
use ModStart\Admin\Layout\AdminCRUDBuilder;
12+
use ModStart\Core\Dao\ModelUtil;
1113
use ModStart\Core\Exception\BizException;
1214
use ModStart\Core\Input\Request;
15+
use ModStart\Core\Input\Response;
1316
use ModStart\Core\Type\TypeUtil;
17+
use ModStart\Core\Util\CRUDUtil;
1418
use ModStart\Field\AbstractField;
1519
use ModStart\Field\AutoRenderedFieldValue;
1620
use ModStart\Form\Form;
21+
use ModStart\Grid\Displayer\ItemOperate;
1722
use ModStart\Grid\GridFilter;
1823
use ModStart\Support\Concern\HasFields;
1924
use ModStart\Widget\ButtonDialogRequest;
25+
use ModStart\Widget\TextAjaxRequest;
2026
use Module\AigcBase\Model\AigcKeyPool;
27+
use Module\AigcBase\Provider\AbstractAigcChatProvider;
2128
use Module\AigcBase\Provider\AigcChatProvider;
2229
use Module\AigcBase\Provider\AigcProvider;
2330
use Module\AigcBase\Type\AigcKeyPoolStatus;
@@ -64,25 +71,43 @@ protected function crud(AdminCRUDBuilder $builder)
6471
}
6572
$builder->radio('status', '状态')->options(AigcKeyPoolStatus::editList())->defaultValue(AigcKeyPoolStatus::ONLINE);
6673
$builder->number('priority', '权重')->defaultValue(10)->help('数字越大被实用的概率越大');
74+
// $builder->display('callCount', '调用次数')->listable(true);
75+
// $builder->display('successCount', '成功次数')->listable(true);
76+
// $builder->display('failCount', '失败次数')->listable(true);
77+
// $builder->display('lastCallTime', '上次调用时间')->listable(true);
78+
$builder->display('_data', '数据统计')
79+
->hookRendering(function (AbstractField $field, $item, $index) {
80+
$html = [];
81+
$html[] = "<table class='ub-table mini border tw-bg-white'>";
82+
//$html[] = '<div>调用次数:' . ($item->callCount + 0) . '</div>';
83+
//$html[] = '<div>成功次数:' . ($item->successCount + 0) . '</div>';
84+
//$html[] = '<div>失败次数:' . ($item->failCount + 0) . '</div>';
85+
//$html[] = '<div>上次调用时间:' . ($item->lastCallTime ? $item->lastCallTime->format('Y-m-d H:i:s') : '-') . '</div>';
86+
$html[] = '<tr><td>调用次数</td><td>' . ($item->callCount + 0) . '</td></tr>';
87+
$html[] = '<tr><td>成功次数</td><td>' . ($item->successCount + 0) . '</td></tr>';
88+
$html[] = '<tr><td>失败次数</td><td>' . ($item->failCount + 0) . '</td></tr>';
89+
$html[] = '<tr><td>上次调用时间</td><td>' . ($item->lastCallTime ? $item->lastCallTime->format('Y-m-d H:i:s') : '-') . '</td></tr>';
90+
$html[] = '</table>';
91+
return AutoRenderedFieldValue::make(join('', $html));
92+
})
93+
->width(300)
94+
->listable(true)->showable(true)->addable(false)->editable(false);
6795
$builder->display('_param', '参数')
6896
->hookRendering(function (AbstractField $field, $item, $index) {
6997
$html = [];
7098
$provider = AigcProvider::getByName($item->type);
7199
if ($provider) {
72-
$html[] = "<table class='ub-table mini border'>";
100+
$html[] = "<table class='ub-table mini border tw-bg-white'>";
73101
foreach ($provider->paramDisplay($item->toArray()) as $v) {
74-
$html[] = "<tr><td>$v[name]</td><td>$v[value]</td></tr>";
102+
$html[] = "<tr><td>$v[name]</td><td><div style='max-width:8rem;overflow:hidden;text-overflow:ellipsis;'>$v[value]</div></td></tr>";
75103
}
76104
$html[] = "</table>";
77105
}
78106
return AutoRenderedFieldValue::make(join('', $html));
79107
})
108+
->width(300)
80109
->listable(true)->showable(true)->addable(false)->editable(false);
81110
$builder->text('remark', '备注');
82-
$builder->display('callCount', '调用次数')->listable(true);
83-
$builder->display('successCount', '成功次数')->listable(true);
84-
$builder->display('failCount', '失败次数')->listable(true);
85-
$builder->display('lastCallTime', '上次调用时间')->listable(true);
86111

87112
$builder->display('created_at', L('Created At'))->listable(false);
88113
$builder->display('updated_at', L('Updated At'))->listable(false);
@@ -94,18 +119,51 @@ protected function crud(AdminCRUDBuilder $builder)
94119
->gridOperateAppend(
95120
ButtonDialogRequest::make('primary', '<i class="iconfont icon-cog"></i> 功能设置', modstart_admin_url('aigc/key_pool/config'))->size('big')
96121
)
122+
->hookItemOperateRendering(function (ItemOperate $itemOperate) {
123+
$item = $itemOperate->item();
124+
$provider = AigcProvider::getByName($item->type);
125+
if (in_array($provider->type(), [AigcProviderType::CHAT])) {
126+
$itemOperate->prepend(
127+
TextAjaxRequest::make('primary', '测试', modstart_admin_url('aigc/key_pool/test', ['_id' => $item->id]))
128+
->attr('data-ajax-request-loading')
129+
);
130+
}
131+
})
97132
->hookChanged(function (Form $form) {
98133
AigcKeyPoolUtil::clearCache();
99134
})
100135
->title('AI平台对接');
101136
}
102137

138+
public function test()
139+
{
140+
AdminPermission::demoCheck();
141+
$record = ModelUtil::get(AigcKeyPool::class, CRUDUtil::id());
142+
BizException::throwsIfEmpty('记录不存在', $record);
143+
ModelUtil::decodeRecordJson($record, ['param']);
144+
$provider = AigcProvider::getByFullName($record['type'] . ':' . $record['param']['model']);
145+
BizException::throwsIfEmpty('模型驱动不存在', $provider);
146+
$ret = Response::generateError('暂不支持测试');
147+
switch ($provider->type()) {
148+
case AigcProviderType::CHAT:
149+
/** @var AbstractAigcChatProvider $chatProvider */
150+
$chatProvider = $provider;
151+
$ret = $chatProvider->chat('test', '你是什么模型,使用最简短的回答');
152+
break;
153+
}
154+
if (Response::isSuccess($ret)) {
155+
return Response::generateSuccess('测试成功');
156+
}
157+
return $ret;
158+
}
159+
103160
public function config(AdminConfigBuilder $builder)
104161
{
105162
$builder->useDialog();
106163
$builder->pageTitle('功能设置');
107164
$builder->switch('AigcBase_AdminRichEditorEnable', '后台富文本编辑器AI功能')->defaultValue(false);
108165
$builder->select('AigcBase_AdminRichEditorDriver', '后台富文本编辑器AI驱动')->options(AigcChatProvider::modelMap());
166+
$builder->select('AigcBase_AdminDefaultChatDriver', '后台默认AI对话驱动')->options(AigcChatProvider::modelMap());
109167
$builder->formClass('wide-lg');
110168
$builder->disableBoxWrap(true);
111169
return $builder->perform();

module/AigcBase/Admin/routes.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
$router->match(['get', 'post'], 'aigc/key_pool/edit', 'AigcKeyPoolController@edit');
88
$router->match(['post'], 'aigc/key_pool/delete', 'AigcKeyPoolController@delete');
99
$router->match(['get'], 'aigc/key_pool/show', 'AigcKeyPoolController@show');
10+
$router->match(['post'], 'aigc/key_pool/test', 'AigcKeyPoolController@test');
1011

1112
$router->match(['get', 'post'], 'aigc/key_pool/config', 'AigcKeyPoolController@config');
1213

1314
$router->match(['post'], 'aigc/chat/{type}', 'AigcChatController@index');
15+
$router->match(['post'], 'aigc/chat_quick', 'AigcChatController@quick');

module/AigcBase/Docs/module/content.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
已支持AI平台
77
智谱AI
88
OpenAI
9+
百度文心一言
10+
讯飞星火
11+
阿里千锤百炼
12+
硅基流动
13+
讯飞星火
14+
Api2d
15+
Azure
16+
Deepseek
17+
豆包
18+
Gemini
19+
Minimax
920
```
1021

1122
> 以上AI驱动需要在后台模块进行自定义安装

module/AigcBase/Docs/release.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## 1.4.1 积分计算方式升级
2+
3+
- 升级:积分计算方式
4+
5+
---
6+
7+
## 1.4.0 AI模型配置测试,调用字段统计
8+
9+
- 新增:AI模型配置增加测试功能,支持测试模型是否可用
10+
- 新增:后台API对接列表新增数据统计字段
11+
12+
---
13+
114
## 1.3.1 非Markdown格式模型调用异常问题
215

316
- 修复:非Markdown格式模型调用异常问题

module/AigcBase/Util/AigcCreditUtil.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,24 @@ public static function calc($configKeyPrefix, $countCalculator)
2121
return $amount * $cost;
2222
}
2323

24-
public static function calcContentLength($configKeyPrefix, $content)
24+
/**
25+
* 计算长度,1个汉字2个字符,1个英文字母1个字符
26+
* @param $text string
27+
* @return int
28+
*/
29+
public static function countChar($text)
2530
{
26-
return self::calc($configKeyPrefix, mb_strlen($content));
31+
// 1个汉字2个字符
32+
$text = preg_replace('/[\x{4e00}-\x{9fa5}]/u', 'xx', $text);
33+
// 1个英文字母1个字符
34+
// ignore
35+
$text = preg_replace('/[a-zA-Z]/u', 'x', $text);
36+
return mb_strlen($text);
37+
}
38+
39+
public static function calcContentCharLength($configKeyPrefix, $content)
40+
{
41+
return self::calc($configKeyPrefix, self::countChar($content));
2742
}
2843

2944
public static function change($memberUserId, $change, $remark)
@@ -35,9 +50,9 @@ public static function change($memberUserId, $change, $remark)
3550
ModelUtil::transactionCommit();
3651
}
3752

38-
public static function changeByContentLength($memberUserId, $configKeyPrefix, $content, $remark)
53+
public static function changeByContentCharLength($memberUserId, $configKeyPrefix, $content, $remark)
3954
{
40-
$amount = self::calcContentLength($configKeyPrefix, $content);
55+
$amount = self::calcContentCharLength($configKeyPrefix, $content);
4156
self::change($memberUserId, -$amount, $remark);
4257
}
4358

module/AigcBase/config.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,23 @@
1515
],
1616
"suggest": [
1717
"AigcChatOpenAi",
18+
"AigcChatZhipuAi",
19+
"AigcChatAliyun",
20+
"AigcChatAliyunBailian",
21+
"AigcChatApi2d",
22+
"AigcChatAzure",
23+
"AigcChatBaidu",
24+
"AigcChatDeepseek",
25+
"AigcChatDoubao",
26+
"AigcChatGemini",
27+
"AigcChatMinimax",
28+
"AigcChatOpenAi",
29+
"AigcChatTecmz",
30+
"AigcChatTencent",
31+
"AigcChatXunfei",
1832
"AigcChatZhipuAi"
1933
],
20-
"version": "1.3.1",
34+
"version": "1.4.1",
2135
"modstartVersion": ">=4.1.0",
2236
"author": "ModStart",
2337
"description": "提供AI基础框架包,支持各种模型接入",

module/Blog/Admin/Controller/BlogCommentController.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected function crud(AdminCRUDBuilder $builder)
3939
})
4040
->gridFilter(function (GridFilter $filter) {
4141
$filter->eq('id', L('ID'));
42+
$filter->eq('status', '状态')->select(BlogCommentStatus::class);
4243
$filter->like('username', '用户');
4344
})
4445
->hookItemOperateRendering(function (ItemOperate $itemOperate) {

module/Blog/Admin/Controller/BlogMessageController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use ModStart\Grid\GridFilter;
1616
use ModStart\Support\Concern\HasFields;
1717
use ModStart\Widget\TextAjaxRequest;
18-
use Module\Blog\Type\BlogCommentStatus;
1918
use Module\Blog\Type\BlogMessageStatus;
2019

2120
class BlogMessageController extends Controller
@@ -39,10 +38,11 @@ protected function crud(AdminCRUDBuilder $builder)
3938
})
4039
->gridFilter(function (GridFilter $filter) {
4140
$filter->eq('id', L('ID'));
41+
$filter->eq('status', '状态')->select(BlogMessageStatus::class);
4242
$filter->like('username', '用户');
4343
})
4444
->hookItemOperateRendering(function (ItemOperate $itemOperate) {
45-
if ($itemOperate->item()->status === BlogCommentStatus::WAIT_VERIFY) {
45+
if ($itemOperate->item()->status === BlogMessageStatus::WAIT_VERIFY) {
4646
$itemOperate->prepend(TextAjaxRequest::success('审核通过', action('\\' . __CLASS__ . '@verifyPass', ['_id' => $itemOperate->item()->id])));
4747
$itemOperate->prepend(TextAjaxRequest::danger('审核拒绝', action('\\' . __CLASS__ . '@verifyReject', ['_id' => $itemOperate->item()->id])));
4848
}

0 commit comments

Comments
 (0)