mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:35:50 +00:00
perf: 优化AI上下文
This commit is contained in:
parent
cc97d9f1ea
commit
477aef7db6
@ -17,6 +17,7 @@ use App\Module\Doo;
|
|||||||
use App\Module\Ihttp;
|
use App\Module\Ihttp;
|
||||||
use App\Module\TextExtractor;
|
use App\Module\TextExtractor;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use League\HTMLToMarkdown\HtmlConverter;
|
||||||
use DB;
|
use DB;
|
||||||
|
|
||||||
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
@error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
|
||||||
@ -439,6 +440,12 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
if ($msg->msg['model_name']) {
|
if ($msg->msg['model_name']) {
|
||||||
$extras['model_name'] = $msg->msg['model_name'];
|
$extras['model_name'] = $msg->msg['model_name'];
|
||||||
}
|
}
|
||||||
|
if (preg_match("/(.*?)(\s+|\s*[_-]\s*)(think|thinking|reasoning)\s*$/", $extras['model_name'], $match)) {
|
||||||
|
$extras['model_name'] = $match[1];
|
||||||
|
$extras['max_tokens'] = 20000;
|
||||||
|
$extras['thinking'] = 4096;
|
||||||
|
$extras['temperature'] = 1.0;
|
||||||
|
}
|
||||||
if ($dialog->session_id) {
|
if ($dialog->session_id) {
|
||||||
$extras['context_key'] = 'session_' . $dialog->session_id;
|
$extras['context_key'] = 'session_' . $dialog->session_id;
|
||||||
}
|
}
|
||||||
@ -580,7 +587,8 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
if ($msg->type !== 'text') {
|
if ($msg->type !== 'text') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
$original = $msg->msg['text'];
|
|
||||||
|
$original = $msg->msg['text'] ?: '';
|
||||||
if ($mention) {
|
if ($mention) {
|
||||||
$original = preg_replace("/<span class=\"mention user\" data-id=\"(\d+)\">(.*?)<\/span>/", "", $original);
|
$original = preg_replace("/<span class=\"mention user\" data-id=\"(\d+)\">(.*?)<\/span>/", "", $original);
|
||||||
}
|
}
|
||||||
@ -591,8 +599,12 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
}
|
}
|
||||||
return $command;
|
return $command;
|
||||||
}
|
}
|
||||||
$aiContents = [];
|
if (!$isAiBot) {
|
||||||
if ($isAiBot) {
|
return trim(strip_tags($original));
|
||||||
|
}
|
||||||
|
|
||||||
|
$contents = [];
|
||||||
|
// 任务
|
||||||
if (preg_match_all("/<span class=\"mention task\" data-id=\"(\d+)\">(.*?)<\/span>/", $original, $match)) {
|
if (preg_match_all("/<span class=\"mention task\" data-id=\"(\d+)\">(.*?)<\/span>/", $original, $match)) {
|
||||||
$taskIds = Base::newIntval($match[1]);
|
$taskIds = Base::newIntval($match[1]);
|
||||||
foreach ($taskIds as $index => $taskId) {
|
foreach ($taskIds as $index => $taskId) {
|
||||||
@ -603,16 +615,18 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
$taskName = addslashes($taskInfo->name) . " (ID:{$taskId})";
|
$taskName = addslashes($taskInfo->name) . " (ID:{$taskId})";
|
||||||
$taskContext = implode("\n", $taskInfo->AIContext());
|
$taskContext = implode("\n", $taskInfo->AIContext());
|
||||||
}
|
}
|
||||||
$aiContents[] = "<task_content path=\"{$taskName}\">\n{$taskContext}\n</task_content>";
|
$contents[] = "<task_content path=\"{$taskName}\">\n{$taskContext}\n</task_content>";
|
||||||
$original = str_replace($match[0][$index], "'{$taskName}' (see below for task_content tag)", $original);
|
$original = str_replace($match[0][$index], "'{$taskName}' (see below for task_content tag)", $original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 文件、报告
|
||||||
if (preg_match_all("/<a class=\"mention ([^'\"]*)\" href=\"([^\"']+?)\"[^>]*?>[~%]([^>]*)<\/a>/", $original, $match)) {
|
if (preg_match_all("/<a class=\"mention ([^'\"]*)\" href=\"([^\"']+?)\"[^>]*?>[~%]([^>]*)<\/a>/", $original, $match)) {
|
||||||
$urlPaths = $match[2];
|
$urlPaths = $match[2];
|
||||||
foreach ($urlPaths as $index => $urlPath) {
|
foreach ($urlPaths as $index => $urlPath) {
|
||||||
$pathTag = null;
|
$pathTag = null;
|
||||||
$pathName = null;
|
$pathName = null;
|
||||||
$pathContent = null;
|
$pathContent = null;
|
||||||
|
// 文件
|
||||||
if (preg_match("/single\/file\/(.*?)$/", $urlPath, $fileMatch)) {
|
if (preg_match("/single\/file\/(.*?)$/", $urlPath, $fileMatch)) {
|
||||||
$pathTag = "file_content";
|
$pathTag = "file_content";
|
||||||
$pathName = addslashes($match[3][$index]);
|
$pathName = addslashes($match[3][$index]);
|
||||||
@ -625,7 +639,9 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
$pathContent = TextExtractor::getFileContent($urlPath);
|
$pathContent = TextExtractor::getFileContent($urlPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} elseif (preg_match("/single\/report\/detail\/(.*?)$/", $urlPath, $reportMatch)) {
|
}
|
||||||
|
// 报告
|
||||||
|
elseif (preg_match("/single\/report\/detail\/(.*?)$/", $urlPath, $reportMatch)) {
|
||||||
$pathTag = "report_content";
|
$pathTag = "report_content";
|
||||||
$pathName = addslashes($match[3][$index]);
|
$pathName = addslashes($match[3][$index]);
|
||||||
$pathContent = "报告状态:不存在或已删除";
|
$pathContent = "报告状态:不存在或已删除";
|
||||||
@ -636,17 +652,23 @@ class BotReceiveMsgTask extends AbstractTask
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($pathTag) {
|
if ($pathTag) {
|
||||||
$aiContents[] = "<{$pathTag} path=\"{$pathName}\">\n{$pathContent}\n</{$pathTag}>";
|
$contents[] = "<{$pathTag} path=\"{$pathName}\">\n{$pathContent}\n</{$pathTag}>";
|
||||||
$original = str_replace($match[0][$index], "'{$pathName}' (see below for {$pathTag} tag)", $original);
|
$original = str_replace($match[0][$index], "'{$pathName}' (see below for {$pathTag} tag)", $original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($msg->msg['type'] !== 'md') {
|
||||||
|
// 转换为Markdown
|
||||||
|
try {
|
||||||
|
$converter = new HtmlConverter();
|
||||||
|
$original = $converter->convert($original);
|
||||||
|
} catch (\Exception) { }
|
||||||
}
|
}
|
||||||
$command = trim(strip_tags($original));
|
if ($contents) {
|
||||||
if ($aiContents) {
|
// 添加tag内容
|
||||||
$command .= "\n\n" . implode("\n\n", $aiContents);
|
$original .= "\n\n" . implode("\n\n", $contents);
|
||||||
}
|
}
|
||||||
return $command ?: '';
|
return $original ?: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
<template v-else-if="field.type === 'model'">
|
<template v-else-if="field.type === 'model'">
|
||||||
<Select v-model="formData[field.prop]" transfer>
|
<Select v-model="formData[field.prop]" transfer>
|
||||||
<Option v-for="item in modelOption(field.prop)" :value="item.value" :key="item.value">{{ item.label }}</Option>
|
<Option v-for="(item, key) in modelOption(field.prop)" :value="item.value" :key="key">{{ item.label }}</Option>
|
||||||
</Select>
|
</Select>
|
||||||
</template>
|
</template>
|
||||||
<template v-else-if="field.type === 'textarea'">
|
<template v-else-if="field.type === 'textarea'">
|
||||||
|
|||||||
1
resources/assets/js/store/ai.js
vendored
1
resources/assets/js/store/ai.js
vendored
@ -88,6 +88,7 @@ const AISystemConfig = {
|
|||||||
label: "模型列表",
|
label: "模型列表",
|
||||||
prop: "models",
|
prop: "models",
|
||||||
type: "textarea",
|
type: "textarea",
|
||||||
|
maxlength: 1000,
|
||||||
placeholder: "一行一个模型名称",
|
placeholder: "一行一个模型名称",
|
||||||
functions: "使用默认模型列表"
|
functions: "使用默认模型列表"
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user