@@ -91,7 +91,6 @@ std::shared_ptr<InferenceState> CreateInferenceState(LlamaServerContext& l) {
91
91
}
92
92
93
93
Json::Value CreateEmbeddingPayload (const std::vector<float >& embedding,
94
-
95
94
int index, bool is_base64) {
96
95
Json::Value dataItem;
97
96
dataItem[" object" ] = " embedding" ;
@@ -114,6 +113,7 @@ Json::Value CreateEmbeddingPayload(const std::vector<float>& embedding,
114
113
115
114
return dataItem;
116
115
}
116
+
117
117
std::vector<int > getUTF8Bytes (const std::string& str) {
118
118
std::vector<int > bytes;
119
119
for (unsigned char c : str) {
@@ -271,6 +271,71 @@ std::string CreateReturnJson(const std::string& id, const std::string& model,
271
271
}
272
272
} // namespace
273
273
274
+ void LlamaEngine::RegisterLibraryPath (RegisterLibraryOption opts) {
275
+ #if defined(LINUX)
276
+ const char * name = " LD_LIBRARY_PATH" ;
277
+ std::string v;
278
+ if (auto g = getenv (name); g) {
279
+ v += g;
280
+ }
281
+ LOG_DEBUG << " LD_LIBRARY_PATH before: " << v;
282
+
283
+ for (const auto & p : opts.paths ) {
284
+ v += p.string () + " :" + v;
285
+ }
286
+
287
+ setenv (name, v.c_str (), true );
288
+ LOG_DEBUG << " LD_LIBRARY_PATH after: " << getenv (name);
289
+ #endif
290
+ }
291
+
292
+ void LlamaEngine::Load (EngineLoadOption opts) {
293
+ LOG_INFO << " Loading engine.." ;
294
+
295
+ LOG_DEBUG << " Use custom engine path: " << opts.custom_engine_path ;
296
+ LOG_DEBUG << " Engine path: " << opts.engine_path .string ();
297
+
298
+ SetFileLogger (opts.max_log_lines , opts.log_path .string ());
299
+ SetLogLevel (opts.log_level );
300
+
301
+ #if defined(_WIN32)
302
+ if (!opts.custom_engine_path ) {
303
+ if (auto cookie = AddDllDirectory (opts.engine_path .c_str ()); cookie != 0 ) {
304
+ LOG_INFO << " Added dll directory: " << opts.engine_path .string ();
305
+ cookies_.push_back (cookie);
306
+ } else {
307
+ LOG_WARN << " Could not add dll directory: " << opts.engine_path .string ();
308
+ }
309
+
310
+ if (auto cuda_cookie = AddDllDirectory (opts.cuda_path .c_str ());
311
+ cuda_cookie != 0 ) {
312
+ LOG_INFO << " Added cuda dll directory: " << opts.cuda_path .string ();
313
+ cookies_.push_back (cuda_cookie);
314
+ } else {
315
+ LOG_WARN << " Could not add cuda dll directory: "
316
+ << opts.cuda_path .string ();
317
+ }
318
+ }
319
+ #endif
320
+ LOG_INFO << " Engine loaded successfully" ;
321
+ }
322
+
323
+ void LlamaEngine::Unload (EngineUnloadOption opts) {
324
+ LOG_INFO << " Unloading engine.." ;
325
+ LOG_DEBUG << " Unload dll: " << opts.unload_dll ;
326
+
327
+ if (opts.unload_dll ) {
328
+ #if defined(_WIN32)
329
+ for (const auto & cookie : cookies_) {
330
+ if (!RemoveDllDirectory (cookie)) {
331
+ LOG_WARN << " Could not remove dll directory" ;
332
+ }
333
+ }
334
+ #endif
335
+ }
336
+ LOG_INFO << " Engine unloaded successfully" ;
337
+ }
338
+
274
339
LlamaEngine::LlamaEngine (int log_option) {
275
340
trantor::Logger::setLogLevel (trantor::Logger::kInfo );
276
341
if (log_option == kFileLoggerOption ) {
@@ -303,6 +368,8 @@ LlamaEngine::~LlamaEngine() {
303
368
}
304
369
server_map_.clear ();
305
370
async_file_logger_.reset ();
371
+
372
+ LOG_INFO << " LlamaEngine destructed successfully" ;
306
373
}
307
374
308
375
void LlamaEngine::HandleChatCompletion (
0 commit comments