118 lines
3.1 KiB
C++
118 lines
3.1 KiB
C++
#ifndef CTAI_BASE_H
|
||
#define CTAI_BASE_H
|
||
|
||
#include <iostream>
|
||
#include <QString>
|
||
|
||
#ifndef QSL
|
||
#define QSL(str) (QString::fromStdString)(str)
|
||
#endif
|
||
|
||
#ifndef QSN
|
||
#define QSN(str) (QString::number)(str)
|
||
#endif
|
||
|
||
// tokens消耗数据
|
||
typedef struct tokens_args
|
||
{
|
||
QString prompt_tokens = {};
|
||
QString completion_tokens = {};
|
||
QString total_tokens = {};
|
||
QString cache_hit_tokens = {};
|
||
QString cache_miss_tokens = {};
|
||
} tokens_data;
|
||
|
||
//插入SEND信息框模式,主要区分插入和重试
|
||
typedef enum HISTORY_SEND_MODE{
|
||
HISTORY_SEND_INSERT,
|
||
HISTORY_SEND_RESTART
|
||
}HISTORY_SEND_MODE;
|
||
|
||
// 消息模式,主要用于区分传入ctaiHistoryTextEdit控件信息来源
|
||
typedef enum msg_mode{
|
||
SYSTEM,
|
||
USER
|
||
}msg_type;
|
||
//CURL配置
|
||
typedef struct curl_opts
|
||
{
|
||
bool ssl_state = true;
|
||
int timeout = 120;
|
||
bool followlocation = false;
|
||
bool keepalive = false;
|
||
bool verbose = true;
|
||
} curl_opts;
|
||
//模型参数和数据,包含大模型返回数据
|
||
typedef struct model_data{
|
||
std::string api_url = "https://api.deepseek.com/chat/completions";
|
||
std::string api_key = "Authorization: Bearer sk-7e6932ed45674c389dea1cd3481e0ec2";
|
||
std::string user_model = "deepseek-chat";
|
||
//std::string api_url="https://api.siliconflow.cn/v1/chat/completions";
|
||
//std::string api_key="Authorization: Bearer sk-oiphigpzqtmkkcoucyakrfevcvndroywvxhprvscjqhdykdb";
|
||
//std::string user_model = "deepseek-ai/DeepSeek-V3";
|
||
std::string send_content_header = "Content-Type: application/json";
|
||
std::string send_accept_header = "Accept: application/json";
|
||
std::string send_user_data;
|
||
std::string send_user_time;
|
||
std::string send_user_id;
|
||
std::string send_user_ico;
|
||
std::string postback_model_data;
|
||
msg_type msg_type_mode;
|
||
std::string send_system_ico;
|
||
bool postback_stream_mode = false;
|
||
std::string postback_time;
|
||
std::string postback_server_model;
|
||
std::string postback_finish_reason;
|
||
std::string postback_send_id;
|
||
std::string postback_system_fingerprint;
|
||
// 提示消耗tokens
|
||
int postback_prompt_tokens;
|
||
// 生成消耗tokens
|
||
int postback_completion_tokens;
|
||
// 总消耗tokens
|
||
int postback_total_tokens;
|
||
// 提示命中缓存tokens
|
||
int postback_prompt_cache_hit_tokens;
|
||
// 生成未命中缓存tokens
|
||
int postback_prompt_cache_miss_tokens;
|
||
//请求体,不可采用临时变量
|
||
std::string request_body;
|
||
}model_data;
|
||
|
||
// 将全角符号转换为半角符号的映射
|
||
const QMap<QString, QString> fullToHalfMap = {
|
||
{",", ","},
|
||
{"。", "."},
|
||
{"!", "!"},
|
||
{"?", "?"},
|
||
{":", ":"},
|
||
{";", ";"},
|
||
{"(", "("},
|
||
{")", ")"},
|
||
{"[", "["},
|
||
{"]", "]"},
|
||
{"【", "["},
|
||
{"】", "]"},
|
||
{"{", "{"},
|
||
{"}", "}"},
|
||
{"|", "|"},
|
||
{""", "\""},
|
||
{"'", "'"},
|
||
{" ̄", "~"},
|
||
{"<", "<"},
|
||
{">", ">"},
|
||
{"=", "="},
|
||
{"+", "+"},
|
||
{"-", "-"},
|
||
{"*", "*"},
|
||
{"/", "/"},
|
||
{"%", "%"},
|
||
{"#", "#"},
|
||
{"&", "&"},
|
||
{"@", "@"},
|
||
{"`", "`"},
|
||
{" ", " "} // 全角空格转换为半角空格
|
||
};
|
||
|
||
|
||
#endif // CTAI_BASE_H
|