Overview

The model generates code from natural language prompt.

code_generation_model = CodeGenerationModel.from_pretrained("code-bison")
prefix = "write a python function to do binary search"
response = code_generation_model.predict(prefix=prefix)
 
print(response.text)

To better generate code with repeatability, it’s suggested to use templates

language = "Python"
file_format = "json"
extract_info = "names"
requirements = """
              - the name should be start with capital letters.
              - There should be no duplicate names in the final list.
              """
 
prefix = f"""Create a {language} to parse {file_format} and extract {extract_info} with the following requirements: {requirements}.
              """
 
response = code_generation_model.predict(prefix=prefix, max_output_tokens=1024)
 
print(response.text)