🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
UiChatEventHandler.hpp
浏览该文件的文档.
1
22
23#pragma once
24
25#include "AstGlobal.h"
26#include "AstAI/ChatEventHandler.hpp"
27#include "AstUtil/MarkdownHTMLRenderer.hpp"
28#include <QObject>
29#include <atomic>
30
31AST_NAMESPACE_BEGIN
32
43class AST_UIAI_API UiChatEventHandler : public QObject, public ChatEventHandler
44{
45 Q_OBJECT
46
47public:
48 explicit UiChatEventHandler(QObject* parent = nullptr);
49 ~UiChatEventHandler() override;
50
51 // —— ChatEventHandler 接口 ——
52
53 void onContentChunk(const std::string& text) override;
54 void onContentComplete(const std::string& text) override;
55 void onReasoningChunk(const std::string& reasoning) override;
56 void onReasoningComplete(const std::string& reasoning) override;
57 void onToolCallRequest(const std::string& toolCallId,
58 const std::string& functionName,
59 const std::string& arguments) override;
60 void onToolCallResult(const std::string& toolCallId,
61 const std::string& functionName,
62 const std::string& result) override;
63 void onComplete() override;
64 void onError(const std::string& error) override;
65
67 bool isCancelled() const override;
68
69public Q_SLOTS:
71 void cancel();
72
74 void reset();
75
76Q_SIGNALS:
78 void contentChunk(const QString& chunk);
79
81 void htmlChunk(const QString& html);
82
84 void contentComplete(const QString& text);
85
87 void reasoningChunk(const QString& reasoning);
88
90 void reasoningComplete(const QString& reasoning);
91
93 void toolCallRequest(const QString& callId,
94 const QString& funcName,
95 const QString& args);
96
98 void toolCallResult(const QString& callId,
99 const QString& funcName,
100 const QString& output);
101
103 void completed();
104
106 void errorOccurred(const QString& errMsg);
107
108private:
109 std::atomic<bool> cancelled_{false};
110 MarkdownHTMLRenderer mdRenderer_; // 流式 Markdown→HTML 渲染器
111};
112
115AST_NAMESPACE_END
流式聊天事件处理器
定义 ChatEventHandler.hpp:42
virtual bool isCancelled() const
检查是否被取消
定义 ChatEventHandler.hpp:94
virtual void onComplete()
本轮对话完成
定义 ChatEventHandler.hpp:86
virtual void onToolCallRequest(const std::string &toolCallId, const std::string &functionName, const std::string &arguments)
LLM 请求调用工具(含完整函数名和参数)
定义 ChatEventHandler.hpp:71
virtual void onReasoningComplete(const std::string &reasoning)
收到完整推理内容
定义 ChatEventHandler.hpp:62
virtual void onReasoningChunk(const std::string &reasoning)
收到一块推理内容(delta)
定义 ChatEventHandler.hpp:58
virtual void onContentChunk(const std::string &text)
收到一块文本内容(delta)
定义 ChatEventHandler.hpp:51
virtual void onError(const std::string &error)
发生错误
定义 ChatEventHandler.hpp:90
virtual void onContentComplete(const std::string &text)
收到完整文本内容
定义 ChatEventHandler.hpp:54
virtual void onToolCallResult(const std::string &toolCallId, const std::string &functionName, const std::string &result)
工具执行完毕,返回结果
定义 ChatEventHandler.hpp:79
HTML 流式渲染器
定义 MarkdownHTMLRenderer.hpp:38
流式聊天事件的 Qt 信号桥接器
定义 UiChatEventHandler.hpp:44
void toolCallResult(const QString &callId, const QString &funcName, const QString &output)
工具执行完毕
void contentChunk(const QString &chunk)
收到原始文本增量(Markdown 原文)
void errorOccurred(const QString &errMsg)
发生错误
void reasoningChunk(const QString &reasoning)
收到推理内容增量
void toolCallRequest(const QString &callId, const QString &funcName, const QString &args)
LLM 请求调用工具
void reasoningComplete(const QString &reasoning)
推理内容完成
void htmlChunk(const QString &html)
收到转换后的 HTML 增量(Markdown→HTML 流式渲染结果)
void contentComplete(const QString &text)
文本内容完成,携带完整文本
void completed()
本轮对话完成