INNER CODE UNIT · TypeScript
existingLeaf
eugeneyan/obsidian-copilot · plugin/main.ts:36
const existingLeaf = this.app.workspace.getLeavesOfType('markdown').find(leaf => leaf.view.file && leaf.view.file.path === file.path);
if (existingLeaf) {
// If a pane with the file already exists, just set the content
(existingLeaf.view as MarkdownView).editor.setValue(content);
} else {
// If no pane with the file exists, create a new one
const leaf = this.app.workspace.getLeaf('split', 'vertical');
leaf.openFile(file);
}
}
private async queryLLM(messages: Array<any>, model: string, temperature = 0.7) {
return await fetch('https://api.openai.com/v1/chat/completions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',