text2ERP
This commit is contained in:
1 parent
fec2fc096e
commit
283ec9e7b3
11 files changed
+1379
-19
No files matched your search
@@ -138,9 +138,10 @@ export function useChat() {
|
||||
* query: 用户输入文本
|
||||
* agentId: 目标 Agent ID
|
||||
*/
|
||||
const sendMessage = async (query: string, agentId: number) => {
|
||||
const sendMessage = async (query: string, agentId: number, kbType: string = '企业知识库') => {
|
||||
console.info('[chat][send] start', {
|
||||
agentId,
|
||||
kbType,
|
||||
queryLength: query.length,
|
||||
conversationId: conversationId.value,
|
||||
});
|
||||
@@ -159,7 +160,7 @@ export function useChat() {
|
||||
}
|
||||
return messages.value[botMsgIndex] || null;
|
||||
};
|
||||
|
||||
|
||||
isThinking.value = true;
|
||||
|
||||
try {
|
||||
@@ -171,6 +172,7 @@ export function useChat() {
|
||||
query,
|
||||
agent_id: agentId,
|
||||
conversation_id: conversationId.value,
|
||||
kb_type: kbType
|
||||
})
|
||||
});
|
||||
|
||||
@@ -230,7 +232,7 @@ export function useChat() {
|
||||
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
botMsg.content += data.answer;
|
||||
botMsg.content += normalizeStreamText(data.answer);
|
||||
console.debug('[chat][sse] append answer chunk', {
|
||||
event: data.event,
|
||||
appended: data.answer.length,
|
||||
@@ -256,9 +258,15 @@ export function useChat() {
|
||||
if (typeof data.answer === 'string' && data.answer.length > 0) {
|
||||
const botMsg = ensureBotMessage();
|
||||
if (!botMsg) continue;
|
||||
botMsg.content += data.answer;
|
||||
console.debug('[chat][sse] append final answer', {
|
||||
const normalizedAnswer = normalizeStreamText(data.answer);
|
||||
if (data.replace_answer) {
|
||||
botMsg.content = normalizedAnswer;
|
||||
} else {
|
||||
botMsg.content += normalizedAnswer;
|
||||
}
|
||||
console.debug('[chat][sse] apply final answer', {
|
||||
event: data.event,
|
||||
replace: Boolean(data.replace_answer),
|
||||
appended: data.answer.length,
|
||||
total: botMsg.content.length,
|
||||
});
|
||||
@@ -296,5 +304,10 @@ export function useChat() {
|
||||
}
|
||||
};
|
||||
|
||||
const normalizeStreamText = (text: string) => {
|
||||
if (!text) return '';
|
||||
return text.replace(/\\n/g, '\n');
|
||||
};
|
||||
|
||||
return { messages, isThinking, conversationId, sendMessage };
|
||||
}
|
||||
Reference in new issue
Block a user