From 51877df13075ad10ef51107f15bcd21f1661febe Mon Sep 17 00:00:00 2001
From: zhou zhou <3272660260@qq.com>
Date: 星期二, 17 三月 2026 09:48:01 +0800
Subject: [PATCH] #AI
---
rsf-admin/src/ai/AiChatWidget.jsx | 61 ++++++++++++++++++++++++++----
1 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/rsf-admin/src/ai/AiChatWidget.jsx b/rsf-admin/src/ai/AiChatWidget.jsx
index 9c713e7..9a5bcf0 100644
--- a/rsf-admin/src/ai/AiChatWidget.jsx
+++ b/rsf-admin/src/ai/AiChatWidget.jsx
@@ -32,6 +32,7 @@
const DRAWER_WIDTH = 720;
const SESSION_WIDTH = 220;
+const DIAGNOSIS_MESSAGE = '璇峰褰撳墠WMS绯荤粺杩涜涓�娆″贰妫�璇婃柇锛岀粨鍚堝簱瀛樸�佷换鍔°�佽澶囩珯鐐规暟鎹瘑鍒紓甯稿苟缁欏嚭澶勭悊寤鸿銆�';
const parseSseChunk = (chunk, onEvent) => {
const blocks = chunk.split('\n\n');
@@ -269,14 +270,12 @@
}
};
- const handleSend = async () => {
- if (!draft.trim() || !activeSessionId || sending) {
+ const streamChat = async ({ userContent, endpoint, sceneCode }) => {
+ if (!userContent || !activeSessionId || sending) {
return;
}
- const userContent = draft.trim();
const sessionId = activeSessionId;
const modelCode = activeSession?.modelCode || models[0]?.code;
- setDraft('');
setError('');
setSending(true);
setMessagesBySession((prev) => {
@@ -304,7 +303,7 @@
let receivedDelta = false;
try {
- const response = await fetch(`${PREFIX_BASE_URL}ai/chat/stream`, {
+ const response = await fetch(`${PREFIX_BASE_URL}${endpoint}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
@@ -314,7 +313,8 @@
body: JSON.stringify({
sessionId,
message: userContent,
- modelCode
+ modelCode,
+ sceneCode
}),
signal: controller.signal
});
@@ -392,6 +392,30 @@
setSending(false);
streamControllerRef.current = null;
}
+ };
+
+ const handleSend = async () => {
+ if (!draft.trim() || !activeSessionId || sending) {
+ return;
+ }
+ const userContent = draft.trim();
+ setDraft('');
+ await streamChat({
+ userContent,
+ endpoint: 'ai/chat/stream',
+ sceneCode: 'general_chat'
+ });
+ };
+
+ const handleDiagnose = async () => {
+ if (!activeSessionId || sending) {
+ return;
+ }
+ await streamChat({
+ userContent: DIAGNOSIS_MESSAGE,
+ endpoint: 'ai/diagnose/stream',
+ sceneCode: 'system_diagnose'
+ });
};
const assistantReplyText = (messageList) => {
@@ -575,6 +599,15 @@
</MenuItem>
))}
</Select>
+ <Button
+ variant="outlined"
+ size="small"
+ disabled={sending || !activeSessionId}
+ onClick={handleDiagnose}
+ sx={{ borderRadius: 2, whiteSpace: 'nowrap' }}
+ >
+ 涓�閿瘖鏂�
+ </Button>
</Stack>
<Divider />
<Box
@@ -609,8 +642,11 @@
寮�濮嬫柊鐨勬櫤鑳藉璇�
</Typography>
<Typography variant="body2">
- 鍙互鐩存帴鎻愰棶浠撳偍涓氬姟闂锛屾垨鍒囨崲妯″瀷寮�濮嬫柊鐨勪細璇濄��
+ 鍙互鐩存帴鎻愰棶浠撳偍涓氬姟闂锛屾垨鐐瑰嚮涓�閿瘖鏂揩閫熷贰妫�褰撳墠WMS鐘舵�併��
</Typography>
+ <Button variant="outlined" onClick={handleDiagnose} disabled={sending || !activeSessionId}>
+ 涓�閿瘖鏂�
+ </Button>
</Stack>
) : (
<Stack spacing={2}>
@@ -704,6 +740,15 @@
label={activeSession?.modelCode || '鏈�夋嫨妯″瀷'}
sx={{ bgcolor: 'rgba(25,118,210,0.08)', color: 'primary.main' }}
/>
+ <Button
+ variant="text"
+ size="small"
+ disabled={sending || !activeSessionId}
+ onClick={handleDiagnose}
+ sx={{ minWidth: 'auto', px: 1 }}
+ >
+ 涓�閿瘖鏂�
+ </Button>
<Typography variant="caption" color="text.secondary">
`Enter` 鍙戦�侊紝`Shift + Enter` 鎹㈣
</Typography>
@@ -715,7 +760,7 @@
maxRows={6}
value={draft}
onChange={(event) => setDraft(event.target.value)}
- placeholder="杈撳叆闂锛屾敮鎸佸浼氳瘽鍜屾ā鍨嬪垏鎹�"
+ placeholder="杈撳叆闂锛屾敮鎸佸浼氳瘽銆佸妯″瀷鍜屼竴閿瘖鏂�"
onKeyDown={(event) => {
if (event.key === 'Enter' && !event.shiftKey) {
event.preventDefault();
--
Gitblit v1.9.1