Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f2ed4ba

Browse filesBrowse files
committed
WIP
1 parent 3e78f00 commit f2ed4ba
Copy full SHA for f2ed4ba

File tree

Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+21
-1
lines changed

‎Makefile

Copy file name to clipboardExpand all lines: Makefile
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ common.o: examples/common.cpp examples/common.h
257257
grammar-parser.o: examples/grammar-parser.cpp examples/grammar-parser.h
258258
$(CXX) $(CXXFLAGS) -c $< -o $@
259259

260-
libllama.so: llama.o ggml.o $(OBJS)
260+
libllama.so: llama.o ggml.o grammar-parser.o $(OBJS)
261261
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
262262

263263
clean:

‎llama.cpp

Copy file name to clipboardExpand all lines: llama.cpp
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "llama-util.h"
1010
#include "llama.h"
11+
#include "grammar-parser.h"
1112

1213
#include "ggml.h"
1314
#ifdef GGML_USE_CUBLAS
@@ -1998,6 +1999,24 @@ void llama_grammar_free(struct llama_grammar * grammar) {
19981999
delete grammar;
19992000
}
20002001

2002+
struct llama_grammar * llama_parse_grammar(const char * grammar_str) {
2003+
grammar_parser::parse_state parsed_grammar;
2004+
llama_grammar * grammar = NULL;
2005+
if (grammar_str != NULL) {
2006+
parsed_grammar = grammar_parser::parse(grammar_str);
2007+
// will be empty (default) if there are parse errors
2008+
if (parsed_grammar.out_grammar.empty()) {
2009+
return NULL;
2010+
}
2011+
fprintf(stderr, "%s: grammar:\n", __func__);
2012+
grammar_parser::print_grammar(stderr, parsed_grammar);
2013+
fprintf(stderr, "\n");
2014+
grammar = llama_grammar_init(
2015+
parsed_grammar.out_grammar.data(), parsed_grammar.symbol_ids.at("root"));
2016+
}
2017+
return grammar;
2018+
}
2019+
20012020
//
20022021
// sampling
20032022
//

‎llama.h

Copy file name to clipboardExpand all lines: llama.h
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ extern "C" {
264264
//
265265
LLAMA_API struct llama_grammar * llama_grammar_init(const uint16_t * src, uint16_t start_rule_id);
266266
LLAMA_API void llama_grammar_free(struct llama_grammar * grammar);
267+
LLAMA_API struct llama_grammar * llama_parse_grammar(const char * grammar_str);
267268

268269
// Sampling functions
269270

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.