@@ -223,6 +223,7 @@ Java_com_rnllama_LlamaContext_initContext(
223
223
jobject thiz,
224
224
jstring model_path_str,
225
225
jstring chat_template,
226
+ jstring reasoning_format,
226
227
jboolean embedding,
227
228
jint embd_normalize,
228
229
jint n_ctx,
@@ -259,6 +260,13 @@ Java_com_rnllama_LlamaContext_initContext(
259
260
const char *chat_template_chars = env->GetStringUTFChars (chat_template, nullptr );
260
261
defaultParams.chat_template = chat_template_chars;
261
262
263
+ const char *reasoning_format_chars = env->GetStringUTFChars (reasoning_format, nullptr );
264
+ if (reasoning_format_chars == " deepseek" ) {
265
+ defaultParams.reasoning_format = COMMON_REASONING_FORMAT_DEEPSEEK;
266
+ } else {
267
+ defaultParams.reasoning_format = COMMON_REASONING_FORMAT_NONE;
268
+ }
269
+
262
270
defaultParams.n_ctx = n_ctx;
263
271
defaultParams.n_batch = n_batch;
264
272
defaultParams.n_ubatch = n_ubatch;
@@ -326,6 +334,7 @@ Java_com_rnllama_LlamaContext_initContext(
326
334
327
335
env->ReleaseStringUTFChars (model_path_str, model_path_chars);
328
336
env->ReleaseStringUTFChars (chat_template, chat_template_chars);
337
+ env->ReleaseStringUTFChars (reasoning_format, reasoning_format_chars);
329
338
env->ReleaseStringUTFChars (cache_type_k, cache_type_k_chars);
330
339
env->ReleaseStringUTFChars (cache_type_v, cache_type_v_chars);
331
340
@@ -884,10 +893,16 @@ Java_com_rnllama_LlamaContext_doCompletion(
884
893
llama->is_predicting = false ;
885
894
886
895
auto toolCalls = createWritableArray (env);
896
+ std::string reasoningContent = " " ;
897
+ std::string *content = nullptr ;
887
898
auto toolCallsSize = 0 ;
888
899
if (!llama->is_interrupted ) {
889
900
try {
890
901
common_chat_msg message = common_chat_parse (llama->generated_text , static_cast <common_chat_format>(chat_format));
902
+ if (!message.reasoning_content .empty ()) {
903
+ reasoningContent = message.reasoning_content ;
904
+ }
905
+ content = &message.content ;
891
906
for (const auto &tc : message.tool_calls ) {
892
907
auto toolCall = createWriteableMap (env);
893
908
putString (env, toolCall, " type" , " function" );
@@ -908,6 +923,12 @@ Java_com_rnllama_LlamaContext_doCompletion(
908
923
909
924
auto result = createWriteableMap (env);
910
925
putString (env, result, " text" , llama->generated_text .c_str ());
926
+ if (content) {
927
+ putString (env, result, " content" , content->c_str ());
928
+ }
929
+ if (!reasoningContent.empty ()) {
930
+ putString (env, result, " reasoning_content" , reasoningContent.c_str ());
931
+ }
911
932
if (toolCallsSize > 0 ) {
912
933
putArray (env, result, " tool_calls" , toolCalls);
913
934
}
0 commit comments