This commit is contained in:
boi 2025-05-25 07:31:49 +08:00
parent 47678edb02
commit 987a063e6e
4 changed files with 98 additions and 4 deletions

View File

@ -31,6 +31,9 @@ ciyclass.cardtable = function (opn) {
this.post = Object.assign(this.post, opn.post);
ciyfn._table_eventpage(_pagedom, this);
ciyfn._table_dragitem(this.dom);
this.listdom.on('scroll', function () {
ciyfn.lazyimg();
});
this.callpage = function (page, scroll) {
if (page === undefined)
page = this.pageno;
@ -175,6 +178,9 @@ ciyclass.table = function (opn) {
this.post = Object.assign(this.post, opn.post);
var dataready = true;
ciyfn._table_eventpage(_pagedom, this);
this.listdom.on('scroll', function () {
ciyfn.lazyimg();
});
this.callpage = function (page, scroll) {
if (!dataready)
return ciyfn.toast('数据处理中,请稍后操作');
@ -451,6 +457,9 @@ ciyclass.table = function (opn) {
thos._shcolumn(localset);
if (typeof (opn.fn_done) == 'function')
opn.fn_done(json, thos.post);
setTimeout(function () {
ciyfn.lazyimg();
}, 1000);
}
}
this.tabletr_html = function (ldat) {

View File

@ -83,6 +83,7 @@ Version: 0.7.0
--bg9: #6f7c82;
--man3: #033a61;
--man4: #175787;
--man5: #1E9FFF;
--man6: #83c1f1;

View File

@ -74,6 +74,8 @@ if (!empty($qstr)) {
header('X-Accel-Buffering: no');
ob_start();
$retarr = call_user_func($qstrarr[0] . '::sse_' . $qstrarr[1], function ($data, $id = '') {
if(is_object($data) || is_array($data))
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
// if (strpos($data, "\n") !== false)
// $data = 'base64,' . base64_encode($data);
if (empty($id))

View File

@ -85,6 +85,7 @@ class openai {
$tools[] = $tool;
}
}
$resultcontent = '';
while (true) {
$data = array();
$data['model'] = $this->aicfg['model'];
@ -92,7 +93,7 @@ class openai {
if ($tools)
$data['tools'] = $tools;
if ($this->aicfg['maxtoken'] > 0)
$data['max_tokens'] = $this->aicfg['maxtoken'];
$data['max_tokens'] = (int)$this->aicfg['maxtoken'];
if ($this->fp > -999)
$data['frequency_penalty'] = $this->fp;
if ($this->pp > -999)
@ -155,9 +156,45 @@ class openai {
}
continue;
}
if ($finish == 'length') {
if ($isjson) {
$message['content'] = self::fixjson($message['content']);
//以下暂时AI能力有限
// $context = mb_substr($content, -200, 200);
// $last_char = mb_substr($context, -1);
// $expected = '';
// switch ($last_char) {
// case '{': $expected = '对象未闭合'; break;
// case '[': $expected = '数组未闭合'; break;
// case ':': $expected = '值未完成'; break;
// case ',': $expected = '需要下一个元素'; break;
// }
// $tmp = <<<data
// 请严格作为JSON生成器继续输出必须遵循以下规则
// 1. 仅续写以下JSON片段绝对不要重复已有内容
// 2. 当前状态:{$expected},最后字符是"{$last_char}"
// 3. 保持语法正确,自动闭合未完成的字符串/括号
// 4. 如果原JSON是对象继续添加属性如果是数组继续添加元素
// 当前JSON片段仅作上下文参考不要重复
// {$context}
// 请直接输出JSON续写内容不要包含上下文片段
// data;
// $this->messages[] = array('role' => 'user', 'content' => $tmp);
} else {
$resultcontent .= $message['content'];
$this->messages[] = array('role' => 'user', 'content' => '请继续完成之前的对话');
continue;
}
}
if (!$isjson) {
$resultcontent .= $message['content'];
$message['finish_reason'] = $finish;
$message['content'] = $resultcontent;
return $message;
}
$content = $message['content'];
@ -167,9 +204,10 @@ class openai {
if ($ind2 !== false)
$content = substr($content, $ind + 7, $ind2 - $ind - 7);
}
$json = json_decode($content, true);
$resultcontent .= $content;
$json = json_decode($resultcontent, true);
if ($json === null)
return 'ERR: json decode error.' . $content;
return 'ERR: json decode error.' . $resultcontent;
return $json;
}
}
@ -181,7 +219,7 @@ class openai {
'stream' => true,
];
if ($this->aicfg['maxtoken'] > 0)
$data['max_tokens'] = $this->aicfg['maxtoken'];
$data['max_tokens'] = (int)$this->aicfg['maxtoken'];
if ($this->fp > -999)
$data['frequency_penalty'] = $this->fp;
if ($this->pp > -999)
@ -217,4 +255,48 @@ class openai {
curl_close($ch);
return true;
}
function fixjson($jsonstr) {
$fixed = $jsonstr;
$inString = false;
$escaped = false;
for ($i = 0; $i < strlen($fixed); $i++) {
$char = $fixed[$i];
if (!$escaped && $char === '"') {
$inString = !$inString;
}
$escaped = ($char === '\\' && !$escaped);
}
if ($inString) {
$fixed .= '"';
}
$stack = [];
$inString = false;
$escaped = false;
for ($i = 0; $i < strlen($fixed); $i++) {
$char = $fixed[$i];
if (!$inString) {
if ($char === '{') {
array_push($stack, '}');
} elseif ($char === '[') {
array_push($stack, ']');
} elseif ($char === '}' || $char === ']') {
array_pop($stack);
}
}
if (!$escaped && $char === '"') {
$inString = !$inString;
}
$escaped = ($char === '\\' && !$escaped);
}
$fixed .= implode('', array_reverse($stack));
$fixed = preg_replace('/,\s*([\]}])/m', '$1', $fixed);
$fixed = preg_replace_callback(
'/([{,]\s*)([a-zA-Z_][a-zA-Z0-9_]*)(\s*:)/',
function ($matches) {
return $matches[1] . '"' . $matches[2] . '"' . $matches[3];
},
$fixed
);
return $fixed;
}
}