deploy: 2026-07-15 14:48 部署更新

This commit is contained in:
selfrelease
2026-07-15 14:48:10 +08:00
parent bb6eaff775
commit 8e40d2c9b6
2 changed files with 92 additions and 14 deletions
+55 -5
View File
@@ -1132,13 +1132,63 @@ async function generateParadigm() {
const result = document.getElementById('paradigm-result');
btn.disabled = true;
btn.textContent = '生成中...';
result.innerHTML = '<p class="text-sm text-gray-400">正在调用千问 LLM 生成标准范式对话,请稍候...</p>';
result.innerHTML = `
<div class="bg-white rounded-lg shadow p-6">
<div class="flex items-center gap-2 mb-4">
<svg class="animate-spin w-5 h-5 text-green-600" fill="none" viewBox="0 0 24 24"><circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/><path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/></svg>
<span class="text-sm text-gray-500">正在调用千问 LLM 生成标准范式对话...</span>
</div>
<pre id="paradigm-stream-text" class="text-xs text-gray-600 bg-gray-50 rounded p-3 max-h-96 overflow-auto whitespace-pre-wrap break-all font-mono"></pre>
</div>
`;
const streamText = document.getElementById('paradigm-stream-text');
let fullContent = '';
try {
const productId = document.getElementById('paradigm-product-select').value;
let paradigmPath = `/conversations/${customerId}/paradigm`;
if (productId) paradigmPath += `?product_id=${productId}`;
const data = await api(paradigmPath, { method: 'POST' });
renderParadigm(data);
let paradigmUrl = `${API}/conversations/${customerId}/paradigm`;
if (productId) paradigmUrl += `?product_id=${productId}`;
const resp = await fetch(paradigmUrl, { method: 'POST' });
if (!resp.ok) throw new Error(`HTTP ${resp.status}`);
const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = '';
while (true) {
const { done, value } = await reader.read();
if (done) break;
buffer += decoder.decode(value, { stream: true });
const lines = buffer.split('\n');
buffer = lines.pop();
for (const line of lines) {
if (!line.startsWith('data: ')) continue;
const dataStr = line.slice(6).trim();
if (dataStr === '[DONE]') continue;
try {
const obj = JSON.parse(dataStr);
if (obj.error) throw new Error(obj.error);
if (obj.content) {
fullContent += obj.content;
streamText.textContent = fullContent;
streamText.scrollTop = streamText.scrollHeight;
}
} catch (e) {
// 忽略解析错误的行
}
}
}
// 尝试解析完整 JSON 并渲染结构化结果
try {
const data = JSON.parse(fullContent);
renderParadigm(data);
} catch (e) {
// JSON 解析失败,保留原始流式文本
result.innerHTML = `
<div class="bg-white rounded-lg shadow p-6">
<h3 class="text-lg font-bold mb-2">标准范式对话模板</h3>
<p class="text-sm text-orange-500 mb-3">LLM 返回内容无法解析为 JSON,以下为原始输出:</p>
<pre class="text-xs text-gray-600 bg-gray-50 rounded p-3 max-h-96 overflow-auto whitespace-pre-wrap break-all">${escapeHtml(fullContent)}</pre>
</div>
`;
}
} catch (e) {
result.innerHTML = `<p class="text-sm text-red-500">生成失败: ${e.message}</p>`;
} finally {