@novastera-oss/llamarn 0.1.1-alpha.1 → 0.1.1-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/CMakeLists.txt +4 -0
- package/cpp/rn-completion.cpp +4 -0
- package/cpp/rn-llama.hpp +5 -0
- package/cpp/rn-utils.hpp +11 -7
- package/package.json +1 -1
package/android/CMakeLists.txt
CHANGED
|
@@ -58,6 +58,10 @@ add_library(
|
|
|
58
58
|
${CPP_DIR}/rn-completion.cpp
|
|
59
59
|
)
|
|
60
60
|
|
|
61
|
+
# Suppress unused function warnings for llama.cpp code
|
|
62
|
+
target_compile_options(common PRIVATE -Wno-unused-function)
|
|
63
|
+
target_compile_options(RNLlamaCpp PRIVATE -Wno-unused-function)
|
|
64
|
+
|
|
61
65
|
# Include directories
|
|
62
66
|
target_include_directories(common PRIVATE
|
|
63
67
|
${CPP_DIR}
|
package/cpp/rn-completion.cpp
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#include "rn-llama.hpp"
|
|
2
|
+
// Suppress unused function warnings from llama.cpp headers
|
|
3
|
+
#pragma GCC diagnostic push
|
|
4
|
+
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
2
5
|
#include "common.h"
|
|
3
6
|
#include "chat.h"
|
|
4
7
|
#include "llama.h"
|
|
5
8
|
#include "sampling.h"
|
|
9
|
+
#pragma GCC diagnostic pop
|
|
6
10
|
#include "rn-utils.hpp"
|
|
7
11
|
|
|
8
12
|
#include <string>
|
package/cpp/rn-llama.hpp
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
// Suppress unused function warnings from llama.cpp headers
|
|
4
|
+
#pragma GCC diagnostic push
|
|
5
|
+
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
3
6
|
#include "common.h"
|
|
4
7
|
#include "llama.h"
|
|
5
8
|
#include "chat.h"
|
|
6
9
|
#include "chat-template.hpp"
|
|
7
10
|
#include "json-schema-to-grammar.h"
|
|
11
|
+
#pragma GCC diagnostic pop
|
|
12
|
+
|
|
8
13
|
#include "rn-utils.hpp"
|
|
9
14
|
|
|
10
15
|
#include <functional>
|
package/cpp/rn-utils.hpp
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
#pragma once
|
|
2
2
|
|
|
3
|
+
// Suppress unused function warnings from llama.cpp headers
|
|
4
|
+
#pragma GCC diagnostic push
|
|
5
|
+
#pragma GCC diagnostic ignored "-Wunused-function"
|
|
3
6
|
#include "common.h"
|
|
4
7
|
#include "llama.h"
|
|
5
8
|
#include "sampling.h"
|
|
9
|
+
#pragma GCC diagnostic pop
|
|
6
10
|
|
|
7
11
|
// Change JSON_ASSERT from assert() to GGML_ASSERT:
|
|
8
12
|
#define JSON_ASSERT GGML_ASSERT
|
|
@@ -187,7 +191,7 @@ static T json_value(const json & body, const std::string & key, const T & defaul
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
|
|
190
|
-
|
|
194
|
+
inline std::string gen_chatcmplid() {
|
|
191
195
|
static const std::string str("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
|
|
192
196
|
std::random_device rd;
|
|
193
197
|
std::mt19937 generator(rd());
|
|
@@ -198,11 +202,11 @@ static std::string gen_chatcmplid() {
|
|
|
198
202
|
return "chatcmpl-" + result;
|
|
199
203
|
}
|
|
200
204
|
|
|
201
|
-
|
|
205
|
+
inline bool ends_with(const std::string & str, const std::string & suffix) {
|
|
202
206
|
return str.size() >= suffix.size() && 0 == str.compare(str.size() - suffix.size(), suffix.size(), suffix);
|
|
203
207
|
}
|
|
204
208
|
|
|
205
|
-
|
|
209
|
+
inline size_t find_partial_stop_string(const std::string &stop, const std::string &text) {
|
|
206
210
|
if (!text.empty() && !stop.empty()) {
|
|
207
211
|
const char text_last_char = text.back();
|
|
208
212
|
for (int64_t char_index = stop.size() - 1; char_index >= 0; char_index--) {
|
|
@@ -218,7 +222,7 @@ static size_t find_partial_stop_string(const std::string &stop, const std::strin
|
|
|
218
222
|
return std::string::npos;
|
|
219
223
|
}
|
|
220
224
|
|
|
221
|
-
|
|
225
|
+
inline bool json_is_array_of_numbers(const json & data) {
|
|
222
226
|
if (data.is_array()) {
|
|
223
227
|
for (const auto & e : data) {
|
|
224
228
|
if (!e.is_number_integer()) {
|
|
@@ -231,7 +235,7 @@ static bool json_is_array_of_numbers(const json & data) {
|
|
|
231
235
|
}
|
|
232
236
|
|
|
233
237
|
// is array having BOTH numbers & strings?
|
|
234
|
-
|
|
238
|
+
inline bool json_is_array_of_mixed_numbers_strings(const json & data) {
|
|
235
239
|
bool seen_string = false;
|
|
236
240
|
bool seen_number = false;
|
|
237
241
|
if (data.is_array()) {
|
|
@@ -251,7 +255,7 @@ static bool json_is_array_of_mixed_numbers_strings(const json & data) {
|
|
|
251
255
|
* - only string, example: "string"
|
|
252
256
|
* - mixed string and tokens, example: [12, 34, "string", 56, 78]
|
|
253
257
|
*/
|
|
254
|
-
|
|
258
|
+
inline llama_tokens tokenize_mixed(const llama_vocab * vocab, const json & json_prompt, bool add_special, bool parse_special) {
|
|
255
259
|
// If `add_bos` is true, we only add BOS, when json_prompt is a string,
|
|
256
260
|
// or the first element of the json_prompt array is a string.
|
|
257
261
|
llama_tokens prompt_tokens;
|
|
@@ -299,7 +303,7 @@ static llama_tokens tokenize_mixed(const llama_vocab * vocab, const json & json_
|
|
|
299
303
|
* - "prompt": [[12, 34, 56], [78, 90, 12]]
|
|
300
304
|
* - "prompt": [[12, 34, "string", 56, 78], [12, 34, 56]]
|
|
301
305
|
*/
|
|
302
|
-
|
|
306
|
+
inline std::vector<llama_tokens> tokenize_input_prompts(const llama_vocab * vocab, const json & json_prompt, bool add_special, bool parse_special) {
|
|
303
307
|
std::vector<llama_tokens> result;
|
|
304
308
|
if (json_prompt.is_string() || json_is_array_of_mixed_numbers_strings(json_prompt)) {
|
|
305
309
|
// string or mixed
|