Add intent dispatch scaffold
This commit is contained in:
+31
-4
@@ -3,6 +3,7 @@
|
||||
#include "../ai/AIProviderFactory.h"
|
||||
#include "../ai/ConversationManager.h"
|
||||
#include "../ai/ConversationStore.h"
|
||||
#include "../assistant/CommandDispatcher.h"
|
||||
#include "../character/CharacterPackageLoader.h"
|
||||
#include "../character/CharacterPackageRepository.h"
|
||||
#include "../config/ConfigManager.h"
|
||||
@@ -460,19 +461,45 @@ bool PetWindow::submitChatMessage(const QString &message)
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString trimmedMessage = message.trimmed();
|
||||
if (trimmedMessage.isEmpty())
|
||||
const QString normalizedMessage = message.trimmed();
|
||||
if (normalizedMessage.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trimmedMessage.size() > MaxUserMessageLength)
|
||||
if (normalizedMessage.size() > MaxUserMessageLength)
|
||||
{
|
||||
playState(QStringLiteral("error"), false);
|
||||
showBubbleMessage(QStringLiteral("消息太长,请控制在 4000 字以内。"));
|
||||
return false;
|
||||
}
|
||||
|
||||
CommandDispatcher dispatcher;
|
||||
const CommandDispatchResult result = dispatcher.dispatch(normalizedMessage);
|
||||
if (result.action == CommandDispatchAction::UnsupportedTool)
|
||||
{
|
||||
playState(QStringLiteral("talk"), false);
|
||||
showBubbleMessage(result.message);
|
||||
return true;
|
||||
}
|
||||
|
||||
return submitAiChatMessage(result.message);
|
||||
}
|
||||
|
||||
bool PetWindow::submitAiChatMessage(const QString &message)
|
||||
{
|
||||
if (!m_conversationManager || m_conversationManager->isBusy())
|
||||
{
|
||||
showBubbleMessage(QStringLiteral("AI 回复正在进行。"));
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString chatMessage = message.trimmed();
|
||||
if (chatMessage.isEmpty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigManager configManager;
|
||||
AIConfig config = configManager.loadAIConfig();
|
||||
QString errorMessage;
|
||||
@@ -507,7 +534,7 @@ bool PetWindow::submitChatMessage(const QString &message)
|
||||
|
||||
QPointer<PetWindow> window(this);
|
||||
m_conversationManager->sendUserMessageStreaming(
|
||||
trimmedMessage,
|
||||
chatMessage,
|
||||
[window](const QString &delta) {
|
||||
if (!window.isNull())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user