githubEdit

Prompt Library (Prompt)

Linked with the "prompt" type.

A library for the prompt type, which is a tree of strings that is helpful when working with AI workflows.

Example Usage

#[main]
fn main() {
    const p = prompt("hello, world", "msg");
    assert_eq(p as str, "<msg>hello, world</msg>");
}

Prompt.any(prompt: prompt) -> bool

Does this prompt have any sub-prompts?

const p = prompt('hello', 'greet');
assert(!p.any());

Prompt.at(prompt: prompt, index: int) -> prompt

Get the sub-prompt at a given index (like a list). Will return null if the prompt does not have any sub-prompts.

const p = prompt('hello', 'greet', prompt('hello there'));
const sub = p[0];
assert_eq(sub, prompt('hello there'));

Prompt.clear(prompt: prompt) -> void

Clear all sub-prompts from this prompt.

Prompt.empty(prompt: prompt) -> bool

Returns true if the prompt does not have any sub-prompts.

Prompt.insert(prompt: prompt, index: int, other: prompt) -> void

Insert a sub-prompt into the given index.

Prompt.len(prompt: prompt) -> int

The number of sub-prompts contained within this prompt.

Prompt.pop(prompt: prompt) -> prompt

Pop a sub-prompt from the end of the sub-prompt list.

Prompt.prompts(prompt: prompt) -> list

Return this prompts list of sub-prompts.

Prompt.push(prompt: prompt, other: prompt | str) -> void

Push a sub-prompt to this prompt.

Prompt.remove(prompt: prompt, index: int) -> prompt

Remove a sub-prompt at the given index.

Prompt.replace(prompt: prompt, index: int, other: prompt) -> void

Replace a sub-prompt at the given index.

Prompt.reverse(prompt: prompt) -> void

Reverse all sub-prompts in this prompt.

Prompt.set_tag(prompt: prompt, tag: str) -> void

Set the tag portion of this prompt. Set to null to clear the tag.

Prompt.set_text(prompt: prompt, text: str) -> void

Set the text portion of this prompt.

Prompt.str(prompt: prompt) -> str

Convert this prompt into a string, just like a cast to 'str' would do.

Prompt.tag(prompt: prompt) -> str

Get the string tag for this prompt, or null if not present.

Prompt.text(prompt: prompt) -> str

Get the text portion of this prompt (ignoring any sub-prompts & tag).

Last updated