🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
ChatSession.hpp
浏览该文件的文档.
1
19
20#pragma once
21
22#include "AstGlobal.h"
23#include "AstAI/LLMClient.hpp"
24#include "AstAI/ChatAgent.hpp"
25#include "AstAI/LLMConfig.hpp"
26#include "AstAI/ChatTool.hpp"
27#include "AstAI/ChatMessages.hpp"
28#include "AstAI/ChatTools.hpp"
29#include "AstAI/AssistantAgent.hpp"
30#include <string>
31#include <vector>
32#include <functional>
33
34AST_NAMESPACE_BEGIN
35
41class AssistantAgent;
42
44class AST_AI_API ChatSession {
45public:
51
55 std::string chat(StringView message, int maxIterForToolCalls = 100);
56
61 std::string chatStream(StringView message, ChatEventHandler& handler, int maxIterForToolCalls = 100);
62
66 errc_t sendMessage(StringView message);
67
70 void setSystemPrompt(StringView systemPrompt);
71
74 ChatMessages& messages(){return messages_;}
75
78 AssistantAgent& agent() const;
79
81 void setAgent(std::unique_ptr<AssistantAgent> agent){agent_ = std::move(agent);}
82
85 ChatTools& tools(){return agent().tools();}
86
88 LLMClient& client(){return agent().client();}
89
91 const std::string& lastError() const {return agent().lastError();}
92
94 LLMConfig& config() { return agent().config(); }
96 const LLMConfig& config() const { return agent().config(); }
97
100 errc_t makeChatCompletion();
101
104 void handleToolCalls(const JsonValue& toolCalls);
105
106private:
107 mutable std::unique_ptr<AssistantAgent> agent_;
108 ChatMessages messages_;
109};
110
113AST_NAMESPACE_END
聊天智能体
定义 AssistantAgent.hpp:47
流式聊天事件处理器
定义 ChatEventHandler.hpp:42
聊天消息集合
定义 ChatMessages.hpp:39
聊天会话
定义 ChatSession.hpp:44
ChatTools & tools()
获取工具集合
定义 ChatSession.hpp:85
const LLMConfig & config() const
获取LLM配置(只读)
定义 ChatSession.hpp:96
LLMConfig & config()
获取LLM配置
定义 ChatSession.hpp:94
void setAgent(std::unique_ptr< AssistantAgent > agent)
设置聊天智能体(转移所有权)
定义 ChatSession.hpp:81
const std::string & lastError() const
获取最后一次错误信息
定义 ChatSession.hpp:91
LLMClient & client()
获取当前使用的AI接口
定义 ChatSession.hpp:88
ChatMessages & messages()
获取消息历史
定义 ChatSession.hpp:74
AI工具集合
定义 ChatTools.hpp:39
JSON 值类
定义 JsonValue.hpp:47
大语言模型客户端接口
定义 LLMClient.hpp:39
LLM请求配置
定义 LLMConfig.hpp:39