diff --git a/manifest.json b/manifest.json index cbb406cb..3268b3ca 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "copilot", "name": "Copilot", - "version": "2.4.2", + "version": "2.4.3", "minAppVersion": "0.15.0", "description": "A ChatGPT Copilot in Obsidian.", "author": "Logan Yang", diff --git a/package-lock.json b/package-lock.json index 78c6b201..9adc1b7a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "obsidian-copilot", - "version": "2.4.2", + "version": "2.4.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "obsidian-copilot", - "version": "2.4.2", + "version": "2.4.3", "license": "AGPL-3.0", "dependencies": { "@huggingface/inference": "^1.8.0", diff --git a/package.json b/package.json index 87748e90..525a935f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian-copilot", - "version": "2.4.2", + "version": "2.4.3", "description": "ChatGPT integration for Obsidian", "main": "main.js", "scripts": { diff --git a/src/components/Chat.tsx b/src/components/Chat.tsx index 896a92e5..0e2eb8be 100644 --- a/src/components/Chat.tsx +++ b/src/components/Chat.tsx @@ -50,11 +50,12 @@ interface ChatProps { aiState: AIState; emitter: EventEmitter; getChatVisibility: () => Promise; + defaultSaveFolder: string; debug: boolean; } const Chat: React.FC = ({ - sharedState, aiState, emitter, getChatVisibility, debug + sharedState, aiState, emitter, getChatVisibility, defaultSaveFolder, debug }) => { const [ chatHistory, addMessage, clearMessages, @@ -112,8 +113,14 @@ const Chat: React.FC = ({ const chatContent = chatHistory.map((message) => `**${message.sender}**: ${message.message}`).join('\n\n'); try { + // Check if the default folder exists or create it + const folder = app.vault.getAbstractFileByPath(defaultSaveFolder); + if (!folder) { + await app.vault.createFolder(defaultSaveFolder); + } + const now = new Date(); - const noteFileName = `Chat-${formatDateTime(now)}.md`; + const noteFileName = `${defaultSaveFolder}/Chat-${formatDateTime(now)}.md`; const newNote: TFile = await app.vault.create(noteFileName, chatContent); const leaf = app.workspace.getLeaf(); leaf.openFile(newNote); diff --git a/src/components/CopilotView.tsx b/src/components/CopilotView.tsx index f65d7bd5..f24113ef 100644 --- a/src/components/CopilotView.tsx +++ b/src/components/CopilotView.tsx @@ -13,24 +13,22 @@ import { Root, createRoot } from 'react-dom/client'; export default class CopilotView extends ItemView { private sharedState: SharedState; private aiState: AIState; - private model: string; private root: Root | null = null; + private defaultSaveFolder: string; private debug = false; emitter: EventEmitter; userSystemPrompt = ''; - useNotesAsContext = false; constructor(leaf: WorkspaceLeaf, private plugin: CopilotPlugin) { super(leaf); this.sharedState = plugin.sharedState; this.app = plugin.app; this.aiState = plugin.aiState; - this.model = plugin.settings.defaultModel; this.debug = plugin.settings.debug; this.emitter = new EventEmitter(); this.getChatVisibility = this.getChatVisibility.bind(this); this.userSystemPrompt = plugin.settings.userSystemPrompt; - this.useNotesAsContext = plugin.settings.useNotesAsContext; + this.defaultSaveFolder = plugin.settings.defaultSaveFolder; } getViewType(): string { @@ -68,6 +66,7 @@ export default class CopilotView extends ItemView { aiState={this.aiState} emitter={this.emitter} getChatVisibility={this.getChatVisibility} + defaultSaveFolder={this.defaultSaveFolder} debug={this.debug} /> diff --git a/src/constants.ts b/src/constants.ts index f96a1977..c3225568 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -107,13 +107,13 @@ export const DEFAULT_SETTINGS: CopilotSettings = { temperature: 0.7, maxTokens: 1000, contextTurns: 3, - useNotesAsContext: false, userSystemPrompt: '', openAIProxyBaseUrl: '', localAIModel: '', ttlDays: 30, stream: true, embeddingProvider: OPENAI, + defaultSaveFolder: 'copilot-conversations', debug: false, }; export const OPEN_AI_API_URL = 'https://api.openai.com/v1/chat/completions'; diff --git a/src/main.ts b/src/main.ts index e0a08661..da870d09 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,13 +32,13 @@ export interface CopilotSettings { temperature: number; maxTokens: number; contextTurns: number; - useNotesAsContext: boolean; userSystemPrompt: string; openAIProxyBaseUrl: string; localAIModel: string; ttlDays: number; stream: boolean; embeddingProvider: string; + defaultSaveFolder: string; debug: boolean; } diff --git a/src/settings.ts b/src/settings.ts index f0303a27..71fc47c8 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -75,6 +75,18 @@ export class CopilotSettingTab extends PluginSettingTab { }); }); + new Setting(containerEl) + .setName("Default Conversation Folder Name") + .setDesc("The default folder name where chat conversations will be saved. Default is 'copilot-conversations'") + .addText(text => text + .setPlaceholder("copilot-conversations") + .setValue(this.plugin.settings.defaultSaveFolder) + .onChange(async (value: string) => { + this.plugin.settings.defaultSaveFolder = value; + await this.plugin.saveSettings(); + }) + ); + containerEl.createEl('h4', { text: 'API Settings' }); containerEl.createEl('h6', { text: 'OpenAI API' }); diff --git a/versions.json b/versions.json index 613c4e2e..0b6e542b 100644 --- a/versions.json +++ b/versions.json @@ -23,5 +23,6 @@ "2.3.6": "0.15.0", "2.4.0": "0.15.0", "2.4.1": "0.15.0", - "2.4.2": "0.15.0" + "2.4.2": "0.15.0", + "2.4.3": "0.15.0" } \ No newline at end of file