forked from D7EAD/liboai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembeddings.cpp
44 lines (38 loc) · 1.41 KB
/
embeddings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "../include/components/embeddings.h"
liboai::Response liboai::Embeddings::create(const std::string& model_id, std::optional<std::string> input, std::optional<std::string> user) const & noexcept(false) {
liboai::JsonConstructor jcon;
jcon.push_back("model", model_id);
jcon.push_back("input", std::move(input));
jcon.push_back("user", std::move(user));
Response res;
res = this->Request(
Method::HTTP_POST, this->openai_root_, "/embeddings", "application/json",
this->auth_.GetAuthorizationHeaders(),
netimpl::components::Body {
jcon.dump()
},
this->auth_.GetProxies(),
this->auth_.GetProxyAuth(),
this->auth_.GetMaxTimeout()
);
return res;
}
liboai::FutureResponse liboai::Embeddings::create_async(const std::string& model_id, std::optional<std::string> input, std::optional<std::string> user) const & noexcept(false) {
liboai::JsonConstructor jcon;
jcon.push_back("model", model_id);
jcon.push_back("input", std::move(input));
jcon.push_back("user", std::move(user));
auto _fn = [this](liboai::JsonConstructor&& jcon) -> liboai::Response {
return this->Request(
Method::HTTP_POST, this->openai_root_, "/embeddings", "application/json",
this->auth_.GetAuthorizationHeaders(),
netimpl::components::Body {
jcon.dump()
},
this->auth_.GetProxies(),
this->auth_.GetProxyAuth(),
this->auth_.GetMaxTimeout()
);
};
return std::async(std::launch::async, _fn, std::move(jcon));
}