15#include "completion_processor.h"
17#if TARGET_OS_IOS || TARGET_OS_VISION
18 #include "ios_http_transport.h"
21 #define CPPHTTPLIB_FORM_URL_ENCODED_PAYLOAD_MAX_LENGTH 1048576
23 #define CPPHTTPLIB_TCP_NODELAY true
44 LLMClient(
const std::string &url,
const int port,
const std::string &API_key =
"",
const int max_retries = 5);
50 bool is_server_alive();
55 void set_SSL(
const char *SSL_cert);
60 bool is_remote()
const {
return !url.empty() && port > -1; }
86 std::string
completion_json(
const json &data, CharArrayFn callback =
nullptr,
bool callbackWithJSON =
true)
override;
98 std::string
slot_json(
const json &data)
override;
102 void cancel(
int id_slot)
override;
112#if TARGET_OS_IOS || TARGET_OS_VISION
115 httplib::Client *client =
nullptr;
116 httplib::SSLClient *sslClient =
nullptr;
118 bool use_ssl =
false;
121 std::string url =
"";
123 std::string API_key =
"";
124 std::string SSL_cert =
"";
126 std::vector<bool*> active_requests;
136 std::string post_request(
const std::string &path,
const json &payload, CharArrayFn callback =
nullptr,
bool callbackWithJSON =
true);
144 UNDREAMAI_API
bool LLMClient_Is_Server_Alive(
LLMClient *llm);
Core LLM functionality interface and base classes.
Client for accessing LLM functionality locally or remotely.
bool is_remote() const
Check if this is a remote client.
Abstract class for local LLM operations with slot management.
virtual std::string slot_json(const json &data)=0
Manage slots with HTTP response support.
virtual int get_next_available_slot()=0
Get an available processing slot.
virtual void cancel(int id_slot)=0
Cancel request.
Abstract class for LLM service providers.
virtual std::string embeddings_json(const json &data)=0
Generate embeddings with HTTP response support.
virtual std::string apply_template_json(const json &data)=0
Apply a chat template to message data.
virtual std::string tokenize_json(const json &data)=0
Tokenize input (override)
virtual std::string completion_json(const json &data, CharArrayFn callback, bool callbackWithJSON)=0
Generate text completion.
virtual std::string detokenize_json(const json &data)=0
Convert tokens back to text.
LLMClient * LLMClient_Construct(LLMProvider *llm)
Construct local LLMClient (C API)
void LLMClient_Set_SSL(LLMClient *llm, const char *SSL_cert)
Set SSL certificate (C API)
LLMClient * LLMClient_Construct_Remote(const char *url, const int port, const char *API_key="")
Construct remote LLMClient (C API)