Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
R
risk-monitor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
蔡建
risk-monitor
Commits
71d717e6
提交
71d717e6
authored
12月 08, 2025
作者:
coderBryanFu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update
上级
35021936
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
163 行增加
和
34 行删除
+163
-34
chat.js
src/api/chat.js
+10
-0
index.vue
src/views/comprehensiveSearch/chat/index.vue
+148
-34
vite.config.js
vite.config.js
+5
-0
没有找到文件。
src/api/chat.js
浏览文件 @
71d717e6
...
...
@@ -7,3 +7,12 @@ export function getChat(params) {
data
:
params
,
})
}
// 清单问答
export
function
getChecklistChat
(
params
)
{
return
request
({
method
:
'POST'
,
url
:
`/checklistChat/langgraph/checklist/chat-stream`
,
data
:
params
,
})
}
\ No newline at end of file
src/views/comprehensiveSearch/chat/index.vue
浏览文件 @
71d717e6
...
...
@@ -85,9 +85,9 @@
<div
class=
"text"
>
{{
`正在思考中,请稍候`
}}
</div>
</div>
<div
class=
"loading-indicator"
>
<span
class=
"dot"
></span>
<span
class=
"dot"
></span>
<span
class=
"dot"
></span>
<span
v-show=
"loadingDotIndex
<
3
"
class=
"dot"
></span>
<span
v-show=
"loadingDotIndex > 0"
class=
"dot"
></span>
<span
v-show=
"loadingDotIndex === 2"
class=
"dot"
></span>
</div>
</div>
</div>
...
...
@@ -140,7 +140,7 @@ import { ref, onMounted, onUnmounted, nextTick } from "vue";
import
{
fetchEventSource
}
from
"@microsoft/fetch-event-source"
;
import
MarkdownIt
from
"markdown-it"
;
import
{
ElMessage
}
from
"element-plus"
;
import
{
getChat
}
from
"@/api/chat"
;
import
{
getChat
,
getChecklistChat
}
from
"@/api/chat"
;
import
router
from
"@/router/index"
;
import
json5
from
"json5"
;
...
...
@@ -152,24 +152,8 @@ const areaList = ref([
value
:
"法案"
},
{
label
:
"政令"
,
value
:
"政令"
},
{
label
:
"智库"
,
value
:
"智库"
},
{
label
:
"出口管制"
,
value
:
"出口管制"
},
{
label
:
"投融资限制"
,
value
:
"投融资限制"
},
{
label
:
"市场准入限制"
,
value
:
"市场准入限制"
label
:
"清单"
,
value
:
"清单"
}
]);
...
...
@@ -186,6 +170,8 @@ const userInput = ref("");
const
isLoading
=
ref
(
false
);
const
abortController
=
ref
(
null
);
const
loadingDotIndex
=
ref
(
0
);
// 消息数据
const
messages
=
ref
([
// {
...
...
@@ -369,6 +355,13 @@ const connectSSE = async question => {
addMessage
(
"ai"
,
""
);
isLoading
.
value
=
true
;
const
loadingInterval
=
setInterval
(()
=>
{
if
(
loadingDotIndex
.
value
<
2
)
{
loadingDotIndex
.
value
++
;
}
else
{
loadingDotIndex
.
value
=
0
;
}
},
500
);
// 创建 AbortController 用于取消请求
abortController
.
value
=
new
AbortController
();
...
...
@@ -394,6 +387,7 @@ const connectSSE = async question => {
openWhenHidden
:
true
,
async
onopen
(
res
)
{
isLoading
.
value
=
false
;
clearInterval
(
loadingInterval
);
console
.
log
(
"流式回答开始"
,
res
);
},
async
onmessage
(
res
)
{
...
...
@@ -465,21 +459,138 @@ const connectSSE = async question => {
});
};
const
chat
=
async
()
=>
{
function
formatDateTime
(
isoString
)
{
const
date
=
new
Date
(
isoString
);
// 获取各个时间部分
const
year
=
date
.
getFullYear
();
const
month
=
String
(
date
.
getMonth
()
+
1
).
padStart
(
2
,
"0"
);
// 月份从0开始
const
day
=
String
(
date
.
getDate
()).
padStart
(
2
,
"0"
);
const
hours
=
String
(
date
.
getHours
()).
padStart
(
2
,
"0"
);
const
minutes
=
String
(
date
.
getMinutes
()).
padStart
(
2
,
"0"
);
const
seconds
=
String
(
date
.
getSeconds
()).
padStart
(
2
,
"0"
);
return
`
${
year
}
-
${
month
}
-
${
day
}
${
hours
}
:
${
minutes
}
:
${
seconds
}
`
;
}
const
chat
=
async
question
=>
{
// 添加用户消息
addMessage
(
"user"
,
question
);
const
params
=
{
query
:
"如何检索?"
,
knowledge_base_name
:
"kb_test251112"
,
top_k
:
6
,
score_threshold
:
0.5
,
metadata
:
{
year
:
2024
}
model
:
"neko-checklist-agent"
,
// messages: [
// {
// role: "user",
// content: "2024年12月5日当期实体清单的主要制裁对象、制裁原因是?"
// }
// ]
messages
:
messages
.
value
.
map
(
item
=>
{
return
{
role
:
item
.
type
===
"ai"
?
"assistant"
:
"user"
,
content
:
item
.
content
};
})
};
try
{
const
res
=
await
getChat
(
params
);
console
.
log
(
"chat"
,
res
);
}
catch
(
error
)
{
console
.
error
(
error
);
// 添加空的 AI 消息用于流式更新
addMessage
(
"ai"
,
""
);
isLoading
.
value
=
true
;
const
loadingInterval
=
setInterval
(()
=>
{
if
(
loadingDotIndex
.
value
<
2
)
{
loadingDotIndex
.
value
++
;
}
else
{
loadingDotIndex
.
value
=
0
;
}
},
500
);
// 创建 AbortController 用于取消请求
abortController
.
value
=
new
AbortController
();
fetchEventSource
(
"/checklistChat/langgraph/checklist/chat-stream"
,
{
method
:
"POST"
,
headers
:
{
"Content-Type"
:
"application/json"
},
body
:
JSON
.
stringify
(
params
),
signal
:
abortController
.
value
.
signal
,
openWhenHidden
:
true
,
async
onopen
(
res
)
{
isLoading
.
value
=
false
;
clearInterval
(
loadingInterval
);
console
.
log
(
"流式回答开始"
,
res
);
},
async
onmessage
(
res
)
{
console
.
log
(
"res"
,
res
);
if
(
res
.
data
===
"[DONE]"
)
{
ElMessage
.
success
(
"生成完成!"
);
}
let
msgData
=
JSON
.
parse
(
res
.
data
);
if
(
msgData
.
logs
)
{
console
.
log
(
"docs"
,
msgData
.
logs
);
const
lastMessage
=
messages
.
value
[
messages
.
value
.
length
-
1
];
if
(
lastMessage
&&
lastMessage
.
type
===
"ai"
)
{
let
newDocs
=
msgData
.
logs
.
map
(
item
=>
{
return
item
.
detail
+
" "
+
formatDateTime
(
item
.
ts
);
});
lastMessage
.
source
=
newDocs
;
scrollToBottom
();
}
}
if
(
msgData
.
choices
&&
msgData
.
choices
[
0
].
delta
.
content
)
{
isCurAnswerMessage
.
value
=
true
;
let
content
=
msgData
.
choices
[
0
].
delta
.
content
;
if
(
content
===
"[DONE]"
)
{
ElMessage
.
success
(
"生成完成!"
);
}
else
{
aiMessage
.
value
+=
content
;
updateLastAIMessage
(
aiMessage
.
value
);
}
}
// if (res.event === "end_of_workflow") {
// ElMessage.success("问答完成!");
// abortController.value.abort();
// abortController.value = new AbortController();
// return;
// }
// if (res.event === "start_of_agent" && msgData.agent_name === "answer") {
// isCurAnswerMessage.value = true;
// aiMessage.value = "";
// }
// if (res.event === "message") {
// let content = msgData.delta.content;
// console.log("msgData", msgData);
// console.log("content", content);
// if (content !== "[DONE]") {
// aiMessage.value += content;
// updateLastAIMessage(aiMessage.value);
// } else {
// aiMessage.value = "";
// abortController.value.abort();
// abortController.value = new AbortController();
// }
// }
},
onerror
(
error
)
{
ElMessage
({
message
:
"问答报错!"
,
type
:
"warning"
});
abortController
.
value
.
abort
();
abortController
.
value
=
new
AbortController
();
throw
new
Error
(
error
);
}
}).
catch
(
error
=>
{
ElMessage
({
message
:
"问答报错!"
,
type
:
"warning"
});
abortController
.
value
.
abort
();
abortController
.
value
=
new
AbortController
();
throw
new
Error
(
error
);
});
};
// 发送消息
...
...
@@ -496,8 +607,11 @@ const sendMessage = async () => {
}
userInput
.
value
=
""
;
if
(
curArea
.
value
===
"法案"
)
{
await
connectSSE
(
question
);
// chat();
}
else
{
chat
(
question
);
}
};
const
newChatTitle
=
ref
(
""
);
// 新对话
...
...
vite.config.js
浏览文件 @
71d717e6
...
...
@@ -56,6 +56,11 @@ export default defineConfig({
target
:
'http://192.168.184.24:7861/'
,
changeOrigin
:
true
,
rewrite
:
(
path
)
=>
path
.
replace
(
/^
\/
aichat/
,
''
)
},
'/checklistChat'
:
{
target
:
'http://8.140.26.4:10021/'
,
changeOrigin
:
true
,
rewrite
:
(
path
)
=>
path
.
replace
(
/^
\/
checklistChat/
,
''
)
}
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论