Skip to content

Commit

Permalink
2.13.8: feat: implement a tags suggestion command
Browse files Browse the repository at this point in the history
  • Loading branch information
louis030195 committed Jan 18, 2023
1 parent 3b7d696 commit b3074cc
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "ava",
"name": "🧙 AVA",
"version": "2.13.7",
"version": "2.13.8",
"minAppVersion": "0.12.0",
"description": "AI assistant for Obsidian",
"author": "louis030195",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ava",
"version": "2.13.7",
"version": "2.13.8",
"description": "AI assistant for Obsidian",
"main": "main.js",
"scripts": {
Expand Down
49 changes: 49 additions & 0 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
rewrite,
REWRITE_CHAR_LIMIT as TEXT_CREATE_CHAR_LIMIT,
search,
suggestTags,
} from './utils';

import posthog from 'posthog-js';
Expand Down Expand Up @@ -725,6 +726,54 @@ export default class AvaPlugin extends Plugin {
},
});

this.addCommand({
id: 'ava-tags',
name: 'Suggest tags',
editorCallback: async (editor: Editor) => {
posthog.capture('use-feature', { feature: 'suggest tags' });
if (!this.settings.token) {
new Notice('🧙 AVA Tags - You need to login to use this feature');
return;
}
const text = editor.getValue();
if (!text) {
new Notice('🧙 AVA Tags - Open a note first');
return;
}

if (text.length > TEXT_CREATE_CHAR_LIMIT) {
new Notice(
'🧙 AVA Tags - Currently only supports files less than 5800 characters ~1200 words'
);
return;
}

new Notice(
'🧙 AVA - Generating tags, this may take a few seconds'
);
this.displayWriteSidebar();

this.statusBarItem.render(<StatusBar status="loading" />);
const file = this.app.workspace.getActiveFile();
const source = await suggestTags(
text,
this.settings.token,
this.manifest.version,
);
store.getState().reset();
store.getState().appendContentToRewrite(`#### Tags\n\n#`);
source.addEventListener('message', function (e: any) {
const payload = JSON.parse(e.data);
store.getState().setEditorContext(editor);
const t = payload.choices[0].text;
store.getState().appendContentToRewrite(t);
});
source.addEventListener('error', onSSEError);
source.stream();
this.statusBarItem.render(<StatusBar status="success" />);
},
});

this.registerView(
VIEW_TYPE_WRITE,
(leaf: WorkspaceLeaf) => new WriteView(leaf, this)
Expand Down
8 changes: 8 additions & 0 deletions src/tutorial.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ Imagine you wanting to relate your current note to another, but can't remember w
3. Type "link"
4. Select "🧙 AVA - Generate Link"
### Get tags suggestions
Want to classify your notes, but can't find the right tags?
1. Press cmd+p
2. Type "ava tag"
3. Select "🧙 AVA - Suggest tags"
### Generate stunning visualizations
Illustrate your thoughts, ideas, or just create art.
Expand Down
24 changes: 24 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,30 @@ export const clearIndex = async (
return json;
};

/**
* v1: Simply generate tags using text completion based on the current note
* TODO v2: pick 3 random notes and use as examples in the prompt
* TODO v3: use /search to find similar notes and return a set of tags
* TODO v4: use /search to find similar notes and get a set of tags and expand with text completion
* @param token
* @param version
* @param noteContent
*/
export const suggestTags = async (
noteContent: string,
token: string,
version: string,
): Promise<any> => {
const prompt = `Suggest a short list of tags in lower case for the note content (for example "#to-process #dogs", depending on the topic of the note):\n\n${noteContent}\n\nTags:#`;
return await complete(prompt, token, version, {
maxTokens: 100,
temperature: 0.5,
topP: 0.5,
stop: ['\n'],
stream: true,
});
};

/**
* Get all Markdown files in the vault with their content and tags
* @param {App} app
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@
"2.13.4": "0.12.0",
"2.13.5": "0.12.0",
"2.13.6": "0.12.0",
"2.13.7": "0.12.0"
"2.13.7": "0.12.0",
"2.13.8": "0.12.0"
}

0 comments on commit b3074cc

Please sign in to comment.