Skip to content

Commit

Permalink
Merge branch 'main' into renovate/anthropic-ai-sdk-0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
ckt1031 authored Oct 5, 2024
2 parents 3995008 + b273025 commit 4cdc015
Show file tree
Hide file tree
Showing 26 changed files with 137 additions and 70 deletions.
6 changes: 1 addition & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# vscode
.vscode

# Intellij
*.iml
.idea
.vscode

# npm
node_modules
Expand Down
5 changes: 5 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/jsLibraryMappings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/material_theme_project_new.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions .idea/obsidian-wordwise-plugin.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Welcome to **Obsidian WordWise**, a community project adding AI features into Obsidian to simplify your workflow. This plugin integrates prompts, tools and commands powered by AI to boost productivity and enhance user experience.

Guidelines to create and use file-based prompts in WordWise: [Docs](docs/file-prompts.md).

## Supported Providers

- [OpenAI](https://openai.com/) - Advanced and powerful.
Expand Down
24 changes: 24 additions & 0 deletions docs/file-prompts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Setting Up File-Based Prompts in WordWise

This document explains how to create and use file-based prompts in WordWise.

1. **Create a Directory:** Choose a location on your system for storing your prompts. For example, `WordWise/Prompts`. Remember this path, as you'll need it later. The path is case-sensitive.
2. **Enable File-Based Prompts:** In WordWise, enable the "File based custom prompts" option. Enter the path you chose in step one (e.g., `WordWise/Prompts`) into the "File Path" field. ![](https://i.imgur.com/mevNOYg.png)
3. **Create a Markdown File:** Create a new markdown file within your chosen prompts directory.
4. **Add Prompt Properties:** Inside the new markdown file, add the following properties enclosed within triple dashes (`---`) at the beginning of the file:

```yaml
---
name: YourPromptName # Required: The name/identifier of your prompt.
disabled: false # Optional: Set to true to temporarily disable this prompt.
provider: ProviderName # Optional: Specify a provider for this prompt.
model: ModelID # Optional: Specify a model ID for this prompt.
systemPrompt: Your system prompt here # Optional: Override the default system prompt.
---
```

- `name`: This is required and serves as the identifier for your prompt.
- `disabled`: (Optional) Use this to temporarily disable the prompt. This corresponds to a checkbox in reading mode.
- `provider`: (Optional) Allows you to specify a particular provider for this prompt.
- `model`: (Optional) Allows you to specify a specific model ID for this prompt.
- `systemPrompt`: (Optional) Use this to override any pre-defined system prompts and tailor them to your specific needs. Place your desired system prompt text after the colon.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"isDesktopOnly": false,
"minAppVersion": "1.0.0",
"name": "WordWise",
"version": "0.7.5"
"version": "1.0.0"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-wordwise-plugin",
"version": "0.7.5",
"version": "1.0.0",
"private": true,
"description": "Writing companion for AI content generation.",
"license": "MIT",
Expand Down
8 changes: 1 addition & 7 deletions src/components/fetch-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,12 @@ export const wrapFetchModelComponent = ({ dropDown, plugin }: Props) => {
models = await getCohereModels({ plugin });
break;
}
case APIProvider.Custom:
case APIProvider.OpenRouter:
case APIProvider.OpenAI: {
models = await getOpenAIModels({ plugin });
break;
}
case APIProvider.GoogleGemini: {
models = await getGoogleGenAIModels({ plugin });
break;
}
default:
throw new Error(`Unknown API Provider: ${settings.aiProvider}`);
models = await getOpenAIModels({ plugin });
}

await setModels(settings.aiProvider, models);
Expand Down
2 changes: 1 addition & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const DEFAULT_SETTINGS: PluginSettings = {
customBehavior: CustomBehavior.Replace,
};

export const settingTabProviderConfiguations = {
export const settingTabProviderConfigurations = {
[APIProvider.OpenAI]: {
defaultHost: DEFAULT_HOST[APIProvider.OpenAI],
docs: 'https://platform.openai.com/docs/introduction',
Expand Down
22 changes: 1 addition & 21 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,4 @@
import type { Plugin, SettingTab } from 'obsidian';

interface PluginManifest {
author?: string;
authorUrl?: string;
description?: string;
dir?: string;
id?: string;
isDesktopOnly?: boolean;
minAppVersion?: string;
name?: string;
version?: string;
}

interface SettingTabI extends SettingTab {
containerEl: HTMLElement;
id: string;
name: string;
navEl: HTMLElement;
plugin?: Plugin;
}
import type {} from 'obsidian';

declare module 'obsidian' {
interface App {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default class WordWisePlugin extends Plugin {
new Notice(parsed.message);
} else if (parsed.result) {
this.settings = mergeDeepRight(this.settings, parsed.result);
this.saveSettings();
await this.saveSettings();
new Notice(
'Settings imported. Please check the settings tab to verify.',
);
Expand Down
2 changes: 1 addition & 1 deletion src/menus/optionsMenu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Very slightly adapted from code by Chetachi Ezikeuzor
// Original source available at https://github.com/chetachiezikeuzor/Highlightr-Plugin/blob/master/src/ui/highlighterMenu.ts

import type { Coords, EnhancedEditor, EnhancedMenu } from '@/types';
import { Menu, Notice } from 'obsidian';
import type { Coords, EnhancedEditor, EnhancedMenu } from '../types';

const optionsMenu = (editor: EnhancedEditor, options: string[]): void => {
if (editor?.hasFocus()) {
Expand Down
4 changes: 2 additions & 2 deletions src/modals/generation-logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class TextGenerationLogModal extends Modal {
private enabled: boolean;
private logs: TextGenerationLog[];

private textLogDiv: HTMLDivElement;
private readonly textLogDiv: HTMLDivElement;

// Action sync function or async function
constructor(plugin: WordWisePlugin) {
Expand Down Expand Up @@ -72,7 +72,7 @@ export default class TextGenerationLogModal extends Modal {
// Add delete button
const deleteButton = contentEl.createEl('button', {
text: 'Delete Log',
cls: 'log-delet-button',
cls: 'log-delete-button',
});

deleteButton.onclick = async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/modals/qr-code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default class ExportSettingsQrCodeModal extends Modal {
'button',
{
text: 'Copy Data String',
cls: 'log-delet-button',
cls: 'log-delete-button',
},
(el) => {
el.onclick = async () => {
Expand Down
4 changes: 1 addition & 3 deletions src/prompts-file-based.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ export async function getFolderBasedPrompt(
if (!exists) return undefined;

const fileContent = await plugin.app.vault.adapter.read(path);
const parsed = readFile(fileContent, true);

return parsed;
return readFile(fileContent, true);
}

export async function getAllFolderBasedPrompt(plugin: WordWisePlugin) {
Expand Down
30 changes: 15 additions & 15 deletions src/settings-tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { wrapAPITestComponent } from './components/test-api';
import {
APIProvider,
CustomBehavior,
settingTabProviderConfiguations,
settingTabProviderConfigurations,
} from './config';
import type WordWisePlugin from './main';
import AddCustomPromptModal from './modals/add-custom-prompt';
Expand Down Expand Up @@ -50,12 +50,12 @@ export class SettingTab extends PluginSettingTab {
dropDown.onChange(async (value) => {
settings.aiProvider = value as APIProvider;
await plugin.saveSettings();
this.restartSettingsTab(plugin);
await this.restartSettingsTab(plugin);
});
});

for (const [provider, config] of Object.entries(
settingTabProviderConfiguations,
settingTabProviderConfigurations,
)) {
if (settings.aiProvider === provider) {
new Setting(containerEl)
Expand Down Expand Up @@ -178,9 +178,9 @@ export class SettingTab extends PluginSettingTab {
new Setting(containerEl).setName('Advanced Model Parameters').setHeading();

new Setting(containerEl)
.setName('Disable native commands')
.setName('Disable pre-defined commands')
.setDesc(
'Disable the native commands provided by the plugin, this will only work if you have a custom prompt setup',
'Disable the pre-defined commands provided by the plugin, this will only work if you have a custom prompt setup',
)
.addToggle((toggle) =>
toggle
Expand All @@ -200,7 +200,7 @@ export class SettingTab extends PluginSettingTab {
toggle.setValue(settings.advancedSettings).onChange(async (value) => {
settings.advancedSettings = value;
await plugin.saveSettings();
this.restartSettingsTab(plugin);
await this.restartSettingsTab(plugin);
}),
);

Expand Down Expand Up @@ -381,7 +381,7 @@ export class SettingTab extends PluginSettingTab {
for (let i = 0; i < 5; i++) {
button.setButtonText(`Are you sure to delete? (${5 - i})`);
button.setDisabled(true);
sleep(1000);
await sleep(1000);
}

button.setDisabled(false);
Expand All @@ -406,25 +406,25 @@ export class SettingTab extends PluginSettingTab {
new Setting(containerEl)
.setName('File based custom prompts (Experimental)')
.setDesc(
'Enable file based custom prompts, this will use the prompts from the file specified below',
'Enable file based custom prompts, this will load file prompts from the folder path specified below',
)
.addToggle((toggle) =>
toggle
.setValue(settings.customPromptsFromFolder.enabled)
.onChange(async (value) => {
settings.customPromptsFromFolder.enabled = value;
await plugin.saveSettings();
this.restartSettingsTab(plugin);
await this.restartSettingsTab(plugin);
}),
);

if (settings.customPromptsFromFolder.enabled) {
new Setting(containerEl)
.setName('File path')
.setDesc('Path to the file containing the custom prompts')
.setName('Folder path')
.setDesc('Folder paths containing the files prompts')
.addText((text) =>
text
.setPlaceholder('Enter the file path')
.setPlaceholder('Enter the folder path')
.setValue(settings.customPromptsFromFolder.path)
.onChange(async (value) => {
settings.customPromptsFromFolder.path = value;
Expand Down Expand Up @@ -465,14 +465,14 @@ export class SettingTab extends PluginSettingTab {
.setName('Reset settings')
.setDesc('This will reset all settings to their default values')
.addButton((button) => {
button.setTooltip('Irrevisible action, please be careful!');
button.setTooltip('Irreversible action, please be careful!');
button.setButtonText('Reset').onClick(async () => {
if (button.buttonEl.textContent === 'Reset') {
// Are you sure? (seconds), give 5 seconds, loop 5 times
for (let i = 0; i < 5; i++) {
button.setButtonText(`Are you sure to reset? (${5 - i})`);
button.setDisabled(true);
sleep(1000);
await sleep(1000);
}

button.setDisabled(false);
Expand All @@ -485,7 +485,7 @@ export class SettingTab extends PluginSettingTab {
// This has already been clicked once, so reset the settings
await plugin.resetSettings();
new Notice('Resetting settings to default values');
this.restartSettingsTab(plugin);
await this.restartSettingsTab(plugin);
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type CodeMirror from 'codemirror';
import type { Editor, Menu } from 'obsidian';
import * as v from 'valibot';
import {
Expand Down Expand Up @@ -44,7 +45,6 @@ export const OpenAIModelsSchema = v.object({
data: v.array(v.object({ id: v.string(), name: v.optional(v.string()) })),
});

export type GoogleGenAIModels = v.InferInput<typeof GoogleGenAIModelsSchema>;
export type OpenAIModels = v.InferInput<typeof OpenAIModelsSchema>;
export type UniformModels = {
id: string;
Expand Down
Loading

0 comments on commit 4cdc015

Please sign in to comment.