Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save buanzo/756929d46a046c726b5f0fd62a0af3fd to your computer and use it in GitHub Desktop.
Save buanzo/756929d46a046c726b5f0fd62a0af3fd to your computer and use it in GitHub Desktop.
Kilu is a YAML-based template system that enables you to generate project files for any project that you indicate. The syntax of a Kilu template is as follows:
A basedir field specifies the base directory for the project. It should be a string value.
A files field contains a list of file entries. Each file entry should have a name and content field. The name field should be a string value that specifies the name of the file, and the content field should be a multiline string that defines the contents of the file.
@buanzo
Copy link
Author

buanzo commented Apr 13, 2023

The GIST above is an LLM prompt. If you feed it, for instance, to GPT4, you can then ask it to use Kilu to provide multi-file content. Like a project scaffolding, maybe a simple website. You can then easily create the files locally by using a script such as this:

kilu.py

import yaml
import os
import sys

if len(sys.argv) < 2:
      print("Usage: python kilu.py <template_file>")
      sys.exit(1)

      template_file = sys.argv[1]

      # Read the template from file
      with open(template_file, "r") as f:
          template = yaml.safe_load(f)

# Create the project directory if it doesn't exist
if not os.path.exists(template["basedir"]):
    os.mkdir(template["basedir"])
    print(f'Created {template["basedir"]}')

# Create the files and write the contents
for file in template["files"]:
    fn = os.path.join(template["basedir"], file["name"])
    with open(fn, "w") as f:
        f.write(file["content"])
        print(f'Created {fn}')

This is how a Kilu template looks like for a generic project:

basedir: ./project
files:
  - name: script1.py
    content: |
      print("Hello world!")
  - name: script2.py
    content: |
      print("OMG")
  - name: data.txt
    content: |
      Here comes the data
      1
      2
      3
      4
      5

In fact... here is kilu... In Kilu! Includes version.txt, kilu_prompt.txt and the kilu.py Kilu interpreter.

basedir: kilu

files:
  - name: kilu.py
    content: |
      import yaml
      import os
      import sys

      if len(sys.argv) < 2:
          print("Usage: python kilu.py <template_file>")
          sys.exit(1)

      template_file = sys.argv[1]

      # Read the template from file
      with open(template_file, "r") as f:
          template = yaml.safe_load(f)

      # Create the project directory if it doesn't exist
      if not os.path.exists(template["basedir"]):
          os.mkdir(template["basedir"])
          print(f'Created {template["basedir"]}')

      # Create the files and write the contents
      for file in template["files"]:
          fn = os.path.join(template["basedir"], file["name"])
          with open(fn, "w") as f:
              f.write(file["content"])
              print(f'Created {fn}')
              
  - name: kilu_prompt.txt
    content: |
      Kilu is a YAML-based template system that enables you to generate project files for any project that you indicate. The syntax of a Kilu template is as follows:

      A basedir field specifies the base directory for the project. It should be a string value.

      A files field contains a list of file entries. Each file entry should have a name and content field. The name field should be a string value that specifies the name of the file, and the content field should be a multiline string that defines the contents of the file.

  - name: version.txt
    content: |
      1.0

Of course, GPT and I built this together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment