mirror of
https://github.com/Balshgit/gpt_chat_bot.git
synced 2025-09-10 17:20:41 +03:00
update provider geekgpt && llama2 (#50)
Update provider geekgpt && llama2
This commit is contained in:
parent
2789b33677
commit
6262059bc7
@ -1,5 +1,7 @@
|
|||||||
# Cpp FreeGPT WebUI
|
# Cpp FreeGPT WebUI
|
||||||
|
|
||||||
|
[](https://github.com/fantasy-peak/cpp-freegpt-webui/actions) [](https://github.com/fantasy-peak/cpp-freegpt-webui/actions)
|
||||||
|
|
||||||
## GPT 3.5/4
|
## GPT 3.5/4
|
||||||
|
|
||||||
<strong>NOT REQUIRE ANY API KEY</strong> ❌🔑
|
<strong>NOT REQUIRE ANY API KEY</strong> ❌🔑
|
||||||
@ -29,9 +31,7 @@ To run the application, run the following command:
|
|||||||
1. Check local g++ version, need g++ version >= gcc version 13.1.0 (GCC)
|
1. Check local g++ version, need g++ version >= gcc version 13.1.0 (GCC)
|
||||||
|
|
||||||
2. install xmake
|
2. install xmake
|
||||||
wget https://github.com/xmake-io/xmake/releases/download/v2.8.2/xmake-v2.8.2.xz.run
|
curl -kfsSL https://xmake.io/shget.text | bash -s v2.8.3
|
||||||
chmod 777 xmake-v2.8.2.xz.run
|
|
||||||
./xmake-v2.8.2.xz.run
|
|
||||||
source ~/.xmake/profile
|
source ~/.xmake/profile
|
||||||
|
|
||||||
3. install libcurl-impersonate, ubuntu (apt-get install libcurl4-openssl-dev) centos7 (yum install libcurl-devel.x86_64)
|
3. install libcurl-impersonate, ubuntu (apt-get install libcurl4-openssl-dev) centos7 (yum install libcurl-devel.x86_64)
|
||||||
@ -64,25 +64,52 @@ docker pull fantasypeak/freegpt:latest
|
|||||||
|
|
||||||
Run the application using Docker:
|
Run the application using Docker:
|
||||||
```
|
```
|
||||||
docker run --rm -p 8858:8858 -it --name freegpt fantasypeak/freegpt:latest
|
docker run -it --rm \
|
||||||
// OR
|
-p 8858:8858 \
|
||||||
docker run --rm --net=host -it --name freegpt fantasypeak/freegpt:latest
|
--name freegpt \
|
||||||
// use http_proxy
|
fantasypeak/freegpt:latest
|
||||||
docker run --rm -p 8858:8858 -it --name freegpt -e HTTP_PROXY=http://127.0.0.1:8080 -e CHAT_PATH=/chat fantasypeak/freegpt:latest
|
```
|
||||||
// set active providers
|
Run the application(use http proxy) using Docker:
|
||||||
docker run --rm -p 8858:8858 -it --name freegpt -e CHAT_PATH=/chat -e PROVIDERS="[\"gpt-4-ChatgptAi\",\"gpt-3.5-turbo-stream-DeepAi\"]" fantasypeak/freegpt:latest
|
```
|
||||||
// enable ip white list function
|
docker run --rm -it \
|
||||||
docker run --rm -p 8858:8858 -it --name freegpt -e IP_WHITE_LIST="[\"127.0.0.1\",\"192.168.1.1\"]" fantasypeak/freegpt:latest
|
-p 8858:8858 \
|
||||||
|
--name freegpt \
|
||||||
|
-e HTTP_PROXY=http://127.0.0.1:8080 \
|
||||||
|
fantasypeak/freegpt:latest
|
||||||
|
```
|
||||||
|
|
||||||
|
Configurable environment variables
|
||||||
|
```
|
||||||
|
01. CHAT_PATH=/chat
|
||||||
|
02. HTTP_PROXY=http://127.0.0.1:8080
|
||||||
|
03. PROVIDERS="[\"gpt-4-ChatgptAi\",\"gpt-3.5-turbo-stream-DeepAi\"]"
|
||||||
|
04. IP_WHITE_LIST="[\"127.0.0.1\",\"192.168.1.1\"]"
|
||||||
|
05. PORT=8858
|
||||||
|
06. HOST=0.0.0.0
|
||||||
|
07. WORK_THREAD_NUM=8
|
||||||
|
08. INTERVAL=300
|
||||||
|
09. ZEUS=http://127.0.0.1:8860
|
||||||
|
10. FLARESOLVERR=http://127.0.0.1:8191/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
### Start the Zeus Service [optional]
|
### Start the Zeus Service [optional]
|
||||||
This is not necessary, Zeus is a cpp-freegpt-webui auxiliary service, because some provider needs to perform specific operations such as get cookies and refreshing web pages etc.
|
This is not necessary, Zeus is a cpp-freegpt-webui auxiliary service, because some provider needs to perform specific operations such as get cookies and refreshing web pages etc.
|
||||||
If you need to use these specific providers, you need to start it(Zeus Docker)
|
If you need to use these specific providers, you need to start it(Zeus Docker)
|
||||||
|
|
||||||
|
Start zeus service
|
||||||
```
|
```
|
||||||
docker pull fantasypeak/freegpt-zeus:latest
|
docker run -d \
|
||||||
docker run --rm --net=host -it --name zeus fantasypeak/freegpt-zeus:latest
|
--name=zeus \
|
||||||
docker pull fantasypeak/freegpt:latest
|
-p 8860:8860 \
|
||||||
docker run --rm --net=host -it --name freegpt fantasypeak/freegpt:latest
|
--rm \
|
||||||
|
fantasypeak/freegpt-zeus:latest
|
||||||
|
```
|
||||||
|
Start the application
|
||||||
|
```
|
||||||
|
docker run -it --rm \
|
||||||
|
--net=host \
|
||||||
|
--name freegpt \
|
||||||
|
fantasypeak/freegpt:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### Start the flaresolverr docker [optional]
|
### Start the flaresolverr docker [optional]
|
||||||
@ -97,9 +124,13 @@ docker run -d \
|
|||||||
```
|
```
|
||||||
|
|
||||||
### Call OpenAi Api
|
### Call OpenAi Api
|
||||||
|
It supports calling OpenAI's API, but need set API_KEY
|
||||||
```
|
```
|
||||||
// It supports calling OpenAI's API, but need set API_KEY
|
docker run --rm -it \
|
||||||
docker run --rm -p 8858:8858 -it --name freegpt -e CHAT_PATH=/chat -e API_KEY=a40f22f2-c1a2-4b1d-a47f-55ae1a7ddbed fantasypeak/freegpt:latest
|
-p 8858:8858 \
|
||||||
|
--name freegpt \
|
||||||
|
-e API_KEY=a40f22f2-c1a2-4b1d-a47f-55ae1a7ddbed \
|
||||||
|
fantasypeak/freegpt:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### WebUI
|
### WebUI
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
#include <yaml_cpp_struct.hpp>
|
#include <yaml_cpp_struct.hpp>
|
||||||
|
|
||||||
struct Config {
|
struct Config {
|
||||||
std::string client_root_path;
|
std::string client_root_path;
|
||||||
std::size_t interval{300};
|
std::size_t interval{300};
|
||||||
std::size_t work_thread_num{8};
|
std::size_t work_thread_num{std::thread::hardware_concurrency() * 2};
|
||||||
std::string host{"0.0.0.0"};
|
std::string host{"0.0.0.0"};
|
||||||
std::string port{"8858"};
|
std::string port{"8858"};
|
||||||
std::string chat_path{"/chat"};
|
std::string chat_path{"/chat"};
|
||||||
|
@ -101,3 +101,24 @@ inline std::string createUuidString() {
|
|||||||
static thread_local boost::uuids::random_generator gen;
|
static thread_local boost::uuids::random_generator gen;
|
||||||
return boost::uuids::to_string(gen());
|
return boost::uuids::to_string(gen());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clang-format off
|
||||||
|
namespace detail {
|
||||||
|
|
||||||
|
template <typename C>
|
||||||
|
struct to_helper {};
|
||||||
|
|
||||||
|
template <typename Container, std::ranges::range R>
|
||||||
|
requires std::convertible_to<std::ranges::range_value_t<R>, typename Container::value_type>
|
||||||
|
Container operator|(R&& r, to_helper<Container>) {
|
||||||
|
return Container{r.begin(), r.end()};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template <std::ranges::range Container>
|
||||||
|
requires(!std::ranges::view<Container>)
|
||||||
|
inline auto to() {
|
||||||
|
return detail::to_helper<Container>{};
|
||||||
|
}
|
||||||
|
// clang-format on
|
||||||
|
@ -21,27 +21,6 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
namespace detail {
|
|
||||||
|
|
||||||
template <typename C>
|
|
||||||
struct to_helper {};
|
|
||||||
|
|
||||||
template <typename Container, std::ranges::range R>
|
|
||||||
requires std::convertible_to<std::ranges::range_value_t<R>, typename Container::value_type>
|
|
||||||
Container operator|(R&& r, to_helper<Container>) {
|
|
||||||
return Container{r.begin(), r.end()};
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace detail
|
|
||||||
|
|
||||||
template <std::ranges::range Container>
|
|
||||||
requires(!std::ranges::view<Container>)
|
|
||||||
inline auto to() {
|
|
||||||
return detail::to_helper<Container>{};
|
|
||||||
}
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
std::string md5(const std::string& str, bool reverse = true) {
|
std::string md5(const std::string& str, bool reverse = true) {
|
||||||
unsigned char hash[MD5_DIGEST_LENGTH];
|
unsigned char hash[MD5_DIGEST_LENGTH];
|
||||||
|
|
||||||
@ -391,6 +370,8 @@ public:
|
|||||||
if (m_curl)
|
if (m_curl)
|
||||||
curl_easy_cleanup(m_curl);
|
curl_easy_cleanup(m_curl);
|
||||||
}
|
}
|
||||||
|
Curl(const Curl&) = delete;
|
||||||
|
Curl& operator=(const Curl&) = delete;
|
||||||
|
|
||||||
auto& setUrl(std::string_view url) {
|
auto& setUrl(std::string_view url) {
|
||||||
m_url = url;
|
m_url = url;
|
||||||
@ -2245,75 +2226,45 @@ boost::asio::awaitable<void> FreeGpt::llama2(std::shared_ptr<Channel> ch, nlohma
|
|||||||
|
|
||||||
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>();
|
||||||
|
|
||||||
struct Input {
|
static std::unordered_multimap<std::string, std::string> headers{
|
||||||
std::shared_ptr<Channel> ch;
|
{"Accept", "*/*"},
|
||||||
std::string recv;
|
{"origin", "https://www.llama2.ai"},
|
||||||
|
{"referer", "https://www.llama2.ai/"},
|
||||||
|
{"Content-Type", "text/plain;charset=UTF-8"},
|
||||||
};
|
};
|
||||||
Input input;
|
auto ret = Curl()
|
||||||
|
.setUrl("https://www.llama2.ai/api")
|
||||||
|
.setProxy(m_cfg.http_proxy)
|
||||||
|
.setRecvHeadersCallback([](std::string) { return; })
|
||||||
|
.setRecvBodyCallback([&](std::string str) mutable {
|
||||||
|
boost::asio::post(ch->get_executor(), [=, str = std::move(str)] { ch->try_send(err, str); });
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.setBody([&] {
|
||||||
|
constexpr std::string_view ask_json_str = R"({
|
||||||
|
"prompt":"[INST] hello [/INST]\n[INST] hello [/INST]\n",
|
||||||
|
"version":"d24902e3fa9b698cc208b5e63136c4e26e828659a9f09827ca6ec5bb83014381",
|
||||||
|
"systemPrompt":"You are a helpful assistant.",
|
||||||
|
"temperature":0.75,
|
||||||
|
"topP":0.9,
|
||||||
|
"maxTokens":800,
|
||||||
|
"image":null,
|
||||||
|
"audio":null
|
||||||
|
})";
|
||||||
|
nlohmann::json ask_request = nlohmann::json::parse(ask_json_str, nullptr, false);
|
||||||
|
ask_request["prompt"] = std::format("[INST] {} [/INST]\n", prompt);
|
||||||
|
std::string ask_request_str = ask_request.dump();
|
||||||
|
SPDLOG_INFO("ask_request_str: [{}]", ask_request_str);
|
||||||
|
return ask_request_str;
|
||||||
|
}())
|
||||||
|
.clearHeaders()
|
||||||
|
.setHttpHeaders(headers)
|
||||||
|
.perform();
|
||||||
|
|
||||||
CURLcode res;
|
|
||||||
CURL* curl = curl_easy_init();
|
|
||||||
if (!curl) {
|
|
||||||
auto error_info = std::format("curl_easy_init() failed:{}", curl_easy_strerror(res));
|
|
||||||
co_await boost::asio::post(boost::asio::bind_executor(ch->get_executor(), boost::asio::use_awaitable));
|
|
||||||
ch->try_send(err, error_info);
|
|
||||||
co_return;
|
|
||||||
}
|
|
||||||
ScopeExit auto_exit{[=] { curl_easy_cleanup(curl); }};
|
|
||||||
|
|
||||||
auto ret = sendHttpRequest(CurlHttpRequest{
|
|
||||||
.curl = curl,
|
|
||||||
.url = "https://www.llama2.ai/api",
|
|
||||||
.http_proxy = m_cfg.http_proxy,
|
|
||||||
.cb = [](void* contents, size_t size, size_t nmemb, void* userp) mutable -> size_t {
|
|
||||||
auto input_ptr = static_cast<Input*>(userp);
|
|
||||||
std::string data{(char*)contents, size * nmemb};
|
|
||||||
auto& [ch, recv] = *input_ptr;
|
|
||||||
boost::asio::post(ch->get_executor(), [=] {
|
|
||||||
boost::system::error_code err{};
|
|
||||||
ch->try_send(err, data);
|
|
||||||
});
|
|
||||||
return size * nmemb;
|
|
||||||
},
|
|
||||||
.input = [&] -> void* {
|
|
||||||
input.recv.clear();
|
|
||||||
input.ch = ch;
|
|
||||||
return &input;
|
|
||||||
}(),
|
|
||||||
.headers = [&] -> auto& {
|
|
||||||
static std::unordered_map<std::string, std::string> headers{
|
|
||||||
{"Accept", "*/*"},
|
|
||||||
{"origin", "https://www.llama2.ai"},
|
|
||||||
{"referer", "https://www.llama2.ai/"},
|
|
||||||
{"Content-Type", "text/plain;charset=UTF-8"},
|
|
||||||
};
|
|
||||||
return headers;
|
|
||||||
}(),
|
|
||||||
.body = [&] -> std::string {
|
|
||||||
constexpr std::string_view ask_json_str = R"({
|
|
||||||
"prompt":"[INST] hello [/INST]\n[INST] hello [/INST]\n",
|
|
||||||
"version":"d24902e3fa9b698cc208b5e63136c4e26e828659a9f09827ca6ec5bb83014381",
|
|
||||||
"systemPrompt":"You are a helpful assistant.",
|
|
||||||
"temperature":0.75,
|
|
||||||
"topP":0.9,
|
|
||||||
"maxTokens":800,
|
|
||||||
"image":null,
|
|
||||||
"audio":null
|
|
||||||
})";
|
|
||||||
nlohmann::json ask_request = nlohmann::json::parse(ask_json_str, nullptr, false);
|
|
||||||
ask_request["prompt"] = std::format("[INST] {} [/INST]\n", prompt);
|
|
||||||
std::string ask_request_str = ask_request.dump();
|
|
||||||
SPDLOG_INFO("ask_request_str: [{}]", ask_request_str);
|
|
||||||
return ask_request_str;
|
|
||||||
}(),
|
|
||||||
.response_header_ptr = nullptr,
|
|
||||||
.expect_response_code = 200,
|
|
||||||
.ssl_verify = false,
|
|
||||||
});
|
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
SPDLOG_ERROR("https://www.llama2.ai/api: [{}]", ret.value());
|
||||||
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, ret.value());
|
ch->try_send(err, ret.value());
|
||||||
co_return;
|
|
||||||
}
|
}
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
@ -2418,102 +2369,77 @@ boost::asio::awaitable<void> FreeGpt::geekGpt(std::shared_ptr<Channel> ch, nlohm
|
|||||||
co_await boost::asio::post(boost::asio::bind_executor(*m_thread_pool_ptr, boost::asio::use_awaitable));
|
co_await boost::asio::post(boost::asio::bind_executor(*m_thread_pool_ptr, boost::asio::use_awaitable));
|
||||||
ScopeExit _exit{[=] { boost::asio::post(ch->get_executor(), [=] { ch->close(); }); }};
|
ScopeExit _exit{[=] { boost::asio::post(ch->get_executor(), [=] { ch->close(); }); }};
|
||||||
boost::system::error_code err{};
|
boost::system::error_code err{};
|
||||||
|
static std::unordered_multimap<std::string, std::string> headers{
|
||||||
auto prompt = json.at("meta").at("content").at("parts").at(0).at("content").get<std::string>();
|
{"Accept", "*/*"},
|
||||||
|
{"authority", "ai.fakeopen.com"},
|
||||||
struct Input {
|
{"content-type", "application/json"},
|
||||||
std::shared_ptr<Channel> ch;
|
{"referer", "https://chat.geekgpt.org/"},
|
||||||
std::string recv;
|
{"origin", "https://chat.geekgpt.org"},
|
||||||
|
{"sec-ch-ua", R"("Google Chrome";v="117", "Not;A=Brand";v="8", "Chromium";v="117")"},
|
||||||
|
{"sec-ch-ua-mobile", R"(?0)"},
|
||||||
|
{"sec-ch-ua-platform", R"("macOS")"},
|
||||||
|
{"cache-control", "no-cache"},
|
||||||
|
{"pragma", "no-cache"},
|
||||||
|
{"authorization", "Bearer pk-this-is-a-real-free-pool-token-for-everyone"},
|
||||||
};
|
};
|
||||||
Input input;
|
std::string recv;
|
||||||
|
auto ret = Curl()
|
||||||
CURLcode res;
|
.setUrl("https://ai.fakeopen.com/v1/chat/completions")
|
||||||
CURL* curl = curl_easy_init();
|
.setProxy(m_cfg.http_proxy)
|
||||||
if (!curl) {
|
.setRecvHeadersCallback([](std::string) { return; })
|
||||||
auto error_info = std::format("curl_easy_init() failed:{}", curl_easy_strerror(res));
|
.setRecvBodyCallback([&](std::string str) mutable {
|
||||||
co_await boost::asio::post(boost::asio::bind_executor(ch->get_executor(), boost::asio::use_awaitable));
|
recv.append(str);
|
||||||
ch->try_send(err, error_info);
|
while (true) {
|
||||||
co_return;
|
auto position = recv.find("\n");
|
||||||
}
|
if (position == std::string::npos)
|
||||||
ScopeExit auto_exit{[=] { curl_easy_cleanup(curl); }};
|
break;
|
||||||
|
auto msg = recv.substr(0, position + 1);
|
||||||
auto ret = sendHttpRequest(CurlHttpRequest{
|
recv.erase(0, position + 1);
|
||||||
.curl = curl,
|
msg.pop_back();
|
||||||
.url = "https://ai.fakeopen.com/v1/chat/completions",
|
if (msg.empty() || !msg.contains("content"))
|
||||||
.http_proxy = m_cfg.http_proxy,
|
continue;
|
||||||
.cb = [](void* contents, size_t size, size_t nmemb, void* userp) mutable -> size_t {
|
auto fields = splitString(msg, "data: ");
|
||||||
auto input_ptr = static_cast<Input*>(userp);
|
boost::system::error_code err{};
|
||||||
std::string data{(char*)contents, size * nmemb};
|
nlohmann::json line_json = nlohmann::json::parse(fields.back(), nullptr, false);
|
||||||
auto& [ch, recv] = *input_ptr;
|
if (line_json.is_discarded()) {
|
||||||
recv.append(data);
|
SPDLOG_ERROR("json parse error: [{}]", fields.back());
|
||||||
while (true) {
|
boost::asio::post(ch->get_executor(), [=] {
|
||||||
auto position = recv.find("\n");
|
ch->try_send(err, std::format("json parse error: [{}]", fields.back()));
|
||||||
if (position == std::string::npos)
|
});
|
||||||
break;
|
continue;
|
||||||
auto msg = recv.substr(0, position + 1);
|
}
|
||||||
recv.erase(0, position + 1);
|
auto str = line_json["choices"][0]["delta"]["content"].get<std::string>();
|
||||||
msg.pop_back();
|
if (!str.empty() && str != "[DONE]")
|
||||||
if (msg.empty() || !msg.contains("content"))
|
boost::asio::post(ch->get_executor(), [=] { ch->try_send(err, str); });
|
||||||
continue;
|
}
|
||||||
auto fields = splitString(msg, "data: ");
|
return;
|
||||||
boost::system::error_code err{};
|
})
|
||||||
nlohmann::json line_json = nlohmann::json::parse(fields.back(), nullptr, false);
|
.setBody([&] {
|
||||||
if (line_json.is_discarded()) {
|
constexpr std::string_view ask_json_str = R"({
|
||||||
SPDLOG_ERROR("json parse error: [{}]", fields.back());
|
"messages": [{
|
||||||
boost::asio::post(ch->get_executor(), [=] {
|
"role": "user",
|
||||||
ch->try_send(err, std::format("json parse error: [{}]", fields.back()));
|
"content": "hello"
|
||||||
});
|
}],
|
||||||
continue;
|
"model": "gpt-3.5-turbo",
|
||||||
}
|
"temperature": 0.9,
|
||||||
auto str = line_json["choices"][0]["delta"]["content"].get<std::string>();
|
"presence_penalty": 0,
|
||||||
if (!str.empty() && str != "[DONE]")
|
"top_p": 1,
|
||||||
boost::asio::post(ch->get_executor(), [=] { ch->try_send(err, str); });
|
"frequency_penalty": 0,
|
||||||
}
|
"stream": true
|
||||||
return size * nmemb;
|
})";
|
||||||
},
|
nlohmann::json ask_request = nlohmann::json::parse(ask_json_str, nullptr, false);
|
||||||
.input = [&] -> void* {
|
ask_request["messages"] = getConversationJson(json);
|
||||||
input.recv.clear();
|
std::string ask_request_str = ask_request.dump();
|
||||||
input.ch = ch;
|
SPDLOG_INFO("request: [{}]", ask_request_str);
|
||||||
return &input;
|
return ask_request_str;
|
||||||
}(),
|
}())
|
||||||
.headers = [&] -> auto& {
|
.clearHeaders()
|
||||||
static std::unordered_map<std::string, std::string> headers{
|
.setHttpHeaders(headers)
|
||||||
{"Accept", "*/*"},
|
.perform();
|
||||||
{"origin", "https://chat.geekgpt.org"},
|
if (ret.has_value()) {
|
||||||
{"referer", "https://chat.geekgpt.org/"},
|
SPDLOG_ERROR("https://ai.fakeopen.com/v1/chat/completions: [{}]", ret.value());
|
||||||
{"Content-Type", "application/json"},
|
|
||||||
{"authority", "ai.fakeopen.com"},
|
|
||||||
{"authorization", "Bearer pk-this-is-a-real-free-pool-token-for-everyone"},
|
|
||||||
};
|
|
||||||
return headers;
|
|
||||||
}(),
|
|
||||||
.body = [&] -> std::string {
|
|
||||||
constexpr std::string_view ask_json_str = R"({
|
|
||||||
"messages": [{
|
|
||||||
"role": "user",
|
|
||||||
"content": "hello"
|
|
||||||
}],
|
|
||||||
"model": "gpt-3.5-turbo",
|
|
||||||
"temperature": 0.9,
|
|
||||||
"presence_penalty": 0,
|
|
||||||
"top_p": 1,
|
|
||||||
"frequency_penalty": 0,
|
|
||||||
"stream": true
|
|
||||||
})";
|
|
||||||
nlohmann::json ask_request = nlohmann::json::parse(ask_json_str, nullptr, false);
|
|
||||||
ask_request["messages"] = getConversationJson(json);
|
|
||||||
std::string ask_request_str = ask_request.dump();
|
|
||||||
SPDLOG_INFO("ask_request_str: [{}]", ask_request_str);
|
|
||||||
return ask_request_str;
|
|
||||||
}(),
|
|
||||||
.response_header_ptr = nullptr,
|
|
||||||
.expect_response_code = 200,
|
|
||||||
.ssl_verify = false,
|
|
||||||
});
|
|
||||||
if (ret) {
|
|
||||||
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, ret.value());
|
ch->try_send(err, ret.value());
|
||||||
co_return;
|
|
||||||
}
|
}
|
||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
@ -316,7 +316,7 @@ boost::asio::awaitable<void> doSession(boost::asio::ip::tcp::acceptor& acceptor,
|
|||||||
co_return;
|
co_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int, char** argv) {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
ScopeExit cleanup{[=] { curl_global_cleanup(); }};
|
ScopeExit cleanup{[=] { curl_global_cleanup(); }};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user