diff --git a/web/jscss/ciytable.js b/web/jscss/ciytable.js index c568020..69bed22 100644 --- a/web/jscss/ciytable.js +++ b/web/jscss/ciytable.js @@ -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) { diff --git a/web/jscss/style.css b/web/jscss/style.css index 5760f76..e3c6441 100644 --- a/web/jscss/style.css +++ b/web/jscss/style.css @@ -83,6 +83,7 @@ Version: 0.7.0 --bg9: #6f7c82; + --man3: #033a61; --man4: #175787; --man5: #1E9FFF; --man6: #83c1f1; diff --git a/web/z/index.php b/web/z/index.php index 0fc0cea..b7f6e42 100644 --- a/web/z/index.php +++ b/web/z/index.php @@ -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)) diff --git a/zciyphp/openai.php b/zciyphp/openai.php index 4e54668..12c8fa6 100644 --- a/zciyphp/openai.php +++ b/zciyphp/openai.php @@ -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 = <<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; + } }