mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-11 22:30:41 +03:00
fix provider gptgo (#60)
This commit is contained in:
parent
2f2b512129
commit
1d8b3c09d7
@ -404,6 +404,18 @@ std::expected<nlohmann::json, std::string> callZeus(const std::string& host, con
|
|||||||
return rsp;
|
return rsp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string decodeBase64(const std::string& to_decode) {
|
||||||
|
auto predicted_len = 3 * to_decode.length() / 4;
|
||||||
|
auto output_buffer{std::make_unique<char[]>(predicted_len + 1)};
|
||||||
|
std::vector<unsigned char> vec_chars{to_decode.begin(), to_decode.end()};
|
||||||
|
auto output_len = EVP_DecodeBlock(reinterpret_cast<unsigned char*>(output_buffer.get()), vec_chars.data(),
|
||||||
|
static_cast<int>(vec_chars.size()));
|
||||||
|
if (predicted_len != static_cast<unsigned long>(output_len)) {
|
||||||
|
throw std::runtime_error("DecodeBase64 error");
|
||||||
|
}
|
||||||
|
return output_buffer.get();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FreeGpt::FreeGpt(Config& cfg)
|
FreeGpt::FreeGpt(Config& cfg)
|
||||||
@ -1056,20 +1068,26 @@ boost::asio::awaitable<void> FreeGpt::gptGo(std::shared_ptr<Channel> ch, nlohman
|
|||||||
auto prompt = json.at("meta").at("content").at("parts").at(0).at("content").get<std::string>();
|
auto prompt = json.at("meta").at("content").at("parts").at(0).at("content").get<std::string>();
|
||||||
|
|
||||||
std::multimap<std::string, std::string> params{
|
std::multimap<std::string, std::string> params{
|
||||||
{"q", prompt},
|
{"ask", prompt},
|
||||||
{"hlgpt", "default"},
|
|
||||||
{"hl", "en"},
|
|
||||||
};
|
};
|
||||||
auto get_token_url = std::format("https://gptgo.ai/action_get_token.php?{}", paramsToQueryStr(params));
|
|
||||||
|
|
||||||
std::string recv;
|
std::string recv;
|
||||||
Curl curl;
|
Curl curl;
|
||||||
auto ret = curl.setUrl(get_token_url)
|
auto ret = curl.setUrl("https://gptgo.ai/get_token.php")
|
||||||
.setProxy(m_cfg.http_proxy)
|
.setProxy(m_cfg.http_proxy)
|
||||||
.setRecvBodyCallback([&](std::string str) {
|
.setRecvBodyCallback([&](std::string str) {
|
||||||
recv.append(str);
|
recv.append(str);
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
|
.setBody(paramsToQueryStr(params))
|
||||||
|
.setHttpHeaders([&] -> auto {
|
||||||
|
std::unordered_multimap<std::string, std::string> headers{
|
||||||
|
{"Content-Type", "application/x-www-form-urlencoded"},
|
||||||
|
{"Accept", "*"},
|
||||||
|
{"Origin", "https://gptgo.ai"},
|
||||||
|
{"Referer", "https://gptgo.ai/"},
|
||||||
|
};
|
||||||
|
return headers;
|
||||||
|
}())
|
||||||
.perform();
|
.perform();
|
||||||
if (ret.has_value()) {
|
if (ret.has_value()) {
|
||||||
SPDLOG_ERROR("{}", ret.value());
|
SPDLOG_ERROR("{}", ret.value());
|
||||||
@ -1078,26 +1096,20 @@ boost::asio::awaitable<void> FreeGpt::gptGo(std::shared_ptr<Channel> ch, nlohman
|
|||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
SPDLOG_INFO("recv: [{}]", recv);
|
SPDLOG_INFO("recv: [{}]", recv);
|
||||||
nlohmann::json line_json = nlohmann::json::parse(recv, nullptr, false);
|
if (recv.size() < 30) {
|
||||||
if (line_json.is_discarded()) {
|
SPDLOG_ERROR("{}", ret.value());
|
||||||
SPDLOG_ERROR("json parse error: [{}]", recv);
|
|
||||||
co_await boost::asio::post(boost::asio::bind_executor(ch->get_executor(), boost::asio::use_awaitable));
|
co_await boost::asio::post(boost::asio::bind_executor(ch->get_executor(), boost::asio::use_awaitable));
|
||||||
ch->try_send(err, std::format("json parse error:{}", recv));
|
ch->try_send(err, std::format("invalid token"));
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
auto status = line_json["status"].get<bool>();
|
std::string token = recv.substr(10, recv.size() - 30);
|
||||||
if (!status) {
|
|
||||||
SPDLOG_ERROR("status is false: [{}]", recv);
|
|
||||||
co_await boost::asio::post(boost::asio::bind_executor(ch->get_executor(), boost::asio::use_awaitable));
|
|
||||||
ch->try_send(err, recv);
|
|
||||||
co_return;
|
|
||||||
}
|
|
||||||
auto token = line_json["token"].get<std::string>();
|
|
||||||
SPDLOG_INFO("token: [{}]", token);
|
SPDLOG_INFO("token: [{}]", token);
|
||||||
|
token = decodeBase64(token);
|
||||||
|
SPDLOG_INFO("decode token: [{}]", token);
|
||||||
recv.clear();
|
recv.clear();
|
||||||
auto url = std::format("https://gptgo.ai/action_ai_gpt.php?token={}", token);
|
auto url = std::format("https://api.gptgo.ai/web.php?array_chat={}", token);
|
||||||
ret = curl.setUrl(url)
|
ret = curl.setUrl(url)
|
||||||
|
.setOpt(CURLOPT_HTTPGET, 1L)
|
||||||
.setProxy(m_cfg.http_proxy)
|
.setProxy(m_cfg.http_proxy)
|
||||||
.setRecvBodyCallback([&](std::string str) {
|
.setRecvBodyCallback([&](std::string str) {
|
||||||
recv.append(str);
|
recv.append(str);
|
||||||
@ -1126,6 +1138,14 @@ boost::asio::awaitable<void> FreeGpt::gptGo(std::shared_ptr<Channel> ch, nlohman
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
})
|
})
|
||||||
|
.setHttpHeaders([&] -> auto {
|
||||||
|
std::unordered_multimap<std::string, std::string> headers{
|
||||||
|
{"Accept", "*"},
|
||||||
|
{"Origin", "https://gptgo.ai"},
|
||||||
|
{"Referer", "https://gptgo.ai/"},
|
||||||
|
};
|
||||||
|
return headers;
|
||||||
|
}())
|
||||||
.perform();
|
.perform();
|
||||||
if (ret.has_value()) {
|
if (ret.has_value()) {
|
||||||
SPDLOG_ERROR("{}", ret.value());
|
SPDLOG_ERROR("{}", ret.value());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user