File size: 488 Bytes
877de4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import torch

def generate_code(model, tokenizer, idea):
    input_text = f"""
    # Idea: {idea}

    # Code:
    """
    input_ids = tokenizer.encode(input_text, return_tensors="pt")
    output_sequences = model.generate(
        input_ids=input_ids,
        max_length=1024,
        num_return_sequences=1,
        no_repeat_ngram_size=2,
        early_stopping=True,
    )
    generated_code = tokenizer.decode(output_sequences[0], skip_special_tokens=True)

    return generated_code