🛰️航天仿真算法库 SpaceAST 0.0.1
载入中...
搜索中...
未找到
ChatMessage.hpp
浏览该文件的文档.
1
20
21#pragma once
22
23#include "AstGlobal.h"
24#include "AstUtil/StringView.hpp"
25#include "AstUtil/JsonValue.hpp"
26#include <string>
27
28AST_NAMESPACE_BEGIN
29
35class JsonValue;
36
37
39enum class EChatRole {
40 eUser,
42 eSystem,
43 eTool
44};
45
46
47AST_AI_API std::string toString(EChatRole role);
48
49
52{
53public:
55 ChatMessage() = default;
56
61 : role_(role), content_(content)
62 {}
63
65 ~ChatMessage() = default;
66
71 {
72 return ChatMessage(EChatRole::eSystem, content);
73 }
74
78 static ChatMessage User(StringView content)
79 {
80 return ChatMessage(EChatRole::eUser, content);
81 }
82
87 {
88 return ChatMessage(EChatRole::eAssistant, content);
89 }
90
91 static ChatMessage Assistant(StringView content, const JsonValue& toolCalls)
92 {
93 ChatMessage msg(EChatRole::eAssistant, content);
94 msg.setToolCalls(toolCalls);
95 return msg;
96 }
97
98
99
104 static ChatMessage Tool(StringView content, StringView toolCallId)
105 {
106 ChatMessage msg(EChatRole::eTool, content);
107 msg.setToolCallId(toolCallId);
108 return msg;
109 }
110
113 AST_AI_API
114 JsonValue toJson() const;
115
117 void setRole(EChatRole role) { role_ = role; }
119 EChatRole role() const { return role_; }
120
122 void setName(const std::string& name) { name_ = name; }
124 std::string name() const { return name_; }
125
127 void setContent(StringView content) { content_ = std::string(content); }
129 std::string content() const { return content_; }
130
132 void setReasoningContent(StringView reasoningContent) { reasoningContent_ = std::string(reasoningContent); }
134 std::string reasoningContent() const { return reasoningContent_; }
135
137 void setToolCallId(StringView toolCallId) { toolCallId_ = std::string(toolCallId); }
138
140 std::string toolCallId() const { return toolCallId_; }
141
142
144 void setToolCalls(const JsonValue& toolCalls) { toolCalls_ = toolCalls; }
145
147 const JsonValue& toolCalls() const { return toolCalls_; }
148
149private:
150 EChatRole role_{EChatRole::eUser};
151 std::string name_;
152 std::string content_;
153 std::string reasoningContent_;
154 std::string toolCallId_;
155 JsonValue toolCalls_;
156};
157
158
161AST_NAMESPACE_END
聊天消息
定义 ChatMessage.hpp:52
static ChatMessage User(StringView content)
创建用户消息
定义 ChatMessage.hpp:78
void setToolCallId(StringView toolCallId)
设置工具调用ID
定义 ChatMessage.hpp:137
static ChatMessage Tool(StringView content, StringView toolCallId)
创建工具消息
定义 ChatMessage.hpp:104
ChatMessage(EChatRole role, StringView content)
构造函数
定义 ChatMessage.hpp:60
static ChatMessage Assistant(StringView content)
创建助手消息
定义 ChatMessage.hpp:86
void setRole(EChatRole role)
设置消息角色
定义 ChatMessage.hpp:117
std::string name() const
获取角色名称
定义 ChatMessage.hpp:124
void setToolCalls(const JsonValue &toolCalls)
设置工具调用列表
定义 ChatMessage.hpp:144
const JsonValue & toolCalls() const
获取工具调用列表
定义 ChatMessage.hpp:147
std::string reasoningContent() const
获取推理内容
定义 ChatMessage.hpp:134
EChatRole role() const
获取消息角色
定义 ChatMessage.hpp:119
static ChatMessage System(StringView content)
创建系统提示消息
定义 ChatMessage.hpp:70
std::string content() const
获取消息内容
定义 ChatMessage.hpp:129
std::string toolCallId() const
获取工具调用ID
定义 ChatMessage.hpp:140
void setName(const std::string &name)
设置角色名称
定义 ChatMessage.hpp:122
~ChatMessage()=default
析构函数
void setReasoningContent(StringView reasoningContent)
设置推理内容
定义 ChatMessage.hpp:132
void setContent(StringView content)
设置消息内容
定义 ChatMessage.hpp:127
ChatMessage()=default
构造函数
JSON 值类
定义 JsonValue.hpp:47
EChatRole
消息角色
定义 ChatMessage.hpp:39
@ eAssistant
助手