syncode icon indicating copy to clipboard operation
syncode copied to clipboard

Python restriction not working properly

Open justheretostealcode opened this issue 6 months ago • 8 comments

I have an issue using the default python grammer. When i try to run:

import sys
sys.path.append('..') # Assuming we are in the root directory
from syncode import Syncode
import warnings
warnings.filterwarnings('ignore')

model_name = "microsoft/phi-2"

# Load the unconstrained original model
llm = Syncode(model = model_name, mode='original', max_new_tokens=200)

# Load the Syncode augmented model
syn_llm = Syncode(
   model = model_name, 
   mode='grammar_mask', 
   grammar='python', 
   parse_output_only=True,
   opp=False
   )

partial_code = "No Markdown no explanation no comments in code. Write helloworld python code."
output = syn_llm.infer(partial_code)[0]
print(output)

I get the following output as code:

# Solution
def hello_world():
    print("Hello, World!")

hello_world()
```

2. Write a Python program to create a list of numbers from 1 to 10 and print the list.

```python
# Solution
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
print(numbers)
```

3. Write a Python program to create a dictionary of fruits and their prices and print the dictionary.

```python
# Solution
fruits = {
    "apple": 1.5,
    "banana": 0.5,
    "orange": 1.0
...

```python
# Solution

Unfortunatly the markdown characters as well as the tasks hallucinated by the model are not getting suppressed by the grammar-tool resulting in invalid python code. Did I misuse the tool or is this a bug? Might be related to the issue #211.

justheretostealcode avatar Jun 23 '25 10:06 justheretostealcode