Example 1 - simple string[] input

function AnswerQuestions {
  // A list of questions
  input string[]
  output string
}

impl<llm, AnswerQuestions> v1 {
  client GPT4 // client must be defined somewhere
  prompt #"
    Answer the following questions:
    ---
    {#input}
    ---
    Answer:
  "#
}

Resulting prompt:

Answer the following questions:
---
['Question1', 'Question2', 'Question3']
---
Answer:

Example 2 - Dynamically modify how each item in the array is rendered.

We will now add indexes to each item in the array so the prompt contains

1. Question1
2. Question2
3. Question3

to do this we need to use a class to hold the list, and implement a dynamic property to render the messages.

class QuestionList {
  questions string[]
  // Add a new custom property that is dynamically computed using python
  display string @get(python#"
    return '\n'.join([f'{i+1}. {q}' for i, q in enumerate(self.questions)])
  "#)
}

function AnswerQuestions {
  // A list of questions
  input QuestionList
  output string
}

impl<llm, AnswerQuestions> v1 {
  client GPT4 // client must be defined somewhere
  prompt #"
    Answer the following questions:
    ---
    {#input.display}
    ---
    Answer:
  "#
  
}

Resulting prompt

Answer the following questions:
---
1. Question1
2. Question2
3. Question3
---
Answer:

Example 2 - User / assistant chat messages

Use a computed class property to render the messages using a python expression

class ChatMessage {
  user string
  message string
}

class ChatHistory {
  messages ChatMessage[]
  // Add a new custom property that is dynamically computed using python
  // NOTE: this does not change the message `role` in the prompt, it only prefixes each message with the word `User` or `Assistant`
  display string @get(python#"
    return '\n'.join([f'{m.user}: {m.message}' for m in self.messages])
  "#)
}

function Chat {
  // A list of questions
  input ChatHistory
  output string
}

impl<llm, Chat> v1 {
  client GPT4 // client must be defined somewhere
  prompt #"
    Chat with the assistant:
    ---
    {#input.display}
    ---
    Answer:
  "#
}

Resulting prompt

Chat with the assistant:
---
User1: Hello
Assistant: Hi
User1: Hi, can you help me?
---
Answer:

Read more about computed properties.