NIM 跨平台 C++ SDK
载入中...
搜索中...
未找到
nim_ai_helper.h
浏览该文件的文档.
1
7#ifndef NIM_AI_HELPER_H
8#define NIM_AI_HELPER_H
9
10#include <functional>
11#include <list>
12#include <map>
13#include <string>
15#include "nim_define_include.h"
16#include "nim_user_helper.h"
17
18namespace nim {
19
23 std::string msg_;
25 int32_t type_{0};
26};
27
33 std::string msg_;
35 int32_t type_{0};
36};
37
41 bool antispam_enabled_{true};
44 void ToJsonValue(nim_cpp_wrapper_util::Json::Value& values) const;
45 std::string ToJsonString() const;
46};
47
61};
62
66 std::string prompt_;
68 int32_t max_tokens_{0};
70 float top_p_{0.0};
72 float temperature_{0.0};
73
74 void SetPrompt(const std::string& prompt) {
75 prompt_ = prompt;
76 field_valid_flags_ |= kAIModelConfigFieldFlagPrompt;
77 }
78 std::string GetPrompt() const { return prompt_; }
79 void SetMaxTokens(int32_t max_tokens) {
80 max_tokens_ = max_tokens;
81 field_valid_flags_ |= kAIModelConfigFieldFlagMaxTokens;
82 }
83 int32_t GetMaxTokens() const { return max_tokens_; }
84 void SetTopP(float top_p) {
85 top_p_ = top_p;
86 field_valid_flags_ |= kAIModelConfigFieldFlagTopP;
87 }
88 float GetTopP() const { return top_p_; }
89 void SetTemperature(float temperature) {
90 temperature_ = temperature;
91 field_valid_flags_ |= kAIModelConfigFieldFlagTemperature;
92 }
93 float GetTemperature() const { return temperature_; }
94
95 bool ExistValue(NIMAIModelConfigFieldFlag flag) const { return (field_valid_flags_ & flag) != 0; }
96
97protected:
98 unsigned int field_valid_flags_{0};
99};
100
102
105 std::string account_id_;
109 std::list<NIMAIModelCallMessage> messages_;
111 std::string prompt_variables_;
114 void ToJsonValue(nim_cpp_wrapper_util::Json::Value& values) const;
115 nim_cpp_wrapper_util::Json::Value ToJsonValue() const;
116};
117
121 std::string account_id_;
123 std::string request_id_;
126 void FromJsonString(const std::string& json_string) {
128 ParseJsonValue(json_string, values);
130 account_id_ = values[kNIMAICallKeyAccountID].asString();
132 request_id_ = values[kNIMAICallKeyRequestID].asString();
133 if (values.isMember(kNIMAICallKeyContent)) {
134 const auto& content = values[kNIMAICallKeyContent];
135 if (content.isMember(kNIMAICallKeyContentKeyMsg))
136 content_.msg_ = content[kNIMAICallKeyContentKeyMsg].asString();
137 if (content.isMember(kNIMAICallKeyContentKeyType))
138 content_.type_ = content[kNIMAICallKeyContentKeyType].asInt();
139 }
140 }
141};
142
146 std::string model_;
148 std::list<std::string> prompt_keys_;
149
150 void SetModel(const std::string& model) {
151 model_ = model;
152 field_valid_flags_ |= kAIModelConfigFieldFlagModel;
153 }
154 std::string GetModel() const { return model_; }
155 void SetPromptKeys(const std::list<std::string>& prompt_keys) {
156 prompt_keys_ = prompt_keys;
157 field_valid_flags_ |= kAIModelConfigFieldFlagPromptKeys;
158 }
159 std::list<std::string> GetPromptKeys() const { return prompt_keys_; }
160};
161
164
165};
166
173
174 void SetModelType(NIMAIModelType model_type) {
175 model_type_ = model_type;
176 value_available_flag_ |= kUserNameCardKeyModelType;
177 }
178 NIMAIModelType GetModelType() const { return model_type_; }
179
180 void SetModelConfig(const NIMAIModelConfig& model_config) {
181 model_config_ = model_config;
182 value_available_flag_ |= kUserNameCardKeyModelConfig;
183 }
184 NIMAIModelConfig GetModelConfig() const { return model_config_; }
185
186 std::string ToJsonString() const;
187 nim_cpp_wrapper_util::Json::Value ToJsonObject() const;
188};
189
196NIM_SDK_CPPWRAPPER_DLL_API bool ParseAIUserNameCards(const std::string& namecards_json, std::list<AIUserNameCard>& namecards);
197
204NIM_SDK_CPPWRAPPER_DLL_API bool ParseAIUserNameCards(const nim_cpp_wrapper_util::Json::Value& namecards_json, std::list<AIUserNameCard>& namecards);
205
212NIM_SDK_CPPWRAPPER_DLL_API bool ParseAIUserNameCard(const std::string& namecard_json, AIUserNameCard& namecard);
213
220NIM_SDK_CPPWRAPPER_DLL_API void ParseAIUserNameCard(const nim_cpp_wrapper_util::Json::Value& namecard_json, AIUserNameCard& namecard);
221
228NIM_SDK_CPPWRAPPER_DLL_API void ParseAIUserModelConfig(const nim_cpp_wrapper_util::Json::Value& model_config_json, NIMAIModelConfig& model_config);
229
230} // namespace nim
231
232#endif // NIM_AI_HELPER_H
Represents a JSON value.
Definition: value.h:196
bool isMember(const char *key) const
Definition: json_value.cpp:1241
String asString() const
Embedded zeroes are possible.
Definition: json_value.cpp:632
namespace nim
bool ParseJsonValue(const std::string &content, nim_cpp_wrapper_util::Json::Value &values)
解析JsonString
Definition: nim_json_util.cpp:70
@ kUserNameCardKeyModelConfig
Model config 字段有效
Definition: nim_user_helper.h:44
@ kUserNameCardKeyModelType
Model type 字段有效
Definition: nim_user_helper.h:42
void ParseAIUserModelConfig(const nim_cpp_wrapper_util::Json::Value &model_config_json, NIMAIModelConfig &model_config)
解析数字人模型配置
Definition: nim_ai_helper.cpp:179
bool ParseAIUserNameCards(const std::string &namecards_json, std::list< AIUserNameCard > &namecards)
Definition: nim_ai_helper.cpp:114
NIMAIModelConfigFieldFlag
Definition: nim_ai_helper.h:48
@ kAIModelConfigFieldFlagTemperature
Temperature 字段有效
Definition: nim_ai_helper.h:56
@ kAIModelConfigFieldFlagPromptKeys
Prompt keys 字段有效
Definition: nim_ai_helper.h:60
@ kAIModelConfigFieldFlagModel
Model 字段有效
Definition: nim_ai_helper.h:58
@ kAIModelConfigFieldFlagMaxTokens
Max tokens 字段有效
Definition: nim_ai_helper.h:52
@ kAIModelConfigFieldFlagTopP
Top p 字段有效
Definition: nim_ai_helper.h:54
@ kAIModelConfigFieldFlagPrompt
Prompt 字段有效
Definition: nim_ai_helper.h:50
bool ParseAIUserNameCard(const std::string &namecard_json, AIUserNameCard &namecard)
Definition: nim_ai_helper.cpp:136
AIUserNameCardFieldFlag
AI 数字人名片字段有效性校验
Definition: nim_ai_helper.h:163
NIMAIModelType
AI 数字人消息模型类型
Definition: nim_ai_def.h:69
NIMAIModelRoleType
AI 数字人消息角色类型
Definition: nim_ai_def.h:59
@ kNIMMessageAIModelRoleTypeSystem
系统
Definition: nim_ai_def.h:61
static const char * kNIMAICallKeyContentKeyMsg
请求/响应的文本内容
Definition: nim_ai_def.h:20
static const char * kNIMAICallKeyRequestID
AI proxy 请求 ID
Definition: nim_ai_def.h:13
static const char * kNIMAICallKeyAccountID
string AI account id
Definition: nim_ai_def.h:11
static const char * kNIMAICallKeyContentKeyType
类型, 暂时只有 0, 代表文本, 预留扩展能力
Definition: nim_ai_def.h:22
static const char * kNIMAICallKeyContent
请求大模型的内容
Definition: nim_ai_def.h:18
NIM 公共数据类型定义总的包含文件
定义导出宏
#define NIM_SDK_CPPWRAPPER_DLL_API
Definition: nim_sdk_cpp_wrapper.h:38
SDK用户信息辅助方法
AI 数字人用户信息
Definition: nim_ai_helper.h:168
NIMAIModelType model_type_
模型选择
Definition: nim_ai_helper.h:170
void SetModelType(NIMAIModelType model_type)
Definition: nim_ai_helper.h:174
NIMAIModelConfig GetModelConfig() const
Definition: nim_ai_helper.h:184
NIMAIModelConfig model_config_
模型相关配置文件
Definition: nim_ai_helper.h:172
void SetModelConfig(const NIMAIModelConfig &model_config)
Definition: nim_ai_helper.h:180
NIMAIModelType GetModelType() const
Definition: nim_ai_helper.h:178
Definition: nim_ai_helper.h:103
NIMAIModelCallContent content_
请求大模型的内容
Definition: nim_ai_helper.h:107
std::string prompt_variables_
提示词变量占位符替换
Definition: nim_ai_helper.h:111
NIMAIModelConfigParams model_config_params_
请求接口模型相关参数配置, 如果参数不为空,则默认覆盖控制相关配置
Definition: nim_ai_helper.h:113
std::string account_id_
机器人账号 ID
Definition: nim_ai_helper.h:105
std::list< NIMAIModelCallMessage > messages_
上下文内容
Definition: nim_ai_helper.h:109
调用大模型的请求内容
Definition: nim_ai_helper.h:21
std::string msg_
请求/响应的文本内容
Definition: nim_ai_helper.h:23
int32_t type_
类型, 暂时只有 0, 代表文本, 预留扩展能力
Definition: nim_ai_helper.h:25
AI 数字人消息上下文参数
Definition: nim_ai_helper.h:29
std::string msg_
上下文的内容
Definition: nim_ai_helper.h:33
AI 数字人代理请求结果
Definition: nim_ai_helper.h:119
void FromJsonString(const std::string &json_string)
Definition: nim_ai_helper.h:126
std::string request_id_
本次响应的标识
Definition: nim_ai_helper.h:123
NIMAIModelCallContent content_
请求 AI 的回复
Definition: nim_ai_helper.h:125
std::string account_id_
数字人的账号 ID
Definition: nim_ai_helper.h:121
AI 数字人模型配置参数
Definition: nim_ai_helper.h:64
bool ExistValue(NIMAIModelConfigFieldFlag flag) const
Definition: nim_ai_helper.h:95
void SetTemperature(float temperature)
Definition: nim_ai_helper.h:89
float GetTopP() const
Definition: nim_ai_helper.h:88
void SetPrompt(const std::string &prompt)
Definition: nim_ai_helper.h:74
std::string prompt_
提示词
Definition: nim_ai_helper.h:66
std::string GetPrompt() const
Definition: nim_ai_helper.h:78
int32_t GetMaxTokens() const
Definition: nim_ai_helper.h:83
void SetMaxTokens(int32_t max_tokens)
Definition: nim_ai_helper.h:79
float GetTemperature() const
Definition: nim_ai_helper.h:93
void SetTopP(float top_p)
Definition: nim_ai_helper.h:84
AI 数字人模型类型
Definition: nim_ai_helper.h:144
std::list< std::string > prompt_keys_
提示词对应的变量
Definition: nim_ai_helper.h:148
std::list< std::string > GetPromptKeys() const
Definition: nim_ai_helper.h:159
std::string model_
具体大模型版本模型名
Definition: nim_ai_helper.h:146
void SetModel(const std::string &model)
Definition: nim_ai_helper.h:150
void SetPromptKeys(const std::list< std::string > &prompt_keys)
Definition: nim_ai_helper.h:155
std::string GetModel() const
Definition: nim_ai_helper.h:154
AI 数字人代理请求反垃圾配置
Definition: nim_ai_helper.h:39
std::string antispam_business_id_
指定易盾业务id
Definition: nim_ai_helper.h:43
云信用户名片
Definition: nim_user_helper.h:50