main
HuangHai 2 weeks ago
parent 7f94cb2cc2
commit 3f889e94e9

@ -10,9 +10,9 @@ ALY_SK = 'oizcTOZ8izbGUouboC00RcmGE8vBQ1'
# 阿里云提供的大模型服务 【阿里云在处理文字材料时,容易引发绿网拦截,导致数据上报异常】 # 阿里云提供的大模型服务 【阿里云在处理文字材料时,容易引发绿网拦截,导致数据上报异常】
LLM_API_KEY = "sk-f6da0c787eff4b0389e4ad03a35a911f" LLM_API_KEY = "sk-f6da0c787eff4b0389e4ad03a35a911f"
LLM_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1" LLM_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
# LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确! #LLM_MODEL_NAME = "qwen-plus" # 不要使用通义千问,会导致化学方程式不正确!
# LLM_MODEL_NAME = "deepseek-v3" LLM_MODEL_NAME = "deepseek-v3"
LLM_MODEL_NAME = "deepseek-r1" # 使用更牛B的r1模型 #LLM_MODEL_NAME = "deepseek-r1" # 使用更牛B的r1模型
EMBED_MODEL_NAME = "BAAI/bge-m3" EMBED_MODEL_NAME = "BAAI/bge-m3"
EMBED_API_KEY = "sk-pbqibyjwhrgmnlsmdygplahextfaclgnedetybccknxojlyl" EMBED_API_KEY = "sk-pbqibyjwhrgmnlsmdygplahextfaclgnedetybccknxojlyl"

@ -68,7 +68,11 @@ async def rag(request: fastapi.Request):
user_prompt = user_prompt + "\n 6、发现输出内容中包含Latex公式的一定要检查是不是包含了$$或$的包含符号,不能让Latex无包含符号出现" user_prompt = user_prompt + "\n 6、发现输出内容中包含Latex公式的一定要检查是不是包含了$$或$的包含符号,不能让Latex无包含符号出现"
elif output_model=='html': elif output_model=='html':
user_prompt=""" user_prompt="""
我需要一个专业的交互式数据可视化数据资料我将提供你也可以根据自己了解的信息进行补充注意1不要与用户进行二次交互直接生成即可2直接输出html代码不要其它信息出现3正面负面信息都要 我需要一个专业的交互式数据可视化数据资料我将提供你也可以根据自己了解的信息进行补充
注意
(1)直接输出html代码,```html 开头 ``` 结尾
(2)不要与用户进行二次交互直接生成即可
(3)正面负面信息都要
绘制可视化具体要求如下 绘制可视化具体要求如下
1. **主题类型** 1. **主题类型**
[明确主题如历史人物关系/公司组织架构/生物基因网络等] [明确主题如历史人物关系/公司组织架构/生物基因网络等]

@ -149,8 +149,6 @@
#answerArea { #answerArea {
min-height: 240px; min-height: 240px;
max-height: 500px; /* 设置最大高度 */
overflow-y: auto; /* 添加垂直滚动条 */
height: auto; height: auto;
overflow-y: auto; overflow-y: auto;
} }
@ -198,8 +196,8 @@
<div class="example-item" onclick="fillExample('“先写后编”的历史写作方式是什么意思?')"> <div class="example-item" onclick="fillExample('“先写后编”的历史写作方式是什么意思?')">
“先写后编”的历史写作方式是什么意思? “先写后编”的历史写作方式是什么意思?
</div> </div>
<div class="example-item" onclick="fillExample('“皇帝”称号的由来')"> <div class="example-item" onclick="fillExample('“皇帝”称号的由来')">
“皇帝”称号的由来 “皇帝”称号的由来
</div> </div>
</div> </div>
@ -209,7 +207,8 @@
</div> </div>
<button id="submitBtn" onclick="submitQuestion()"><span class="icon">💡</span>提问</button> <button id="submitBtn" onclick="submitQuestion()"><span class="icon">💡</span>提问</button>
<button id="clearBtn" onclick="clearAll()"><span class="icon">🗑️</span>清空</button> <button id="clearBtn" onclick="clearAll()"><span class="icon">🗑️</span>清空</button>
<button id="relationBtn" onclick="generateRelation()" style="background-color:#9c27b0"><span class="icon">👥</span>生成刘帮集团的人物关系图</button> <button id="relationBtn" onclick="generateRelation()" style="background-color:#9c27b0"><span class="icon">👥</span>生成刘帮集团的人物关系图
</button>
</div> </div>
<script> <script>
@ -346,76 +345,74 @@
document.getElementById('answerArea').innerHTML = ''; document.getElementById('answerArea').innerHTML = '';
} }
// 在script部分添加新函数 // 在script部分添加新函数
function generateRelation() { function generateRelation() {
const answerArea = document.getElementById('answerArea'); const answerArea = document.getElementById('answerArea');
answerArea.innerHTML = '<div class="loading-animation"><div class="spinner"></div><div>正在生成人物关系图...</div></div>'; answerArea.innerHTML = '<div class="loading-animation"><div class="spinner"></div><div>正在生成人物关系图...</div></div>';
fetch('/api/rag', { fetch('/api/rag', {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Accept': 'text/event-stream' 'Accept': 'text/event-stream'
}, },
body: JSON.stringify({ body: JSON.stringify({
query: "生成刘帮集团的人物关系图", query: "生成刘帮集团的人物关系图",
topic: "ShiJi", topic: "ShiJi",
mode: "hybrid", mode: "hybrid",
output_model: "html" output_model: "html"
})
}) })
}) .then(response => {
.then(response => { const reader = response.body.getReader();
const reader = response.body.getReader(); const decoder = new TextDecoder();
const decoder = new TextDecoder(); let buffer = '';
let buffer = ''; let accumulatedContent = '';
let accumulatedContent = '';
function processChunk() {
function processChunk() { return reader.read().then(({done, value}) => {
return reader.read().then(({done, value}) => { if (done) return;
if (done) {
// 在HTML内容完全接收后执行其中的脚本 buffer += decoder.decode(value, {stream: true});
const scripts = answerArea.getElementsByTagName('script'); const lines = buffer.split('\n');
for (let i = 0; i < scripts.length; i++) { buffer = lines.pop();
try {
eval(scripts[i].innerHTML);
} catch (e) {
console.error('脚本执行错误:', e);
}
}
return;
}
buffer += decoder.decode(value, {stream: true}); for (const line of lines) {
const lines = buffer.split('\n'); if (line.includes('data:')) {
buffer = lines.pop(); const jsonStr = line.replace(/^data:\s*/, '').replace(/^data:\s*/, '').trim();
if (jsonStr) {
for (const line of lines) { try {
if (line.includes('data:')) { const data = JSON.parse(jsonStr);
const jsonStr = line.replace(/^data:\s*/, '').replace(/^data:\s*/, '').trim(); if (data.reply) {
if (jsonStr) { accumulatedContent += data.reply;
try { answerArea.innerHTML = marked.parse(accumulatedContent, markedOptions);
const data = JSON.parse(jsonStr); MathJax.typesetPromise();
if (data.reply) { }
accumulatedContent += data.reply; } catch (e) {
answerArea.innerHTML = marked.parse(accumulatedContent, markedOptions); console.log('忽略解析错误:', e);
MathJax.typesetPromise(); }
answerArea.scrollTop = answerArea.scrollHeight;
} }
} catch (e) {
console.log('忽略解析错误:', e);
} }
} }
}
return processChunk().then(() => {
// 在流处理完成后保存完整的markdown内容
localStorage.setItem('lastMarkdownContent', accumulatedContent);
});
});
} }
return processChunk(); return processChunk();
})
.catch(error => {
// 移除加载动画
answerArea.innerHTML = '';
console.error('Error:', error);
// 出错时也移除加载动画
answerArea.innerHTML = '<div style="color:red">请求出错,请重试</div>';
}); });
} }
return processChunk();
})
.catch(error => {
answerArea.innerHTML = '<div style="color:red">生成关系图出错,请重试</div>';
});
}
</script> </script>
<script src="/static/mathjax/es5/tex-mml-chtml.js" id="MathJax-script" async></script> <script src="/static/mathjax/es5/tex-mml-chtml.js" id="MathJax-script" async></script>
<script src="/static/js/marked.min.js"></script> <script src="/static/js/marked.min.js"></script>

Loading…
Cancel
Save