Skip to content

Commit

Permalink
Comply with review (#72)
Browse files Browse the repository at this point in the history
* change Obsidian Smart Composer -> Smart Composer

* fix: don't use detach on chat view activation

* use sentence case instead of title case in UI

* avoid using options/settings in settings headings

* use htmlToMarkdown from obsidian instead of turndown
  • Loading branch information
glowingjade authored Oct 31, 2024
1 parent 6ea0b58 commit e866ee1
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 69 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Obsidian Smart Composer
# Smart Composer

![SC1_Title.gif](https://github.com/user-attachments/assets/a50a1f80-39ff-4eba-8090-e3d75e7be98c)

Expand Down Expand Up @@ -131,7 +131,7 @@ Your feedback and experiences are crucial in making Smart Composer better for ev

## Contributing

We welcome all kinds of contributions to Obsidian Smart Composer, including bug reports, bug fixes, documentation improvements, and feature enhancements.
We welcome all kinds of contributions to Smart Composer, including bug reports, bug fixes, documentation improvements, and feature enhancements.

**For major feature ideas, please create an issue first to discuss feasibility and implementation approach.**

Expand Down
21 changes: 0 additions & 21 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@types/react": "^18.3.10",
"@types/react-dom": "^18.3.0",
"@types/react-syntax-highlighter": "^15.5.13",
"@types/turndown": "^5.0.5",
"@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
Expand Down Expand Up @@ -70,8 +69,7 @@
"react-markdown": "^9.0.1",
"react-syntax-highlighter": "^15.5.0",
"remark-gfm": "^4.0.0",
"turndown": "^7.2.0",
"uuid": "^10.0.0",
"zod": "^3.23.8"
}
}
}
2 changes: 1 addition & 1 deletion src/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class ChatView extends ItemView {
}

getDisplayText() {
return 'Smart Composer Chat'
return 'Smart composer chat'
}

async onOpen() {
Expand Down
2 changes: 1 addition & 1 deletion src/OpenSettingsModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class OpenSettingsModal extends Modal {
this.setTitle(title)

new Setting(this.contentEl).addButton((button) => {
button.setButtonText('Open Settings')
button.setButtonText('Open settings')
button.onClick(() => {
this.close()
onSubmit()
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useChatHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export function useChatHistory() {
? editorStateToPlainText(firstUserMessage.content).substring(
0,
20,
) || 'New Chat'
: 'New Chat',
) || 'New chat'
: 'New chat',
messages: serializedMessages,
updatedAt: Date.now(),
})
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default class SmartCopilotPlugin extends Plugin {
this.registerView(APPLY_VIEW_TYPE, (leaf) => new ApplyView(leaf))

// This creates an icon in the left ribbon.
this.addRibbonIcon('message-square', 'Open Smart Composer', () =>
this.addRibbonIcon('message-square', 'Open smart composer', () =>
this.openChatView(),
)

Expand Down Expand Up @@ -160,9 +160,9 @@ export default class SmartCopilotPlugin extends Plugin {
// chatProps is consumed in ChatView.tsx
this.initialChatProps = chatProps

this.app.workspace.detachLeavesOfType(CHAT_VIEW_TYPE)
const leaf = this.app.workspace.getLeavesOfType(CHAT_VIEW_TYPE)[0]

await this.app.workspace.getRightLeaf(false)?.setViewState({
await (leaf ?? this.app.workspace.getRightLeaf(false))?.setViewState({
type: CHAT_VIEW_TYPE,
active: true,
})
Expand Down
28 changes: 14 additions & 14 deletions src/settings/SettingTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {

const apiKeysHeading = new Setting(containerEl)
.setHeading()
.setName('API Keys')
.setName('API keys')
.setDesc('Enter your API keys for the services you want to use')

apiKeysHeading.descEl.createEl('br')
Expand All @@ -35,7 +35,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
},
})

new Setting(containerEl).setName('OpenAI API Key').addText((text) =>
new Setting(containerEl).setName('OpenAI API key').addText((text) =>
text
.setPlaceholder('Enter your API key')
.setValue(this.plugin.settings.openAIApiKey)
Expand All @@ -47,7 +47,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
}),
)

new Setting(containerEl).setName('Groq API Key').addText((text) =>
new Setting(containerEl).setName('Groq API key').addText((text) =>
text
.setPlaceholder('Enter your API key')
.setValue(this.plugin.settings.groqApiKey)
Expand All @@ -59,7 +59,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
}),
)

new Setting(containerEl).setName('Anthropic API Key').addText((text) =>
new Setting(containerEl).setName('Anthropic API key').addText((text) =>
text
.setPlaceholder('Enter your API key')
.setValue(this.plugin.settings.anthropicApiKey)
Expand All @@ -72,7 +72,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
)

new Setting(containerEl)
.setName('Ollama Address')
.setName('Ollama address')
.setDesc(
'Set the Ollama URL and port address - normally http://127.0.0.1:11434',
)
Expand All @@ -87,10 +87,10 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
}),
)

new Setting(containerEl).setHeading().setName('Model Settings')
new Setting(containerEl).setHeading().setName('Model')

new Setting(containerEl)
.setName('Chat Model')
.setName('Chat model')
.setDesc('Choose the model you want to use for chat')
.addDropdown((dropdown) =>
dropdown
Expand All @@ -110,7 +110,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
)

new Setting(containerEl)
.setName('Apply Model')
.setName('Apply model')
.setDesc('Choose the model you want to use for apply')
.addDropdown((dropdown) =>
dropdown
Expand All @@ -133,7 +133,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
)

new Setting(containerEl)
.setName('Embedding Model')
.setName('Embedding model')
.setDesc('Choose the model you want to use for embeddings')
.addDropdown((dropdown) =>
dropdown
Expand All @@ -157,7 +157,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {

new Setting(containerEl)
.setHeading()
.setName('System Prompt')
.setName('System prompt')
.setDesc('This prompt will be added to the beginning of every chat.')

new Setting(containerEl)
Expand All @@ -173,10 +173,10 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
}),
)

new Setting(containerEl).setHeading().setName('RAG Options')
new Setting(containerEl).setHeading().setName('RAG')

new Setting(containerEl)
.setName('Chunk Size')
.setName('Chunk size')
.setDesc(
'Set the chunk size for text splitting. After changing this, please re-index the vault using the "Rebuild entire vault index" command.',
)
Expand All @@ -199,7 +199,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
)

new Setting(containerEl)
.setName('Threshold Tokens')
.setName('Threshold tokens')
.setDesc(
'Maximum number of tokens before switching to RAG. If the total tokens from mentioned files exceed this, RAG will be used instead of including all file contents.',
)
Expand All @@ -222,7 +222,7 @@ export class SmartCopilotSettingTab extends PluginSettingTab {
)

new Setting(containerEl)
.setName('Minimum Similarity')
.setName('Minimum similarity')
.setDesc(
'Minimum similarity score for RAG results. Higher values return more relevant but potentially fewer results.',
)
Expand Down
2 changes: 1 addition & 1 deletion src/utils/chatHistoryManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class ChatConversationManager {
const newChatConversation: ChatConversation = {
schemaVersion: CURRENT_SCHEMA_VERSION,
id,
title: 'New Chat',
title: 'New chat',
createdAt: Date.now(),
updatedAt: Date.now(),
messages: [],
Expand Down
23 changes: 2 additions & 21 deletions src/utils/promptGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { App, TFile, requestUrl } from 'obsidian'
import TurndownService from 'turndown'
import { App, TFile, htmlToMarkdown, requestUrl } from 'obsidian'

import { editorStateToPlainText } from '../components/chat-view/chat-input/utils/editor-state-to-plain-text'
import { QueryProgressState } from '../components/chat-view/QueryProgress'
Expand Down Expand Up @@ -390,24 +389,6 @@ ${transcript.map((t) => `${t.offset}: ${t.text}`).join('\n')}`

const response = await requestUrl({ url })

const turndown = new TurndownService()

turndown.addRule('ignoreEmptyLinks', {
filter: (node) => {
return (
node.nodeName === 'A' &&
node.textContent?.trim() === '' &&
!node.querySelector('img')
)
},
replacement: () => '',
})

turndown.remove('script')
turndown.remove('style')

const markdown: string = turndown.turndown(response.text)

return markdown
return htmlToMarkdown(response.text)
}
}

0 comments on commit e866ee1

Please sign in to comment.