File tree Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Expand file tree Collapse file tree 2 files changed +7
-5
lines changed Original file line number Diff line number Diff line change 49
49
50
50
_server_settings : Optional [ServerSettings ] = None
51
51
52
- DEFAULT_GRAMMAR_FILE = os .getenv ("DEFAULT_GRAMMAR_FILE" , "./json_grammar.gbnf" )
53
- with open (DEFAULT_GRAMMAR_FILE ) as f :
54
- default_grammar_text = f .read ()
52
+ DEFAULT_GRAMMAR_FILE = os .getenv ("GRAMMAR_FILE" , "" )
53
+ if DEFAULT_GRAMMAR_FILE != "" :
54
+ with open (DEFAULT_GRAMMAR_FILE ) as f :
55
+ default_grammar_text = f .read ()
55
56
56
57
def set_server_settings (server_settings : ServerSettings ):
57
58
global _server_settings
@@ -308,7 +309,8 @@ async def create_chat_completion(
308
309
if body .grammar is not None :
309
310
kwargs ["grammar" ] = llama_cpp .LlamaGrammar .from_string (body .grammar )
310
311
else :
311
- kwargs ["grammar" ] = llama_cpp .LlamaGrammar .from_string (default_grammar_text )
312
+ if DEFAULT_GRAMMAR_FILE :
313
+ kwargs ["grammar" ] = llama_cpp .LlamaGrammar .from_string (default_grammar_text )
312
314
iterator_or_completion : Union [
313
315
llama_cpp .ChatCompletion , Iterator [llama_cpp .ChatCompletionChunk ]
314
316
] = await run_in_threadpool (llama .create_chat_completion , ** kwargs )
You can’t perform that action at this time.
0 commit comments