Classes consist of a name, a list of properties, and their types. In the context of LLMs, classes describe the type of the variables you can inject into prompts and extract out from the response. In python, classes are represented by pydantic models.

class Foo {
  property1 string
  property2 int?
  property3 Bar[]
  property4 MyEnum
}

Properties

Classes may have any number of properties. Property names must follow:

  • Must start with a letter
  • Must contain only letters, numbers, and underscores
  • Must be unique within the class

The type of a property can be any supported type

Default values

  • Not yet supported. For optional properties, the default value is None in python.

Computed properties

Somtimes, you may want a computed property. For example, you may want to return a full name from a first and last name property. You can do this by adding the @get attribute to a property.

Some use cases are:

  • Format a list of items into a string
  • Format a date into a string
  • Load data from a database
  • Read data from a file

As of now, computed properties are not async! This means you cannot use await in the code block. @async_get is planned for the future.

class Foo {
  first_name string
  last_name string

  full_name string @get(python#"
    return f'{self.first_name} {self.last_name}'
  "#, typescript#"
    return `${this.first_name} ${this.last_name}`
  "#)
}

You can also chain computed properties together.

class Foo {
  full_name_upper string @get(python#"
    return self.full_name.upper()
  "#, typescript#"
    return this.full_name.toUpperCase()
  "#)
}

Inheritance

Not supported. Like rust, we take the stance that composition is better than inheritance.

aliases, descriptions

Classes support aliases, descriptions, and other kinds of attributes. See the prompt engineering docs