Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daabce8a5f | ||
|
|
5a51845e12 | ||
|
|
2c69bd7c91 | ||
|
|
a129211e5e | ||
|
|
e8279a2deb | ||
|
|
2408d980e5 |
@@ -8,12 +8,12 @@
|
||||
<link rel="icon" href="/favicon.ico" />
|
||||
<script src="/node_modules/ace-builds/src-min-noconflict/ace.js" type="text/javascript"></script>
|
||||
<title>NPCs</title>
|
||||
<script type="module" crossorigin src="/assets/index-583c10b3.js"></script>
|
||||
<script type="module" crossorigin src="/assets/index-e0228455.js"></script>
|
||||
<link rel="modulepreload" crossorigin href="/assets/acebuilds-fbc0ccc6.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/reactflow-c250d835.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/reactdrop-be699031.js">
|
||||
<link rel="modulepreload" crossorigin href="/assets/pdfjs-36654f0a.js">
|
||||
<link rel="stylesheet" href="/assets/index-1055532c.css">
|
||||
<link rel="stylesheet" href="/assets/index-e06d93b0.css">
|
||||
</head>
|
||||
|
||||
<body id='body' style="width: 100%; height:100%">
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
"machineName": "服务名",
|
||||
"addOne": "加一条"
|
||||
},
|
||||
|
||||
"flow": {
|
||||
"unsavedChangesConfirmation": "您有未保存的更改,确定要离开吗?",
|
||||
"leave": "离开",
|
||||
|
||||
28
package-lock.json
generated
28
package-lock.json
generated
@@ -51,6 +51,7 @@
|
||||
"cmdk": "^0.2.0",
|
||||
"daisyui": "^3.6.3",
|
||||
"dompurify": "^3.0.5",
|
||||
"echarts": "^5.5.1",
|
||||
"esbuild": "^0.17.19",
|
||||
"i18next": "^23.6.0",
|
||||
"i18next-http-backend": "^2.2.2",
|
||||
@@ -6778,6 +6779,20 @@
|
||||
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
|
||||
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA=="
|
||||
},
|
||||
"node_modules/echarts": {
|
||||
"version": "5.5.1",
|
||||
"resolved": "https://registry.npmmirror.com/echarts/-/echarts-5.5.1.tgz",
|
||||
"integrity": "sha512-Fce8upazaAXUVUVsjgV6mBnGuqgO+JNDlcgF79Dksy4+wgGpQB2lmYoO4TSweFg/mZITdpGHomw/cNBJZj1icA==",
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0",
|
||||
"zrender": "5.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/echarts/node_modules/tslib": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz",
|
||||
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.4.750",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.750.tgz",
|
||||
@@ -17240,6 +17255,19 @@
|
||||
"url": "https://github.com/sponsors/colinhacks"
|
||||
}
|
||||
},
|
||||
"node_modules/zrender": {
|
||||
"version": "5.6.0",
|
||||
"resolved": "https://registry.npmmirror.com/zrender/-/zrender-5.6.0.tgz",
|
||||
"integrity": "sha512-uzgraf4njmmHAbEUxMJ8Oxg+P3fT04O+9p7gY+wJRVxo8Ge+KmYv0WJev945EH4wFuc4OY2NLXz46FZrWS9xJg==",
|
||||
"dependencies": {
|
||||
"tslib": "2.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/zrender/node_modules/tslib": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz",
|
||||
"integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg=="
|
||||
},
|
||||
"node_modules/zustand": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/zustand/-/zustand-4.5.2.tgz",
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
"cmdk": "^0.2.0",
|
||||
"daisyui": "^3.6.3",
|
||||
"dompurify": "^3.0.5",
|
||||
"echarts": "^5.5.1",
|
||||
"esbuild": "^0.17.19",
|
||||
"i18next": "^23.6.0",
|
||||
"i18next-http-backend": "^2.2.2",
|
||||
|
||||
@@ -179,6 +179,7 @@
|
||||
"machineName": "服务名",
|
||||
"addOne": "加一条"
|
||||
},
|
||||
|
||||
"flow": {
|
||||
"unsavedChangesConfirmation": "您有未保存的更改,确定要离开吗?",
|
||||
"leave": "离开",
|
||||
|
||||
142
src/components/Chart/index.tsx
Normal file
142
src/components/Chart/index.tsx
Normal file
@@ -0,0 +1,142 @@
|
||||
import { useEffect, useRef } from "react";
|
||||
import * as echarts from "echarts";
|
||||
|
||||
function Chart({ options }) {
|
||||
const chartRef = useRef(null);
|
||||
let chartInstance = null;
|
||||
|
||||
options = eval('('+options.substring(8)+')');
|
||||
// options = {
|
||||
// "chartType": "line",
|
||||
// "xData": [
|
||||
// "江苏",
|
||||
// "浙江",
|
||||
// "广东",
|
||||
// "广州",
|
||||
// "北京",
|
||||
// "山西",
|
||||
// "河北"
|
||||
// ],
|
||||
// "data": {
|
||||
// "2023上半年":['120%', '132%', '101%', '134%', '90%', '230%', '210%'],
|
||||
// "2024上半年":['220%', '182%', '191%', '234%', '290%', '330%', '310%']
|
||||
// },
|
||||
// "legend": [],
|
||||
// "pieData": []
|
||||
// }
|
||||
options.legend = Object.keys(options.data);
|
||||
options.pieData = [];
|
||||
options.series = [];
|
||||
|
||||
options.xData.map((data,index) =>{
|
||||
if(options.data[options.legend[0]][index] &&options.data[options.legend[0]][index].indexOf("%") !== -1){
|
||||
options.pieData.push({'name':data,'value':options.data[options.legend[0]][index].split("%").join("")})
|
||||
}else{
|
||||
options.pieData.push({'name':data,'value':options.data[options.legend[0]][index]})
|
||||
}
|
||||
})
|
||||
options.legend.map((data,index) =>{
|
||||
let list = [];
|
||||
options.data[data].map(data1 =>{
|
||||
console.log(data1.indexOf('%'))
|
||||
if(data1.indexOf('%') !== -1){
|
||||
list.push(data1.split("%").join(""))
|
||||
}else{
|
||||
list.push(data1)
|
||||
}
|
||||
});
|
||||
options.series.push({
|
||||
name: data,
|
||||
type: options.chartType,
|
||||
data: list,
|
||||
})
|
||||
})
|
||||
console.log(options)
|
||||
let options1;
|
||||
if(options.chartType == "pie"){
|
||||
options1 = {
|
||||
tooltip: {},
|
||||
series: [
|
||||
{
|
||||
name: 'Access From',
|
||||
type: 'pie',
|
||||
radius: '50%',
|
||||
label: {
|
||||
normal: {
|
||||
|
||||
textStyle: { // 提示文字的样式
|
||||
color: '#fff',
|
||||
fontSize: 14
|
||||
}
|
||||
}
|
||||
},
|
||||
data: options.pieData,
|
||||
emphasis: {
|
||||
itemStyle: {
|
||||
shadowBlur: 10,
|
||||
shadowOffsetX: 0,
|
||||
shadowColor: 'rgba(0, 0, 0, 0.5)'
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
}else{
|
||||
options1 = {
|
||||
tooltip: {
|
||||
trigger: 'axis'
|
||||
},
|
||||
xAxis: {
|
||||
data: options.xData,
|
||||
},
|
||||
yAxis: {},
|
||||
series: options.series,
|
||||
};
|
||||
}
|
||||
// 定义渲染函数
|
||||
function renderChart() {
|
||||
try {
|
||||
// `echarts.getInstanceByDom` 可以从已经渲染成功的图表中获取实例,其目的就是在 options 发生改变的时候,不需要
|
||||
// 重新创建图表,而是复用该图表实例,提升性能
|
||||
const renderedInstance = echarts.getInstanceByDom(chartRef.current);
|
||||
if (renderedInstance) {
|
||||
chartInstance = renderedInstance;
|
||||
} else {
|
||||
chartInstance = echarts.init(chartRef.current);
|
||||
}
|
||||
chartInstance.setOption(options1);
|
||||
} catch (error) {
|
||||
console.error("error", error.message);
|
||||
chartInstance && chartInstance.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// 定义窗口大小发生改变执行的回调函数
|
||||
function resizeHandler() {
|
||||
chartInstance.resize();
|
||||
}
|
||||
|
||||
// 页面初始化时,开始渲染图表
|
||||
useEffect(() => {
|
||||
renderChart();
|
||||
|
||||
return () => {
|
||||
// 销毁图表实例,释放内存
|
||||
chartInstance && chartInstance.dispose();
|
||||
};
|
||||
}, []);
|
||||
|
||||
// 监听窗口大小改变
|
||||
useEffect(() => {
|
||||
window.addEventListener("resize", resizeHandler);
|
||||
return () => window.removeEventListener("resize", resizeHandler);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div style={{ width: "800px", height: "400px" }} ref={chartRef} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default Chart;
|
||||
@@ -200,6 +200,7 @@ export default function ChatInput({ clear, form, questions, inputForm, wsUrl, on
|
||||
flow_id: data.flow_id,
|
||||
chat_id: data.chat_id,
|
||||
message: data.message,
|
||||
reasoning_content: data.reasoning_content,
|
||||
thought: data.intermediate_steps
|
||||
})
|
||||
} else if (['end', 'end_cover'].includes(data.type)) {
|
||||
|
||||
@@ -3,7 +3,7 @@ import { LoadIcon } from "@/components/bs-icons/loading";
|
||||
import { CodeBlock } from "@/modals/formModal/chatMessage/codeBlock";
|
||||
import { ChatMessageType } from "@/types/chat";
|
||||
import { copyText } from "@/utils";
|
||||
import { useMemo, useRef } from "react";
|
||||
import { useMemo, useRef, useState } from "react";
|
||||
import ReactMarkdown from "react-markdown";
|
||||
import rehypeMathjax from "rehype-mathjax";
|
||||
import remarkGfm from "remark-gfm";
|
||||
@@ -22,7 +22,7 @@ import npcIcon from "../../../assets/npc/npcIcon.png";
|
||||
import nengliIcon from "../../../assets/npc/nengliIcon.png";
|
||||
import { TitleIconBg } from "../cardComponent";
|
||||
import Thumbs from "@/pages/ChatAppPage/components/Thumbs";
|
||||
|
||||
import Chart from "@/components/Chart"
|
||||
// 颜色列表
|
||||
const colorList = [
|
||||
"#111",
|
||||
@@ -81,11 +81,50 @@ export default function MessageBs({ data, onUnlike = () => { }, flow_type, onSou
|
||||
[data.message, data.message.toString()]
|
||||
)
|
||||
|
||||
const mkdownReasoning = useMemo(
|
||||
() => (
|
||||
<ReactMarkdown
|
||||
remarkPlugins={[remarkGfm, remarkMath]}
|
||||
rehypePlugins={[rehypeMathjax]}
|
||||
linkTarget="_blank"
|
||||
className="bs-mkdown inline-block break-all max-w-full text-sm text-text-answer "
|
||||
components={{
|
||||
code: ({ node, inline, className, children, ...props }) => {
|
||||
if (children.length) {
|
||||
if (children[0] === "▍") {
|
||||
return (<span className="form-modal-markdown-span"> ▍ </span>);
|
||||
}
|
||||
|
||||
children[0] = (children[0] as string).replace("`▍`", "▍");
|
||||
}
|
||||
|
||||
const match = /language-(\w+)/.exec(className || "");
|
||||
|
||||
return !inline ? (
|
||||
<CodeBlock
|
||||
key={Math.random()}
|
||||
language={(match && match[1]) || ""}
|
||||
value={String(children).replace(/\n$/, "")}
|
||||
{...props}
|
||||
/>
|
||||
) : (
|
||||
<code className={className} {...props}> {children} </code>
|
||||
);
|
||||
},
|
||||
}}
|
||||
>
|
||||
{data.reasoning_content ? data.reasoning_content.toString() : ""}
|
||||
</ReactMarkdown>
|
||||
),
|
||||
[data.reasoning_content, data.reasoning_content ? data.reasoning_content.toString() : ""]
|
||||
)
|
||||
|
||||
const messageRef = useRef<HTMLDivElement>(null)
|
||||
const handleCopyMessage = () => {
|
||||
copyText(messageRef.current)
|
||||
}
|
||||
// console.log(data)
|
||||
// let shenduOff = useRef(true)
|
||||
const [shenduOff, setShenduOff] = useState(true)
|
||||
const chatId = useMessageStore(state => state.chatId)
|
||||
return <div className="flex w-full py-1">
|
||||
<div className="w-[100%]">
|
||||
@@ -104,16 +143,30 @@ export default function MessageBs({ data, onUnlike = () => { }, flow_type, onSou
|
||||
{/* 光标 */}
|
||||
{/* {data.message.toString() && !data.end && <div className="animate-cursor absolute w-2 h-5 ml-1 bg-gray-600" style={{ left: cursor.x, top: cursor.y }}></div>} */}
|
||||
{/* </div> */}
|
||||
{/* <div className="App">
|
||||
<Chart options={data.message} />
|
||||
</div>
|
||||
{data.message.toString() ?
|
||||
<div className="chat-start-zk relative">
|
||||
{mkdown}
|
||||
{data.receiver && <p className="text-blue-500 text-sm">@ {data.receiver.user_name}</p>}
|
||||
|
||||
</div>
|
||||
: <div><LoadIcon className="text-gray-400" /></div>
|
||||
} */}
|
||||
{(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && data.message.toString().includes('```chart') && <Chart options={data.message} />}
|
||||
{(data.message.toString() || (data.reasoning_content && data.reasoning_content.toString())) && !data.message.toString().includes('```chart') && <div className="chat-start-zk relative">
|
||||
{(data.reasoning_content && data.reasoning_content.toString()) && <div className="shendu">
|
||||
<div className="shenduBtn" onClick={() => {setShenduOff(!shenduOff)}}>深度思考 <svg className={`${!shenduOff && 'transform180'}`} width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.786 4.167L2.765 1.259c-.416-.4-.985-.482-1.273-.183-.287.298-.183.864.233 1.264l3.021 2.908c.416.4.986.482 1.273.184.287-.299.183-.865-.233-1.265z" fill="currentColor"></path><path d="M8.197 1.206L5.288 4.208c-.4.413-.484.982-.187 1.27.298.289.864.187 1.265-.227L9.274 2.25c.401-.414.485-.983.187-1.271-.297-.288-.863-.187-1.264.227z" fill="currentColor"></path></svg></div>
|
||||
{shenduOff && <div className="shenduText">{mkdownReasoning}</div>}
|
||||
</div>}
|
||||
<div className="mt-[10px]">{mkdown}</div>
|
||||
{/* @user */}
|
||||
{data.receiver && <p className="text-blue-500 text-sm">@ {data.receiver.user_name}</p>}
|
||||
{/* 光标 */}
|
||||
{/* {data.message.toString() && !data.end && <div className="animate-cursor absolute w-2 h-5 ml-1 bg-gray-600" style={{ left: cursor.x, top: cursor.y }}></div>} */}
|
||||
</div>
|
||||
: <div><LoadIcon className="text-gray-400" /></div>
|
||||
}
|
||||
</div>}
|
||||
{(!data.message.toString() && !data.reasoning_content.toString()) && <div><LoadIcon className="text-gray-400" /></div>}
|
||||
|
||||
{/* 赞 踩 */}
|
||||
{!!data.id && data.end && <Thumbs
|
||||
|
||||
@@ -75,7 +75,6 @@ export default function MessagePanne({ useName, guideWord, loadMore, flow_type }
|
||||
} else if (msg.thought) {
|
||||
type = 'system'
|
||||
}
|
||||
// console.log(type)
|
||||
switch (type) {
|
||||
case 'user':
|
||||
return <MessageUser key={msg.id} useName={useName} data={msg} />;
|
||||
|
||||
@@ -50,9 +50,10 @@ const handleHistoryMsg = (data: any[]): ChatMessageType[] => {
|
||||
.replace(/'/g, '"'); // 将单引号替换为双引号
|
||||
return data.map(item => {
|
||||
// let count = 0
|
||||
let { message, files, is_bot, intermediate_steps, ...other } = item
|
||||
let { message,reasoning_content, files, is_bot, intermediate_steps, ...other } = item
|
||||
try {
|
||||
message = message && message[0] === '{' ? JSON.parse(message) : message || ''
|
||||
reasoning_content = reasoning_content && reasoning_content[0] === '{' ? JSON.parse(reasoning_content) : reasoning_content || ''
|
||||
} catch (e) {
|
||||
// 未考虑的情况暂不处理
|
||||
console.error('消息 to JSON error :>> ', e);
|
||||
@@ -64,6 +65,7 @@ const handleHistoryMsg = (data: any[]): ChatMessageType[] => {
|
||||
files: files ? JSON.parse(files) : [],
|
||||
isSend: !is_bot,
|
||||
message,
|
||||
reasoning_content,
|
||||
thought: intermediate_steps,
|
||||
noAccess: true
|
||||
}
|
||||
@@ -134,6 +136,7 @@ export const useMessageStore = create<State & Actions>((set, get) => ({
|
||||
newChat.push({
|
||||
isSend: false,
|
||||
message: runLogsTypes.includes(data.category) ? JSON.parse(data.message) : '',
|
||||
reasoning_content: runLogsTypes.includes(data.category) ? JSON.parse(data.reasoning_content) : '',
|
||||
chatKey: '',
|
||||
thought: data.intermediate_steps || '',
|
||||
category: data.category || '',
|
||||
@@ -165,6 +168,7 @@ export const useMessageStore = create<State & Actions>((set, get) => ({
|
||||
...wsdata,
|
||||
id: isRunLog ? wsdata.extra : wsdata.messageId, // 每条消息必唯一
|
||||
message: isRunLog ? JSON.parse(wsdata.message) : currentMessage.message + wsdata.message,
|
||||
reasoning_content: isRunLog ? JSON.parse(wsdata.reasoning_content) : currentMessage.reasoning_content + wsdata.reasoning_content,
|
||||
thought: currentMessage.thought + (wsdata.thought ? `${wsdata.thought}\n` : ''),
|
||||
files: wsdata.files || null,
|
||||
category: wsdata.category || '',
|
||||
@@ -243,6 +247,7 @@ const bsMsgItem = {
|
||||
id: Math.random() * 1000000,
|
||||
isSend: false,
|
||||
message: '',
|
||||
reasoning_content: '',
|
||||
chatKey: '',
|
||||
thought: '',
|
||||
category: '',
|
||||
|
||||
@@ -13,6 +13,7 @@ import { ChatMessageType } from "../../../types/chat";
|
||||
import { classNames } from "../../../utils";
|
||||
import FileCard from "../fileComponent";
|
||||
import { CodeBlock } from "./codeBlock";
|
||||
import Chart from "@/components/Chart";
|
||||
export default function ChatMessage({
|
||||
chat,
|
||||
lockChat,
|
||||
@@ -26,6 +27,8 @@ export default function ChatMessage({
|
||||
const [hidden, setHidden] = useState(true);
|
||||
const template = chat.template;
|
||||
const [promptOpen, setPromptOpen] = useState(false);
|
||||
|
||||
console.log(chat.message)
|
||||
return (
|
||||
<div
|
||||
className={classNames("form-modal-chat-position", chat.isSend ? "human-word" : "robert-word")}
|
||||
@@ -76,6 +79,9 @@ export default function ChatMessage({
|
||||
<div className="w-full">
|
||||
<div className="w-full dark:text-white">
|
||||
<div className="w-full">
|
||||
|
||||
{chat.message.toString() && chat.message.toString().includes('```chart') && <Chart options={chat.message} />}
|
||||
|
||||
{useMemo(
|
||||
() => (
|
||||
<ReactMarkdown
|
||||
@@ -125,7 +131,9 @@ export default function ChatMessage({
|
||||
},
|
||||
}}
|
||||
>
|
||||
{chat.message.toString()}
|
||||
{chat.message.toString() && !chat.message.toString().includes('```chart') && chat.message.toString()}
|
||||
|
||||
{/* {chat.message.toString()} */}
|
||||
</ReactMarkdown>
|
||||
),
|
||||
[chat.message, chat.message.toString()]
|
||||
|
||||
@@ -4214,4 +4214,23 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.shenduBtn{
|
||||
width: 100px;
|
||||
padding: 7px 14px;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 10px;
|
||||
cursor: pointer;
|
||||
color: #999999;
|
||||
}
|
||||
.transform180{
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
.shenduText{
|
||||
color: #999999;
|
||||
margin-top: 10px;
|
||||
line-height: 26px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { FlowType } from "../flow";
|
||||
|
||||
export type ChatType = { flow: FlowType; reactFlowInstance: ReactFlowInstance };
|
||||
export type ChatMessageType = {
|
||||
reasoning_content: string | Object;
|
||||
message: string | Object;
|
||||
template?: string;
|
||||
isSend: boolean;
|
||||
|
||||
@@ -8,7 +8,7 @@ import path from "path";
|
||||
// Use environment variable to determine the target.
|
||||
// const target = process.env.VITE_PROXY_TARGET || "http://localhost:7860";
|
||||
const target = process.env.VITE_PROXY_TARGET || "http://npcall.ai:3003";
|
||||
// const target = process.env.VITE_PROXY_TARGET || "http://172.30.40.241:7866";
|
||||
// const target = process.env.VITE_PROXY_TARGET || "http://172.30.96.205:7880";
|
||||
|
||||
const proxyTargets = apiRoutes.reduce((proxyObj, route) => {
|
||||
proxyObj[route] = {
|
||||
|
||||
Reference in New Issue
Block a user