Formatting Script Variables
## Formatting Functions
When writing scripts, several formatting functions are available for handling different data types, including strings, numbers, and dates.
### String Formatting Functions
The following functions can be applied to strings to modify their casing or presentation:
1. **`lowercase`**: Converts all letters in the string to lowercase.
2. **`uppercase`**: Converts all letters in the string to uppercase.
3. **`capitalize`**: Capitalizes the first letter of the string, while the rest remain in same case.
4. **`spelling`**: Breaks the word into individual characters for easier pronunciation.
5. **`camel`**: Capitalizes the first letter of each word and lowercase's remaining characters in word
6. **`expand_address`**: Expands address abbreviations into full word for better agent pronunciation (st. -> street)
#### Example:{variable_name%capitalize}
The above example would format the value of `variable_name` by capitalizing its first letter.
### Number Formatting Functions
Numbers can also be formatted for specific uses to better suit the needs of the AI agent:
1. **`implied_hundreds`**: Multiplies the number by 100 if it is less than 100.
2. **`implied_thousands`**: Multiplies the number by 1000 if it is less than 1000.
3. **`spelling`**: Breaks the number into individual digits or characters.
#### Example:
If `number_variable` is `85` and the format function `{number_variable%implied_hundreds}` is used, the result will be `8500`.
### Date Formatting
Dates can also be formatted to meet different requirements. This uses the formatting syntax provided by the Moment.js library. Detailed information on formatting dates can be found [here](https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/01-format/).
### Formatting Syntax
To format a variable in a script, the syntax involves the variable name followed by a percentage sign (`%`) and the formatting function. Below is the general syntax:{variable_name%format_function}
#### Example:
If you have a variable representing a car make called `Taalk_vehicle_make`, you may format it as follows:{Taalk_vehicle_make%capitalize}
This would ensure that the car make, such as `"TOYOTA"`, is converted to `"Toyota"` for better readability and pronunciation.
## Formatting Use Cases
Formatting functions are crucial for ensuring that values are properly pronounced and displayed by the AI agent. For instance:
- If values are provided in all uppercase (e.g., `"BMW"`), it might affect the AI's pronunciation or natural reading pattern. Using the `capitalize` function can help correct this.
- Numbers that are implicitly small or used in calculations might need conversion using `implied_hundreds` or `implied_thousands` to provide better accuracy and context.
### Additional Notes
- Proper formatting ensures that the output provided by the AI agent is natural and intuitive.
- Incorrect or inconsistent formatting, such as values being in all uppercase or numbers being read ambiguously, can lead to awkward pronunciations or confusion.
- Applying appropriate formatting helps the AI to deliver responses that sound smooth and human-like.
## Summary of Available Formatting Functions
Data Type | Function Name | Description |
String
|
lowercase |
Converts all letters to lowercase |
String |
capitalize |
Capitalizes the first letter of the string
|
String |
spelling |
Breaks the word into individual characters
|
String |
camel |
Capitalizes the first letter of the word and lowercase remain
|
Number
|
implied_hundreds |
Multiplies the number by 100 if less than 100
|
Number
|
implied_thousands |
Multiplies the number by 1000 if less than 1000
|
Number
|
spelling |
Breaks the number into individual digits or characters
|
Date |
Moment.js Formatting |
Uses Moment.js to format date values as needed
|
String |
expand_address |
Expands address abbreviations into full word
|
Proper use of these formatting functions will enhance the clarity and quality of AI responses, ensuring a better user experience.