meld
Version:
Meld: A template language for LLM prompts
128 lines (113 loc) • 3.24 kB
text/typescript
import {
createExample,
combineExamples,
SyntaxExampleGroup
} from './helpers';
/**
* Collection of simple integration examples
*
* These examples demonstrate basic combinations of different directive types
*/
export const atomic = {
textAndData: createExample(
'Text and data variables with interpolation',
` greeting = "Hello"
subject = "World"
user = { "name": "Alice", "id": 123 }
message = \`{{greeting}}, {{user.name}}! Your ID is {{user.id}}.\`
{{message}}`
),
textAndPathReferences: createExample(
'Text variables referencing path variables',
` docs = "$PROJECTPATH/docs"
config = "$./config"
docsText = "Docs are at $docs"
configText = "Config is at $config"
Documentation: {{docsText}}
Configuration: {{configText}}`
),
dataAndArrayAccess: createExample(
'Data array with access by index',
` fruits = ["apple", "banana", "cherry"]
index = 1
selection = \`Selected fruit: {{fruits[index]}}\`
{{selection}}`
)
};
/**
* Collection of more complex integration examples
*
* These examples demonstrate advanced combinations of different directive types
*/
export const combinations = {
defineAndRun: combineExamples(
'Define function and use it with run',
createExample(
'Define and run example',
` greet(name) = "echo 'Hello, {{name}}!'"
user = "Alice"
$greet({{user}})`
)
),
pathAndEmbed: combineExamples(
'Path variable with embed and section extraction',
createExample(
'Path and embed example',
` docs = "$PROJECTPATH/docs"
[$docs/README.md # Introduction]`
)
),
complexDataAccess: combineExamples(
'Complex data structures with nested access',
createExample(
'Complex data access',
` config = {
"app": {
"name": "Meld",
"version": "1.0.0",
"features": ["text", "data", "path"]
},
"env": "test"
}
users = [
{ name: "Alice", hobbies: ["reading", "hiking"] },
{ name: "Bob", hobbies: ["gaming", "cooking"] }
]
appInfo = \`{{config.app.name}} v{{config.app.version}}\`
features = \`Features: {{config.app.features}}\`
userHobby = \`{{users[0].name}}'s first hobby is {{users[0].hobbies[0]}}\`
Application: {{appInfo}}
{{features}}
{{userHobby}}`
)
),
defineDataAndRun: combineExamples(
'Define, data, and run integration',
createExample(
'Define command with parameters',
` greet(firstname, lastname) = "echo 'Hello, {{firstname}} {{lastname}}!'"`
),
createExample(
'Create data object',
` person = { firstname: "Bob", lastname: "Smith" }`
),
createExample(
'Run with data object properties',
` $greet({{person.firstname}}, {{person.lastname}})`
)
)
};
/**
* Empty invalid section - integration examples are typically not invalid themselves
* but may contain individual invalid components which would be covered in their
* respective directive type files
*/
export const invalid = {};
/**
* Complete collection of integration examples
*/
export const integrationExamples: SyntaxExampleGroup = {
atomic,
combinations,
invalid
};