### Run Helper Function - Block Mode Examples Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/run+helper+function Demonstrates the block mode 'run' command with examples such as passing 'selection' or direct strings as input, and using titles for brainstorming templates. ```text-generator-template {{#run "default/summarize" "summary"}} {{selection}} {{/run}} ``` ```text-generator-template {{#run "default/summarize" "summary"}} text to be summarized {{/run}} ``` ```text-generator-template {{#run "local/brainstorm" "ideas" "idea"}} {{title}} {{/run}} ``` -------------------------------- ### Request Headers Example for Huggingface Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata Sends additional request metadata, often used for authentication. This example demonstrates setting the 'Authorization' header with a Bearer token for the Huggingface provider. ```json {"Authorization": "Bearer {{keys.hf}}"} ``` -------------------------------- ### Example Output Path Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata Defines the path to retrieve the result from the response when using the template. This path can be customized to extract specific data from the response, such as an image URL. ```markdown ![]({{requestResults.data.0.url}}) ``` -------------------------------- ### Run Helper Function - Inline Mode Examples Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/run+helper+function Illustrates various use cases of the inline 'run' command, including passing 'selection' as input, passing direct strings, and using titles as ideas for other templates. ```text-generator-template {{run "local/summarize" "summary" selection}} ``` ```text-generator-template {{run "local/summarize" "summary" "text to be summarized"}} ``` ```text-generator-template {{run "local/brainstorm" "ideas" title "idea"}} ``` ```text-generator-template brainstorm ideas about {{idea}} ``` -------------------------------- ### CopyAI Configuration Example Source: https://docs.text-gen.com/_notes/old/general/copyai Example of frontmatter configuration for the CopyAI tool. This snippet shows how to set the title and tags for a note related to CopyAI. ```yaml title: copyai tags: layout: note ``` -------------------------------- ### Text Generation with @vanakat/plugin-api Source: https://docs.text-gen.com/_notes/6-+Additional+resources/Use+Text+Generator+into+another+plugins This section details how to install and use the Text Generator plugin's API to generate text. It includes installation instructions, usage examples, and a complete code example. ```APIDOC ## Text Generation with `@vanakat/plugin-api` ### Description This API allows you to programmatically generate text using the Text Generator plugin. ### Method `gen(prompt)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Import and initialize the API const pluginApi = require('@vanakat/plugin-api'); const tg = pluginApi('tg'); // Generate text async function generateText(prompt) { return await tg.gen(prompt); } // Use the function to generate text generateText("Your prompt here").then(console.log).catch(console.error); ``` ### Response #### Success Response (200) - **text** (string) - The generated text based on the provided prompt. #### Response Example ```json { "generated_text": "This is the text generated by the AI." } ``` #### Error Response - **error** (string) - A message describing the error that occurred during text generation. ``` -------------------------------- ### Request Body Example for DALL-E-2 Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata Provides data for the API request, with the format varying by provider. This example shows the body for the DALL-E-2 provider, including parameters like 'n', 'size', and 'prompt'. ```json {"n": 1, "size": "1024x1024", "prompt": "{{escp prompt}}"} ``` -------------------------------- ### Example: Text Generation Workflow (JavaScript) Source: https://docs.text-gen.com/_notes/6-+Additional+resources/Use+Text+Generator+into+another+plugins A complete example demonstrating how to import, initialize the Text Generator API, generate text with a prompt, and log the result or any errors. This showcases a typical asynchronous usage pattern. ```javascript // Import and initialize the API const pluginApi = require('@vanakat/plugin-api'); const tg = pluginApi('tg'); // Generate text (async () => { try { const text = await tg.gen("Example prompt"); console.log(text); } catch (error) { console.error(error); } })(); ``` -------------------------------- ### Template Metadata Example Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata This snippet shows an example of the YAML front matter used for template metadata in Text Generator. It includes fields like title, tags, and layout. ```yaml title: Template Metadata tags: layout: note ``` -------------------------------- ### Frontmatter Configuration Example Source: https://docs.text-gen.com/_notes/old/general/Considered+Context This example shows how to configure frontmatter variables for the Text Generator Plugin. These variables can be included as context for text generation, provided they do not conflict with plugin-reserved YAML keywords. ```yaml --- title: Considered Context tags: doc layout: note --- ``` -------------------------------- ### Install @vanakat/plugin-api Source: https://docs.text-gen.com/_notes/6-+Additional+resources/Use+Text+Generator+into+another+plugins Installs the @vanakat/plugin-api package using npm. This package provides the necessary tools to interact with the Text Generator plugin. ```bash npm install @vanakat/plugin-api ``` -------------------------------- ### Interact with Other Plugins via PluginApi Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Javascript+Templates This example demonstrates how to interact with other installed Obsidian plugins, such as Text To Speech, using the `pluginApi` function within a Text Generator Javascript script. Ensure the target plugin is installed and script execution is enabled. ```html {{#script}} const tts = pluginApi('tts'); await tts.say("This is a test"); // Language is optional, use an ISO 639-1 code {{/script}} ``` -------------------------------- ### Frontmatter Configuration Example Source: https://docs.text-gen.com/_notes/old/general/Examples+of+frontmatter+configurations This snippet demonstrates a basic frontmatter configuration for a note within the Text Generator plugin. It includes essential metadata like title and tags, and specifies the layout. ```yaml title: Examples of frontmatter configurations tags: layout: note ``` -------------------------------- ### Display Notice Message to User Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `notice` helper displays a non-critical informational message to the user. This can be used to provide feedback or suggestions without interrupting the user's workflow. ```handlebars {{notice "Working on something..."}} ``` -------------------------------- ### Configure Custom Provider Headers for Hugging Face Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Example of custom headers for the Hugging Face provider, including authorization token. ```json headers: '{ "Authorization": "Bearer {{keys.hf}}" }' ``` -------------------------------- ### Template Metadata Fields Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata This section details the various fields available within the Template File Metadata for the Text Generator plugin, outlining their types, purposes, and providing examples. ```APIDOC ## Template Metadata ### Description The Template File Metadata is a crucial component of any template in Text Generator. It serves as the header information that provides essential details about the template itself. Properly documenting this metadata ensures clarity, usability, and consistency in your template management. This documentation will guide you through the various fields within the Template File Metadata and how to use them effectively. ### Fields in Template File Metadata | Field | Type | Purpose | Example | |-------------------|-----------------------|----------------------------------------------------------------------|--------------------------| | `promptId` | String | Unique identifier for each prompt. Must match the name of the template file. | | | `name` | String | Concise and descriptive name for the prompt. | | | `description` | String | Explains the purpose of the prompt. | | | `author` | String | Attributes the prompt to its creator. | | | `required_values` | Array of Strings | Lists values necessary for template function. | | | `tags` | Array of Strings | Relevant keywords for filtering prompts. | | | `version` | String (Semantic Ver.)| Indicates prompt version. | | | `commands` | Array of Strings | Specifies actions associated with the template. | `generate`, `insert&create` | | `mode` | String | Specifies the desired mode for completions. | `insert`, `replace` | | `system and messages` | Object | Configures system behavior and define messages. | | | `max_tokens` | Number | Maximum tokens considered in completion. | | | `temperature` | Number | Indicates randomness of model output. | | | `stream` | Boolean | Controls streaming mode operation. | `true`, `false` | | `provider` | String | Service/platform used for processing. | "openAIChat", "ollama" | | `model` | String | Name of the model for selected provider. | | | `disableProvider` | Boolean | Allows disabling of template execution (disabled by default). | `true`, `false` | | `endpoint` | String | Specific endpoint for template use. | | | `output` | String | Path to retrieve result from response. | `![]({{requestResults.data.0.url}})` | | `body` | String (Object) | Data for the API request. | `{"n": 1, "prompt": "{{escp prompt}}"}` | | `headers` | String (Object) | Sends additional request metadata. | `{"Authorization": "Bearer {{keys.hf}}"}` | | `chain.loader` | String | Loader function to initialize chain process. | `loadSummarizationChain` | | `chain.type` | "map_reduce" | "refine" | "staff" | Type of langchain chains to utilize. | | | `chain.verbose` | Boolean | Provides detailed logging for chain process. | | | `splitter.chunkSize` | Number | Size of each chunk for input data splitting. | | | `splitter.chunkOverlap` | Number | Overlapping elements between consecutive chunks. | | | `strict` | Boolean | Forces the user to fill all the Variables before running the template. | | | `viewTypes` | Array of Strings | Tells Obsidan what files are supported (markdown, excalidraw, canvas) | | ### `promptId` * **Type** : String * **Purpose** : The `promptId` field serves as a unique identifier for each prompt in your UI. It distinguishes one template from another, helping users quickly locate and select the desired prompt. It must be the same as the name of the template file. ### `name` * **Type** : String * **Purpose** : The `name` field provides a concise and descriptive name for the prompt. It should be short yet precise, enabling users to identify the prompt easily. ### `description` * **Type** : String * **Purpose** : The `description` field explains the purpose of the prompt and how users should utilize it. It is essential to keep this description simple, concise, and user-friendly. ### `author` * **Type** : String * **Purpose** : The `author` field attributes the prompt to its creator. It helps give credit to the person responsible for creating the template. ### `required_values` * **Type** : Array of Strings * **Purpose** : The `required_values` field lists the values that are necessary for the template to function correctly. It informs users of the specific data inputs or parameters they need to provide when using the template. ### `tags` * **Type** : Array of Strings * **Purpose** : The `tags` field includes relevant keywords or labels that describe the prompt. These tags are used for filtering prompts, making it easier for users to find templates that match their needs. ``` -------------------------------- ### Fetch Current Date and Time Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `date` helper retrieves the current date and time. This is useful for timestamping operations or any feature requiring current date information. ```handlebars {{date}} ``` -------------------------------- ### Handlebars Template Operation Helper Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `run` helper allows executing another template within the current context, promoting reusability and modular design for complex template structures. ```Handlebars {{run "templateName"}} ``` -------------------------------- ### Initialize Text Generator API (JavaScript) Source: https://docs.text-gen.com/_notes/6-+Additional+resources/Use+Text+Generator+into+another+plugins Initializes the Text Generator API by importing the plugin API and creating an instance for 'tg'. This setup is required before making any text generation calls. ```javascript const pluginApi = require('@vanakat/plugin-api'); const tg = pluginApi('tg'); ``` -------------------------------- ### Select Random File Based on Pattern and Length Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `getRandomFile` helper selects a random file that matches a given pattern in its path and falls within a specified content length range (minLength and maxLength). ```handlebars {{getRandomFile "input/" 100 1500}} ``` ```handlebars {{getRandomFile pattern minLength maxLength}} ``` -------------------------------- ### Iterating Through {{highlights}} Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{#each highlights}} helper iterates over text segments marked with double equal signs (==example==). It provides a way to selectively process highlighted content within a note. ```text-generator-template {{#each highlights}} * {{this}} {{/each}} ``` -------------------------------- ### Configure Custom Provider Body for DALL-E 2 Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Example of a custom request body for the DALL-E 2 provider, including parameters like number of images, size, and prompt. ```json body: "{\"n\": 1, \"size\": \"1024x1024\", \"prompt\": \"{{escp prompt}}\"}" ``` -------------------------------- ### Run Helper Function - Block Mode Additional Context Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/run+helper+function Shows how to pass additional context or variables within the block mode 'run' command, emphasizing the need for JSON-serializable data structures. ```text-generator-template {{#run "default/summarize" "summary"}} { "selection": "{{escp2 title}}", ... other config } {{/run}} ``` -------------------------------- ### Run Helper Function - Block Mode Syntax Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/run+helper+function Presents the syntax for the block mode 'run' command in Text Generator templates. This mode allows for passing content within the block as input to the executed template. ```text-generator-template {{#run "packageId/promptId" "output" "target"}} {{input}} {{/run}} ``` -------------------------------- ### Log Message to Console Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `log` helper outputs a message to the console. It is primarily used for debugging purposes or to inform the user about background processes within the template. ```handlebars {{log "Working on something..."}} ``` -------------------------------- ### Handlebars File Operation Helpers Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates Helpers for performing file operations within Handlebars templates. The `write` helper writes content to a specified file, and the `read` helper retrieves content from a file. ```Handlebars {{#write "readme.md"}} ... content of readme.md file in the document ... {{/write}} ``` ```Handlebars {{read "readme.md"}} ``` -------------------------------- ### Adding Starred Blocks for Context Source: https://docs.text-gen.com/_notes/old/general/Considered+Context This example demonstrates how to include specific sections of a long article as context by adding an asterisk to the heading. This requires enabling the option in the plugin's settings. ```markdown # Title* This is a title # Introduction write introduction ``` -------------------------------- ### Iterating Through Linked Mentions Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{#each mentions.linked}} helper iterates through notes that are directly linked to the current note within the vault. It facilitates working with explicitly connected notes. ```text-generator-template {{#each mentions.linked}} * {{this.results}} {{/each}} ``` -------------------------------- ### Set Completion Mode Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata Specifies the desired mode for completions when using the template. Available modes include 'insert', 'replace', and 'rename'. This field offers flexibility in how completions are integrated into content. ```yaml mode: insert ``` -------------------------------- ### Template File Metadata (PromptInfo) YAML Example Source: https://docs.text-gen.com/_notes/old/templates/Template+File+Metadata This YAML snippet shows the 'PromptInfo' section, which contains essential metadata for a prompt template. It includes fields for prompt identification, naming, description, author, required values, tags, version, and commands. ```yaml --- PromptInfo: promptId: getParagraph name: ✍️ Write paragraphs description: select a content contiens items, a paragraph for each item will be generated. required_values: title, outline author: Noureddine tags: writing version: 0.0.1 commands: - generate --- ``` -------------------------------- ### Run Helper Function - Inline Mode Syntax Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/run+helper+function Defines the syntax for the inline 'run' command in Text Generator templates. It allows executing a template and optionally storing its output and passing input. ```text-generator-template {{run "packageId/promptId" "output" "input" "target"}} ``` -------------------------------- ### Template File Metadata YAML Example Source: https://docs.text-gen.com/_notes/old/templates/Template+File+Metadata This YAML snippet demonstrates the structure for defining metadata for a template file. It includes fields like title, tags, and layout, which are common in static site generators or documentation systems. ```yaml title: Template File Metadata tags: layout: note ``` -------------------------------- ### Using {{clipboard}} Context Variable Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{clipboard}} context variable represents the current content that has been copied to the system clipboard. It enables templates to interact with and insert clipboard data. ```text-generator-template {{clipboard}} ``` -------------------------------- ### Iterating Through {{selections}} Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{#each selections}} helper iterates over all text segments selected by the user, particularly useful for multiple selections made with the Alt key. It allows systematic processing of each selected piece of text. ```text-generator-template {{#each selections}} * {{this}} {{/each}} ``` -------------------------------- ### Using {{content}} Context Variable Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{content}} context variable provides access to the entire text content of the current note. This is useful for operations that require the full note body. ```text-generator-template {{content}} ``` -------------------------------- ### Configure System and Messages for LLM Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Template+Metadata Configures the system's behavior and defines messages for interactions with the LLM. The 'system' field is a string describing the system's role, and 'messages' is an array of alternating user and assistant messages to define conversation flow. ```yaml system: messages: - - - - ``` -------------------------------- ### Using {{title}} Context Variable Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{title}} context variable represents the title of the current note. It can be used to dynamically reference or manipulate the note's title within templates. ```text-generator-template {{title}} ``` -------------------------------- ### Split Text using Langchain in Javascript Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Javascript+Templates This Javascript example utilizes Langchain's `RecursiveCharacterTextSplitter` to split text extracted from a YouTube video into manageable chunks. It requires the `extract` function and Langchain's splitter. Ensure script execution is enabled. ```html {{#script}} const youtubeScript = await extract("yt", "https://www.youtube.com/watch?v=tNAsLbGdM6A"); const splitter = new RecursiveCharacterTextSplitter({ chunkSize: 4000, chunkOverlap: 1, }); const output = await splitter.createDocuments([youtubeScript]); return output.join("***/n"); {{/script}} ``` -------------------------------- ### Select Next/Previous Word Relative to Cursor in Text Generation Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The `{{NextWord}}` and `{{PreviousWord}}` context variables select the next or previous word relative to the cursor's position, respectively. These facilitate word-by-word navigation and editing. ```handlebars {{NextWord}} {{PreviousWord}} ``` -------------------------------- ### Iterate YAML Metadata in Text Generation Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The `{{#each yaml}}` helper iterates through the top-level metadata (Object) of a note. It provides access to keys (`{{@key}}`) and values (`{{this}}`) of the metadata. For direct access to a specific variable, use `{{yaml.variable}}`. ```handlebars {{#each yaml}} {{@key}}: {{this}} {{/each}} {{yaml.variable}} ``` -------------------------------- ### Iterating Through Unlinked Mentions Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{#each mentions.unlinked}} helper iterates through notes that are referenced in the vault without a direct wiki-link (e.g., '...note...'). It helps manage and process unlinked references to the current note. ```text-generator-template {{#each mentions.unlinked}} * {{this.results}} {{/each}} ``` -------------------------------- ### Use substring function in templates Source: https://docs.text-gen.com/_notes/old/commands/substring The 'substring' function allows extraction of a portion of text. It takes the variable name, a start position, and an end position as arguments. For example, to get the first 100 characters of 'selection', use '{{{substring selection 0 99}}}'. ```text/template {{{substring var startPosition endPosition}}} ``` ```text/template {{{substring selection 0 99}}} ``` -------------------------------- ### Choose a model Configuration (YAML) Source: https://docs.text-gen.com/_notes/old/general/Choose+a+model This snippet demonstrates how to configure the 'Choose a model' setting using YAML frontmatter. It specifies the title, tags, and layout for the note. The model selection can be overridden by frontmatter settings and supports the latest ChatGPT models. The list of available OpenAI models can be updated in the plugin settings. ```yaml title: Choose a model tags: layout: note ``` -------------------------------- ### Frontmatter Configuration Source: https://docs.text-gen.com/_notes/old/general/Frontmatter+Configuration Explains how to configure the Text Generator Plugin using frontmatter, including options for appending parameters, context, and output handling. ```APIDOC ## Frontmatter Configuration ### Description Frontmatter configuration allows for flexible setup of the Text Generator Plugin, compatible with services like OpenAI and HuggingFace. It defines how requests are structured and processed. ### Method N/A (Configuration) ### Endpoint N/A (Configuration) ### Parameters #### Path Parameters N/A #### Query Parameters N/A #### Request Body N/A (Configuration is done via frontmatter) ### Request Example ```yaml title: Frontmatter Configuration tags: doc layout: note ``` ## YAML configuration Frontmatter configuration is very flexible and can work with many services such as OpenAI and HuggingFace. ## The structure of the frontmatter ```yaml --- config: append: bodyParams: Boolean reqParams: Boolean context: String output: String bodyParams: parameter: value reqParams: parameter: value --- ``` ### Configuration Options: * **config** * **append** * **bodyParams** : Append or not body form-data parameters to the default configuration (true/false). Default is `true`. * **reqParams** : Append or not request parameters to the default configuration (true/false). Default is `true`. * **context** * The variable that will include the considered content in `bodyParams`. Default is `"prompt"`. * **output** * Request results are in the variable `requestResults`. Requires Javascript code to extract results. * **bodyParams** * Includes body form-data parameters. Refer to the specific API documentation (e.g., OpenAI Documentation) for available variables. * Examples: * **n** : Number of generations * **max_tokens** : Maximum number of tokens per generation. * **reqParams** * **url** : Base URL for request construction. ### See Examples of frontmatter configurations. [Link to examples] ``` -------------------------------- ### Handlebars Variable Management Helpers Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates Helpers for managing variables within Handlebars templates. The `set` helper stores values in variables, accessible via the `vars` object, while the `get` helper retrieves these stored values. ```Handlebars {{set "var1" selection}} ``` ```Handlebars {{#set "var1"}} {{selection}} {{/set}} ``` ```Handlebars {{get "var1"}} or {{vars.var1}} ``` -------------------------------- ### Run Another Template using Run Helper Function Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Javascript+Templates This Javascript example shows how to execute another Text Generator template (e.g., 'default/summary') from within a script, passing data as context. It first extracts content using `extract` and then uses `run` to process it. Script execution must be enabled. ```html {{#script}} const youtubeScript = await extract("youtube", "https://www.youtube.com/watch?v=tNAsLbGdM6A"); const summary = await run("default/summary", {tg_selection: youtubeScript}); return summary; {{/script}} ``` -------------------------------- ### Configure System and Messages for Interactions Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Demonstrates setting up system prompts and message arrays for structured interactions with the language model, useful for tasks like translation or correction. ```yaml system: "You are an English translator, spelling corrector, and improver. Respond in corrected and improved English." messages: - "User: Hello, how are you?" - "Assistant: Hello! I am doing well, thank you for asking." - "User: I need help with this sentence." - "Assistant: Please provide the sentence, and I will do my best to assist you." ``` -------------------------------- ### Create New File From Template - Text Generator Source: https://docs.text-gen.com/_notes/2-+Options/Commands/Generate+and+Create+a+New+File+From+Template This command generates a new file by utilizing a specified template and processing a prompt. The output of the prompt is then used to populate the new document. ```markdown title: Generate and Create a New File From Template tags: layout: note ``` -------------------------------- ### Configure Model Parameters and Streaming Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Shows how to set parameters like maximum tokens and temperature for controlling the language model's output, and enable/disable streaming mode. ```yaml # Model parameters max_tokens: 150 temperature: 0.7 # Streaming mode stream: true ``` -------------------------------- ### Trim Whitespace from String Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `trim` helper removes leading and trailing whitespace from a string. This is useful for cleaning user input or preparing text for output. ```handlebars {{trim " hello world "}} ``` -------------------------------- ### Handlebars Information Extraction Helper Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `extract` helper is used to obtain information from various sources, enhancing the template's content processing and analysis capabilities. ```Handlebars {{extract "source"}} ``` -------------------------------- ### Basic Content Extraction with 'extract' (Text Generator) Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/extract+helper+function Demonstrates the basic usage of the 'extract' command to retrieve content from various sources. It supports different extractor types like 'web', 'youtube', 'pdf', 'image', and 'audio', taking the source as an argument. ```text-generator {{extract "extractorType" source}} ``` ```text-generator {{extract "web" weburl}} {{extract "web" "https://example.com"}} ``` ```text-generator {{extract "youtube" ytUrl}} {{extract "pdf" pdfPath}} {{extract "image" imgPath}} {{extract "audio" audioPath}} ``` -------------------------------- ### Filter Unique Elements from Array Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `unique` helper filters an array to return only unique elements, removing any duplicates. It takes an array as input and returns a new array with distinct values. ```handlebars {{unique ["apple", "banana", "apple", "orange", "banana"]}} ``` -------------------------------- ### Configure Provider and Endpoint Settings Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Details how to specify the AI provider, custom endpoints, and disable providers if necessary. ```yaml provider: "openAIChat" # endpoint: "https://api.example.com/v1" disableProvider: false ``` -------------------------------- ### Iterating Through {{children}} Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{#each children}} context variable iterates over notes or sub-notes that are cited or related to the current note. It allows access to and display of information from related notes. ```text-generator-template {{#each children}} # {{this.title}} {{this.content}} {{/each}} ``` -------------------------------- ### Excalidraw Plugin Parsing Source: https://docs.text-gen.com/assets/images/childrenNotes Demonstrates how the Excalidraw plugin parses text elements and templates. It shows the structure for referencing child notes and iterating through them. ```markdown excalidraw-plugin: parsed tags: [excalidraw] ⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ # Text Elements CH2 Template [[ [[ CH1 [[ [[ CH2 CH1 Note {{children[1]}} {{children[0]}} {{ each children}} {{this}} {{/each}} ``` -------------------------------- ### Display Error Message and Halt Execution Source: https://docs.text-gen.com/_notes/3-+Templates/subpages/Handlebar+Templates The `error` helper displays a critical error message to the user and halts the template's execution. It is used when essential conditions are not met and the template cannot proceed. ```handlebars {{error "Sorry, this template won't work without a note"}} ``` -------------------------------- ### Define Completion Modes in Configuration Source: https://docs.text-gen.com/_notes/old/templates/draft+metadata Illustrates how to configure the desired mode for text completions (insert, replace, rename) within the plugin's settings. ```yaml # Configuration for completion modes # Available modes: insert, replace, rename mode: insert ``` -------------------------------- ### Using {{selection}} Context Variable Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The {{selection}} context variable refers to the text currently selected by the user. It allows templates to operate on specific highlighted portions of a note. ```text-generator-template {{selection}} ``` -------------------------------- ### Manifest File Configuration for Template Packages Source: https://docs.text-gen.com/_notes/old/templates/Share+a+New+Template+Package Defines the structure and required fields for a manifest file used in Text Generator plugin template packages. This file includes metadata such as package ID, name, version, description, author, and repository information. ```json { "packageId": "default", // package id has to be unique from the other packages "name": "Default Prompts Package", // name of the package "version": "0.0.6", // version of the package if you're planning to update it later "minTextGeneratorVersion": "0.1.0", // minimum version of text generator that can work with it (use your current version) "description": "...", // description of the package "author": "...", // author name "tags" : "writing, brainstorming", // tags for the package "authorUrl": "...", // author page, or funding page "repo":"username/repo" // get it from the repo url } ``` -------------------------------- ### Select Current Paragraph at Cursor in Text Generation Source: https://docs.text-gen.com/_notes/3-+Templates/01+Understanding+Context The `{{cursorParagraph}}` context variable selects the entire paragraph where the cursor is currently located. This is helpful for operations focused on paragraph-level editing, formatting, or analysis. ```handlebars {{cursorParagraph}} ```