Generator
XMLNodeDescription
The XMLNodeDescription
class is designed to generate and manage descriptions for XML tags. It provides functionality to create customizable prompts for XML elements, including their attributes and usage examples.
Constructor
Creates a new XMLNodeDescription
instance.
Parameters:
desc: object
: An object containing the tag details:tag: string
: The XML tag name.description: string
: A description of the XML tag.selfClosing?: boolean
: Optional. Indicates if the tag is self-closing. Default isfalse
.attributes?: Record<string, string>
: Optional. A key-value pair of attribute names and their descriptions.
Methods
Getters
tag: string
Returns the XML tag name.
prompt: string
Returns the complete prompt, combining mainPrompt
, attributePrompt
, and examplePrompt
.
mainPrompt: string
Returns the main prompt describing the tag.
attributePrompt: string
Returns the prompt describing the tag's attributes.
examplePrompt: string
Returns the prompt providing usage examples of the tag.
Public Methods
setExamples(examples: XMLNodeDescriptionExample[]): void
Sets the examples for the XML tag and regenerates the example prompt.
Parameters:
examples: XMLNodeDescriptionExample[]
: An array of input-output examples.
setAttributes(attributes: Record<string, string>): void
Sets the attributes for the XML tag and regenerates the attribute prompt.
Parameters:
attributes: Record<string, string>
: A key-value pair of attribute names and their descriptions.
overloadMainPrompt(prompt: string): void
Overrides the main prompt with a custom string.
Parameters:
prompt: string
: The new main prompt.
overloadExamplePrompt(callback: ((example: XMLNodeDescriptionExample) => string) | null): void
Sets a custom callback for formatting example prompts and regenerates the example prompt.
Parameters:
callback: ((example: XMLNodeDescriptionExample) => string) | null
: A function that takes an example and returns a formatted string, or null to reset to default formatting.
overloadAttributePrompt(callback: ((key: string, value: string) => string) | null): void
Sets a custom callback for formatting attribute prompts and regenerates the attribute prompt.
Parameters:
callback: ((key: string, value: string) => string) | null
: A function that takes an attribute key and value and returns a formatted string, or null to reset to default formatting.
Usage Example
Last updated