Skip to content

Commit 5e59112

Browse files
committed
prevent other calls when uninitialized
1 parent 2d5d82e commit 5e59112

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

gpttype_adapter.cpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static llama_v2_context * llama_ctx_v2;
7373
static llama_v3_context * llama_ctx_v3;
7474
static llama_context * llama_ctx_v4;
7575

76-
static gpt_params * kcpp_params;
76+
static gpt_params * kcpp_params = nullptr;
7777
static int max_context_limit_at_load = 0;
7878
static int n_past = 0;
7979
static int n_threads = 4;
@@ -1399,18 +1399,27 @@ ModelLoadResult gpttype_load_model(const load_model_inputs inputs, FileFormat in
13991399

14001400
bool gpttype_generate_abort()
14011401
{
1402+
if(kcpp_params==nullptr)
1403+
{
1404+
printf("\nWarning: KCPP not initialized!\n");
1405+
}
14021406
stopper_unused_tokens = remaining_tokens;
14031407
remaining_tokens = 0;
14041408
return true;
14051409
}
14061410

14071411
std::vector<int> gpttype_get_token_arr(const std::string & input)
14081412
{
1413+
std::vector<int> toks;
1414+
if(kcpp_params==nullptr)
1415+
{
1416+
printf("\nWarning: KCPP not initialized!\n");
1417+
return toks;
1418+
}
14091419
if(debugmode==1)
14101420
{
14111421
printf("\nFileFormat: %d, Tokenizing: %s",file_format ,input.c_str());
14121422
}
1413-
std::vector<int> toks;
14141423
TokenizeString(input, toks, file_format);
14151424
int tokcount = toks.size();
14161425
if(debugmode==1)
@@ -1422,6 +1431,11 @@ std::vector<int> gpttype_get_token_arr(const std::string & input)
14221431

14231432
const std::string & gpttype_get_pending_output()
14241433
{
1434+
if(kcpp_params==nullptr)
1435+
{
1436+
printf("\nWarning: KCPP not initialized!\n");
1437+
return concat_output_reader_copy;
1438+
}
14251439
concat_output_mtx.lock();
14261440
concat_output_reader_copy = concat_output;
14271441
concat_output_mtx.unlock();
@@ -1430,6 +1444,14 @@ const std::string & gpttype_get_pending_output()
14301444

14311445
generation_outputs gpttype_generate(const generation_inputs inputs, generation_outputs &output)
14321446
{
1447+
if(kcpp_params==nullptr)
1448+
{
1449+
printf("\nWarning: KCPP not initialized!\n");
1450+
snprintf(output.text, sizeof(output.text), "%s", "");
1451+
output.status = 0;
1452+
generation_finished = true;
1453+
return output;
1454+
}
14331455
concat_output_mtx.lock();
14341456
concat_output = "";
14351457
concat_output_reader_copy = "";

0 commit comments

Comments
 (0)