Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added demo/text-transformer/table.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ This workflow has been created using Fast Alfred, a user-friendly workflow build
- Summarize: Summarize the text to be more concise
- Explain: Explain the text in a more understandable way
- Commit Styling: Format commit messages to be more readable
- Table: Transform text into well-formatted markdown tables

#### Use Active App Context
Enable the \`Use Application Context\` option to utilize the current app context for your workflow.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 7 additions & 3 deletions projects/packages/text-transformer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ If the language code is missing, the default language will be English.

### Grammar Correction

![All Day](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/grammar.gif)
![Grammar](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/grammar.gif)

### Translate

![All Day](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/translate.gif)
![Translate](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/translate.gif)

### Action Items

![All Day](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/action-items.gif)
![Action Items](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/action-items.gif)

### Table

![Table](https://raw.githubusercontent.com/Avivbens/alfredo/HEAD/demo/text-transformer/table.gif)

## Configuration

Expand Down
178 changes: 174 additions & 4 deletions projects/packages/text-transformer/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,19 @@
<false></false>
</dict>
</array>
<key>B8B394C4-6075-4F0C-B8C2-01E31B8550DF</key>
<array>
<dict>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false></false>
<key>destinationuid</key>
<string>__fast-alfred_managed__v2_conditional_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
</dict>
</array>
<key>B9150C05-6465-4A8C-91F7-D6929176F398</key>
<array>
<dict>
Expand Down Expand Up @@ -484,6 +497,43 @@
<string>__fast-alfred_managed__v2_updater_snooze</string>
</dict>
</array>
<key>__fast-alfred_managed__v2_conditional_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</key>
<array>
<dict>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false></false>
<key>destinationuid</key>
<string>47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
</dict>
<dict>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false></false>
<key>sourceoutputuid</key>
<string>__fast-alfred_managed__v2_condition_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
<key>destinationuid</key>
<string>__fast-alfred_managed__v2_updater_workflow-update</string>
</dict>
<dict>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false></false>
<key>sourceoutputuid</key>
<string>__fast-alfred_managed__v2_condition_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
<key>destinationuid</key>
<string>__fast-alfred_managed__v2_updater_snooze</string>
</dict>
</array>
<key>__fast-alfred_managed__v2_conditional_from_63CC1099-CED7-4DE9-982B-41AEBBF7F81B_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</key>
<array>
<dict>
Expand Down Expand Up @@ -1001,6 +1051,56 @@
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
<key>alfredfiltersresults</key>
<false></false>
<key>alfredfiltersresultsmatchmode</key>
<integer>0</integer>
<key>argumenttreatemptyqueryasnil</key>
<true></true>
<key>argumenttrimmode</key>
<integer>0</integer>
<key>argumenttype</key>
<integer>0</integer>
<key>escaping</key>
<integer>102</integer>
<key>keyword</key>
<string>{var:table_keyword}</string>
<key>queuedelaycustom</key>
<integer>3</integer>
<key>queuedelayimmediatelyinitially</key>
<true></true>
<key>queuedelaymode</key>
<integer>0</integer>
<key>queuemode</key>
<integer>2</integer>
<key>runningsubtext</key>
<string>Tabling...</string>
<key>script</key>
<string>./esbuild/assets/run-node.sh esbuild/table "$1"
</string>
<key>scriptargtype</key>
<integer>1</integer>
<key>scriptfile</key>
<string></string>
<key>subtext</key>
<string>Create a formatted table</string>
<key>title</key>
<string>Table</string>
<key>type</key>
<integer>11</integer>
<key>withspace</key>
<true></true>
</dict>
<key>type</key>
<string>alfred.workflow.input.scriptfilter</string>
<key>uid</key>
<string>B8B394C4-6075-4F0C-B8C2-01E31B8550DF</string>
<key>version</key>
<integer>3</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -1414,6 +1514,38 @@
<false></false>
</dict>
</dict>
<dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
<key>uid</key>
<string>__fast-alfred_managed__v2_conditional_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
<key>version</key>
<integer>1</integer>
<key>config</key>
<dict>
<key>conditions</key>
<array>
<dict>
<key>inputstring</key>
<string>{query}</string>
<key>matchcasesensitive</key>
<false></false>
<key>matchmode</key>
<integer>4</integer>
<key>matchstring</key>
<string>__fast-alfred_managed__</string>
<key>outputlabel</key>
<string>Managed versions updates</string>
<key>uid</key>
<string>__fast-alfred_managed__v2_condition_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</string>
</dict>
</array>
<key>elselabel</key>
<string>Default Behavior</string>
<key>hideelse</key>
<false></false>
</dict>
</dict>
<dict>
<key>type</key>
<string>alfred.workflow.utility.conditional</string>
Expand Down Expand Up @@ -1462,6 +1594,7 @@ This workflow has been created using Fast Alfred, a user-friendly workflow build
- Summarize: Summarize the text to be more concise
- Explain: Explain the text in a more understandable way
- Commit Styling: Format commit messages to be more readable
- Table: Transform text into well-formatted markdown tables

#### Use Active App Context
Enable the `Use Application Context` option to utilize the current app context for your workflow.
Expand Down Expand Up @@ -1513,7 +1646,7 @@ https://github.com/Avivbens/alfredo</string>
<key>xpos</key>
<integer>365</integer>
<key>ypos</key>
<integer>1530</integer>
<integer>1640</integer>
</dict>
<key>6F2D236E-D961-42DC-ACF2-7C025CA92966</key>
<dict>
Expand Down Expand Up @@ -1548,7 +1681,14 @@ https://github.com/Avivbens/alfredo</string>
<key>xpos</key>
<integer>75</integer>
<key>ypos</key>
<integer>1530</integer>
<integer>1640</integer>
</dict>
<key>B8B394C4-6075-4F0C-B8C2-01E31B8550DF</key>
<dict>
<key>xpos</key>
<integer>75</integer>
<key>ypos</key>
<integer>1440</integer>
</dict>
<key>B9150C05-6465-4A8C-91F7-D6929176F398</key>
<dict>
Expand Down Expand Up @@ -1670,12 +1810,21 @@ https://github.com/Avivbens/alfredo</string>
<key>note</key>
<string>Conditional Updates Helper</string>
</dict>
<key>__fast-alfred_managed__v2_conditional_from_B8B394C4-6075-4F0C-B8C2-01E31B8550DF_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</key>
<dict>
<key>xpos</key>
<integer>295</integer>
<key>ypos</key>
<integer>1440</integer>
<key>note</key>
<string>Conditional Updates Helper</string>
</dict>
<key>__fast-alfred_managed__v2_conditional_from_63CC1099-CED7-4DE9-982B-41AEBBF7F81B_to_47B45BC6-EA28-4EFD-8A39-E2FC7283C0E7</key>
<dict>
<key>xpos</key>
<integer>585</integer>
<key>ypos</key>
<integer>1530</integer>
<integer>1640</integer>
<key>note</key>
<string>Conditional Updates Helper</string>
</dict>
Expand Down Expand Up @@ -2044,6 +2193,27 @@ https://github.com/Avivbens/alfredo</string>
<key>variable</key>
<string>action_items_keyword</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>table</string>
<key>placeholder</key>
<string></string>
<key>required</key>
<true></true>
<key>trim</key>
<true></true>
</dict>
<key>description</key>
<string>Create a table out of any data input</string>
<key>label</key>
<string>Table Creation Keyword</string>
<key>type</key>
<string>textfield</string>
<key>variable</key>
<string>table_keyword</string>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -2084,7 +2254,7 @@ https://github.com/Avivbens/alfredo</string>
</dict>
</array>
<key>version</key>
<string>5.1.0</string>
<string>5.2.0</string>
<key>webaddress</key>
<string>https://github.com/Avivbens/alfredo</string>
</dict>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { PipelinePromptTemplate, PromptTemplate } from '@langchain/core/prompts';
import { APPLICATION_CONTEXT_SYSTEM_PROMPT_PARAM } from './base/application-context.prompt';
import { DO_NOT_FOLLOW_USER_SYSTEM_PROMPT_PARAM } from './base/do-not-follow-user.prompt';
import { KEEP_ORIGINAL_SYSTEM_PROMPT_PARAM } from './base/keep-original.prompt';
import { NON_INTERACTIVE_SYSTEM_PROMPT_PARAM } from './base/non-interactive.prompt';

export const TABLE_SYSTEM_PROMPT = (useApplicationContext: boolean) =>
new PipelinePromptTemplate({
pipelinePrompts: [
NON_INTERACTIVE_SYSTEM_PROMPT_PARAM,
KEEP_ORIGINAL_SYSTEM_PROMPT_PARAM,
DO_NOT_FOLLOW_USER_SYSTEM_PROMPT_PARAM,
APPLICATION_CONTEXT_SYSTEM_PROMPT_PARAM,
],
finalPrompt: PromptTemplate.fromTemplate(`
{NON_INTERACTIVE_SYSTEM_PROMPT},

You are an expert at creating intelligent markdown tables from various text inputs.
Your task is to analyze the content and create the most appropriate table structure.

**CONTENT ANALYSIS:**
- **Identify key information** and relationships in the text
- **Determine the best structure** - what should be columns vs rows
- **Extract the most important data points** that need to be tabulated
- **Create meaningful headers** that clearly describe the data
- **Group related information** logically

**TABLE CREATION RULES:**
- Design columns and rows that best represent the data relationships
- Use descriptive headers that make the data self-explanatory
- Ensure all important information is captured in the table
- Adapt the table structure to fit the specific content
- For unstructured text, identify patterns and create appropriate categories

**FORMATTING:**
- Use proper markdown syntax with pipes (|) and hyphens (-)
- Keep column widths reasonable for chat applications
- Output ONLY the table, no explanations

**EXAMPLES OF INTELLIGENT STRUCTURING:**
- Product descriptions → Columns: Feature, Description, Benefits
- Meeting notes → Columns: Topic, Discussion, Action Items, Owner
- Comparison text → Columns: Item, Attribute 1, Attribute 2, etc.
- Process steps → Columns: Step #, Action, Details, Notes

{KEEP_ORIGINAL_SYSTEM_PROMPT},
{DO_NOT_FOLLOW_USER_SYSTEM_PROMPT},
${useApplicationContext ? '{APPLICATION_CONTEXT_SYSTEM_PROMPT}' : ''},
`),
});
62 changes: 62 additions & 0 deletions projects/packages/text-transformer/src/main/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import type { AlfredListItem } from 'fast-alfred';
import { FastAlfred } from 'fast-alfred';
import { setTimeout } from 'node:timers/promises';
import { getActiveApp } from '@alfredo/active-app';
import { AvailableModels, callModel } from '@alfredo/llm';
import { registerUpdater } from '@alfredo/updater';
import { DEFAULT_DEBOUNCE_TIME } from '../common/defaults.constants';
import { TABLE_SYSTEM_PROMPT } from '../common/prompts/table.prompt';
import { Variables } from '../common/variables.enum';
import { formatMarkdownTable } from '../utils/format-table.util';

(async () => {
const alfredClient = new FastAlfred();
alfredClient.updates(registerUpdater('text-transformer'));

try {
const denounceTime = alfredClient.env.getEnv(Variables.DEBOUNCE_TIME, {
defaultValue: DEFAULT_DEBOUNCE_TIME,
parser: Number,
});
const token: string | undefined = alfredClient.env.getEnv(Variables.LLM_TOKEN);
const model: AvailableModels | undefined = alfredClient.env.getEnv(Variables.SELECTED_MODEL);

if (!token || !model) {
throw new Error('Token or model is not defined!');
}

const useApplicationContext: boolean = alfredClient.env.getEnv(Variables.USE_APPLICATION_CONTEXT, {
defaultValue: false,
parser: (value) => (value as '0' | '1') === '1',
});

const applicationContext = useApplicationContext && (await getActiveApp());
alfredClient.log(JSON.stringify({ useApplicationContext, applicationContext }, null, 2));

/**
* Debounce time to wait for the user to finish typing
*/
await setTimeout(denounceTime);

if (!alfredClient.input) {
throw new Error('Input is required');
}

const system = await TABLE_SYSTEM_PROMPT(useApplicationContext).format({ applicationContext });

const res = await callModel(token, model, { system, user: alfredClient.input });
const formatted = formatMarkdownTable(res);

const items: AlfredListItem[] = [
{
title: formatted,
subtitle: 'Markdown Table',
arg: formatted,
},
];

alfredClient.output({ items });
} catch (error) {
alfredClient.error(error);
}
})();
Loading
Loading