Skip to content

Commit

Permalink
Fixed grammar builder stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Dicklesworthstone committed Oct 3, 2023
1 parent 50199da commit dad7df5
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 78 deletions.
7 changes: 0 additions & 7 deletions embeddings_data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,6 @@ class ShowLogsIncrementalModel(BaseModel):
logs: str
last_position: int

class GrammarBuilderRequest(BaseModel):
sample_json: Optional[dict]
pydantic_model_description: Optional[str]

class GrammarBuilderResponse(BaseModel):
bnf_grammar: str

class AddGrammarRequest(BaseModel):
bnf_grammar: str
grammar_file_name: str
Expand Down
12 changes: 11 additions & 1 deletion grammar_builder.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from service_functions import validate_bnf_grammar_func
from typing import List, Dict
import json

Expand Down Expand Up @@ -196,10 +197,15 @@ def json_to_bnf(self, json_str):
}
}
'''

print('\n' + '_' * 80 + '\n')
bnf_grammar = gb.json_to_bnf(sample_json)
print(bnf_grammar)
print('\n' + '_' * 80 + '\n')
print("Validating grammar...")
is_valid, validation_message = validate_bnf_grammar_func(bnf_grammar)
print(validation_message)

print('\n\n\n')

gb = GrammarBuilder()
sample_pydantic_model_description = '''
Expand All @@ -220,4 +226,8 @@ class AudioTranscriptResponse(BaseModel):

bnf_grammar = gb.pydantic_to_json_bnf(sample_pydantic_model_description)
print(bnf_grammar)
print('\n' + '_' * 80 + '\n')
print("Validating grammar...")
is_valid, validation_message = validate_bnf_grammar_func(bnf_grammar)
print(validation_message)

2 changes: 1 addition & 1 deletion service_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ async def generate_completion_from_llm(request: TextCompletionRequest, req: Requ
list_of_responses.append(response)
return list_of_responses

def validate_bnf_grammar_revised(grammar):
def validate_bnf_grammar_func(grammar):
defined_rules, used_rules = set(), set()
for line in grammar.strip().split('\n'):
if '::=' not in line:
Expand Down
Loading

0 comments on commit dad7df5

Please sign in to comment.