Skip to content

Commit

Permalink
v2.4.3 Add default save location (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
logancyang authored Aug 14, 2023
1 parent 5e80515 commit effd534
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-copilot",
"version": "2.4.2",
"version": "2.4.3",
"description": "ChatGPT integration for Obsidian",
"main": "main.js",
"scripts": {
Expand Down
11 changes: 9 additions & 2 deletions src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,12 @@ interface ChatProps {
aiState: AIState;
emitter: EventEmitter;
getChatVisibility: () => Promise<boolean>;
defaultSaveFolder: string;
debug: boolean;
}

const Chat: React.FC<ChatProps> = ({
sharedState, aiState, emitter, getChatVisibility, debug
sharedState, aiState, emitter, getChatVisibility, defaultSaveFolder, debug
}) => {
const [
chatHistory, addMessage, clearMessages,
Expand Down Expand Up @@ -112,8 +113,14 @@ const Chat: React.FC<ChatProps> = ({
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);
Expand Down
7 changes: 3 additions & 4 deletions src/components/CopilotView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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}
/>
</React.StrictMode>
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit effd534

Please sign in to comment.