2023-04-01 13:31:26 +00:00
/ *
THIS IS A GENERATED / BUNDLED FILE BY ESBUILD
if you want to view the source , please visit the github repository of this plugin
* /
var _ _defProp = Object . defineProperty ;
var _ _getOwnPropDesc = Object . getOwnPropertyDescriptor ;
var _ _getOwnPropNames = Object . getOwnPropertyNames ;
var _ _hasOwnProp = Object . prototype . hasOwnProperty ;
var _ _export = ( target , all ) => {
for ( var name in all )
_ _defProp ( target , name , { get : all [ name ] , enumerable : true } ) ;
} ;
var _ _copyProps = ( to , from , except , desc ) => {
if ( from && typeof from === "object" || typeof from === "function" ) {
for ( let key of _ _getOwnPropNames ( from ) )
if ( ! _ _hasOwnProp . call ( to , key ) && key !== except )
_ _defProp ( to , key , { get : ( ) => from [ key ] , enumerable : ! ( desc = _ _getOwnPropDesc ( from , key ) ) || desc . enumerable } ) ;
}
return to ;
} ;
var _ _toCommonJS = ( mod ) => _ _copyProps ( _ _defProp ( { } , "__esModule" , { value : true } ) , mod ) ;
// main.ts
var main _exports = { } ;
_ _export ( main _exports , {
default : ( ) => LightweightChatGPTPlugin
} ) ;
module . exports = _ _toCommonJS ( main _exports ) ;
var import _obsidian = require ( "obsidian" ) ;
var DEFAULT _SETTINGS = {
apiKey : "" ,
chatGPTModel : "gpt-3.5-turbo" ,
2023-04-15 00:58:06 +00:00
apiUrl : "https://api.openai.com" ,
apiUrlPath : "/v1/chat/completions" ,
temperature : 1 ,
maxTokens : 16 ,
defaultPrompt : "" ,
2023-04-01 13:31:26 +00:00
insertionMode : "end" ,
2023-05-08 01:44:02 +00:00
displayTokensUsage : true ,
2023-04-01 13:31:26 +00:00
showSidebarIcon : true
} ;
2023-11-17 13:37:43 +00:00
function extractErrorMessage ( error ) {
if ( error instanceof Error ) {
return error . message ;
} else {
return String ( error ) ;
}
}
2023-04-01 13:31:26 +00:00
var LightweightChatGPTPlugin = class extends import _obsidian . Plugin {
async onload ( ) {
try {
await this . loadSettings ( ) ;
} catch ( error ) {
2023-11-17 13:37:43 +00:00
let message ;
if ( error instanceof Error ) {
message = error . message ;
} else {
message = String ( error ) ;
}
console . error ( "Error loading settings:" , message ) ;
2023-04-01 13:31:26 +00:00
}
this . app . workspace . onLayoutReady ( ( ) => {
if ( this . settings . showSidebarIcon ) {
this . addSidebarIcon ( ) ;
}
} ) ;
this . addCommand ( {
2023-04-06 02:29:58 +00:00
id : "open-lightweight-window" ,
name : "Open Lightweight Window" ,
2023-04-01 13:31:26 +00:00
callback : ( ) => {
try {
2023-04-15 00:58:06 +00:00
new LightweightChatGPTWindow ( this . app , this ) . open ( ) ;
2023-04-01 13:31:26 +00:00
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error opening Lightweight ChatGPT Plugin Window:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
}
2023-04-06 02:29:58 +00:00
}
// hotkeys: [
// {
// modifiers: ['CTRL'],
// key: 'k',
// },
// ]
2023-04-01 13:31:26 +00:00
} ) ;
try {
this . addSettingTab ( new LightweightChatGPTSettingTab ( this . app , this ) ) ;
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error adding settings tab:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
}
}
addSidebarIcon ( ) {
try {
2023-04-02 02:59:38 +00:00
this . ribbonIconEl = this . addRibbonIcon ( "feather" , "GPT-LiteInquirer" , ( evt ) => {
2023-04-01 13:31:26 +00:00
try {
2023-04-15 00:58:06 +00:00
new LightweightChatGPTWindow ( this . app , this ) . open ( ) ;
2023-04-01 13:31:26 +00:00
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error opening Lightweight ChatGPT Plugin Window:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
}
} ) ;
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error adding sidebar icon:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
}
}
removeSidebarIcon ( ) {
if ( this . ribbonIconEl ) {
try {
this . ribbonIconEl . remove ( ) ;
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error closing sidebar icon:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
}
}
}
onunload ( ) {
}
async loadSettings ( ) {
this . settings = Object . assign ( { } , DEFAULT _SETTINGS , await this . loadData ( ) ) ;
}
async saveSettings ( ) {
await this . saveData ( this . settings ) ;
}
} ;
var LightweightChatGPTWindow = class extends import _obsidian . Modal {
2023-04-15 00:58:06 +00:00
constructor ( app , plugin ) {
2023-04-01 13:31:26 +00:00
super ( app ) ;
2023-04-19 14:46:11 +00:00
this . isSendingRequest = false ;
2023-04-15 00:58:06 +00:00
this . plugin = plugin ;
2023-04-01 13:31:26 +00:00
}
onOpen ( ) {
const { contentEl } = this ;
2023-04-06 02:29:58 +00:00
contentEl . createEl ( "h2" , { text : "GPT Lite Inquirer Window" } ) ;
2023-04-01 13:31:26 +00:00
const activeView = this . app . workspace . getActiveViewOfType ( import _obsidian . MarkdownView ) ;
const selectedText = activeView ? activeView . editor . getSelection ( ) : "" ;
this . inputTextArea = contentEl . createEl ( "textarea" ) ;
2023-04-06 02:29:58 +00:00
this . inputTextArea . classList . add ( "gpt-input-textarea" ) ;
2023-04-02 02:59:38 +00:00
this . inputTextArea . rows = 4 ;
2023-04-01 13:31:26 +00:00
this . inputTextArea . placeholder = "Enter your text here ..." ;
2023-04-15 00:58:06 +00:00
if ( ! this . plugin . settings . defaultPrompt && selectedText ) {
this . inputTextArea . value = ` ${ selectedText }
-- --
` ;
} else if ( this . plugin . settings . defaultPrompt && ! selectedText ) {
this . inputTextArea . value = ` ${ this . plugin . settings . defaultPrompt }
` ;
} else if ( this . plugin . settings . defaultPrompt && selectedText ) {
this . inputTextArea . value = ` ${ selectedText }
-- --
$ { this . plugin . settings . defaultPrompt }
` ;
} else {
this . inputTextArea . value = "" ;
}
2023-04-01 13:31:26 +00:00
this . inputTextArea . addEventListener ( "keydown" , ( event ) => {
if ( event . key === "Enter" && ! event . shiftKey && ! event . ctrlKey ) {
event . preventDefault ( ) ;
this . insertAtCursor ( this . inputTextArea , "\n" ) ;
} else if ( event . key === "Enter" && event . ctrlKey ) {
event . preventDefault ( ) ;
sendButton . click ( ) ;
}
} ) ;
contentEl . createEl ( "hr" ) ;
const maxTokensContainer = contentEl . createEl ( "div" ) ;
2023-04-02 02:59:38 +00:00
maxTokensContainer . className = "max-tokens-container" ;
2023-04-01 13:31:26 +00:00
const maxTokensLabelContainer = maxTokensContainer . createEl ( "div" ) ;
maxTokensLabelContainer . createEl ( "label" , { text : "Max tokens:" } ) ;
2023-11-17 13:37:43 +00:00
const maxTokensDescription = maxTokensLabelContainer . createEl ( "p" , { text : "Max OpenAI ChatGPT Tokens" } ) ;
2023-04-06 02:29:58 +00:00
maxTokensDescription . classList . add ( "max-tokens-description" ) ;
2023-04-01 13:31:26 +00:00
this . maxTokensInput = maxTokensContainer . createEl ( "input" , { type : "number" } ) ;
this . maxTokensInput . placeholder = "Enter max Tokens number" ;
2023-04-06 02:29:58 +00:00
this . maxTokensInput . classList . add ( "max-tokens-input" ) ;
2023-04-01 13:31:26 +00:00
this . maxTokensInput . min = "1" ;
this . maxTokensInput . max = "2048" ;
2023-04-15 00:58:06 +00:00
this . maxTokensInput . value = this . plugin . settings . maxTokens . toString ( ) ;
2023-04-01 13:31:26 +00:00
this . maxTokensInput . addEventListener ( "input" , ( ) => {
if ( parseInt ( this . maxTokensInput . value ) > parseInt ( this . maxTokensInput . max ) ) {
this . maxTokensInput . value = this . maxTokensInput . max ;
new import _obsidian . Notice ( ` Max tokens cannot exceed ${ this . maxTokensInput . max } ` ) ;
} else if ( ! parseInt ( this . maxTokensInput . value ) && parseInt ( this . maxTokensInput . value ) < parseInt ( this . maxTokensInput . min ) ) {
this . maxTokensInput . value = this . maxTokensInput . min ;
new import _obsidian . Notice ( ` Max tokens cannot be less than ${ this . maxTokensInput . min } ` ) ;
}
} ) ;
const buttonSendContainer = contentEl . createEl ( "div" ) ;
buttonSendContainer . style . marginTop = "1rem" ;
const sendButton = buttonSendContainer . createEl ( "button" , {
text : "Send"
} , ( el ) => {
el . style . backgroundColor = "green" ;
el . style . color = "white" ;
} ) ;
2023-04-19 14:46:11 +00:00
const responseDividerLine = contentEl . createEl ( "hr" ) ;
responseDividerLine . style . display = "none" ;
2023-04-01 13:31:26 +00:00
this . outputContainer = contentEl . createEl ( "div" ) ;
2023-04-06 02:29:58 +00:00
this . outputContainer . classList . add ( "output-container" ) ;
2023-05-08 01:44:02 +00:00
this . displayTokensUsageContainer = contentEl . createEl ( "div" ) ;
this . displayTokensUsageContainer . classList . add ( "display-tokens-usage-container" ) ;
const buttonsBottomContainer = contentEl . createEl ( "div" ) ;
buttonsBottomContainer . classList . add ( "buttons-bottom-container" ) ;
const copyToClipboardButton = buttonsBottomContainer . createEl ( "button" , { text : "Copy to clipboard" } ) ;
2023-04-01 13:31:26 +00:00
copyToClipboardButton . style . marginRight = "1rem" ;
2023-05-08 01:44:02 +00:00
copyToClipboardButton . style . backgroundColor = "green" ;
copyToClipboardButton . style . color = "white" ;
2023-04-01 13:31:26 +00:00
copyToClipboardButton . style . display = "none" ;
2023-05-08 01:44:02 +00:00
const addToPostButton = buttonsBottomContainer . createEl ( "button" , { text : "Add to current document" } ) ;
2023-04-01 13:31:26 +00:00
addToPostButton . style . marginRight = "1rem" ;
addToPostButton . style . display = "none" ;
sendButton . addEventListener ( "click" , async ( ) => {
if ( ! parseInt ( this . maxTokensInput . value ) ) {
2023-04-15 00:58:06 +00:00
new import _obsidian . Notice ( ` Use the default value of ${ this . plugin . settings . maxTokens . toString ( ) } for max Tokens ` ) ;
this . maxTokensInput . value = this . plugin . settings . maxTokens . toString ( ) ;
2023-04-01 13:31:26 +00:00
}
2023-04-19 14:46:11 +00:00
if ( ! this . plugin . settings . apiKey ) {
new import _obsidian . Notice ( "Please enter your API key in the plugin settings." ) ;
return ;
}
2023-04-01 13:31:26 +00:00
if ( ! this . inputTextArea . value ) {
2023-05-08 01:44:02 +00:00
new import _obsidian . Notice ( "Please enter text" ) ;
2023-04-01 13:31:26 +00:00
return ;
}
2023-04-19 14:46:11 +00:00
if ( this . isSendingRequest ) {
return ;
}
this . isSendingRequest = true ;
2023-04-01 13:31:26 +00:00
sendButton . textContent = "Sending ..." ;
sendButton . textContent = "Waiting for API full response ..." ;
try {
2023-04-19 14:46:11 +00:00
new import _obsidian . Notice ( "Sending..." ) ;
2023-04-01 13:31:26 +00:00
this . responseAPIText = await this . sendRequestToChatGPT ( ) ;
2023-05-08 01:44:02 +00:00
if ( this . responseAPIText && this . responseAPIText . trim ( ) !== "" ) {
2023-04-19 14:46:11 +00:00
this . outputContainer . empty ( ) ;
}
this . outputContainer . createEl ( "p" , { text : this . responseAPIText } ) ;
2023-04-01 13:31:26 +00:00
sendButton . textContent = "Send" ;
2023-04-19 14:46:11 +00:00
responseDividerLine . style . display = "block" ;
2023-04-01 13:31:26 +00:00
copyToClipboardButton . style . display = "block" ;
addToPostButton . style . display = "block" ;
} catch ( error ) {
sendButton . textContent = "Send" ;
2023-11-17 13:37:43 +00:00
console . error ( "Error during API request:" , extractErrorMessage ( error ) ) ;
2023-04-19 14:46:11 +00:00
} finally {
this . isSendingRequest = false ;
2023-04-01 13:31:26 +00:00
}
} ) ;
copyToClipboardButton . addEventListener ( "click" , ( ) => {
this . copyToClipboard ( this . responseAPIText ) ;
} ) ;
addToPostButton . addEventListener ( "click" , ( ) => {
2023-04-15 00:58:06 +00:00
this . appendToCurrentNote ( this . inputTextArea . value , this . responseAPIText , this . plugin . settings . insertionMode ) ;
2023-04-01 13:31:26 +00:00
} ) ;
}
2023-05-08 01:44:02 +00:00
async displayTokensUsage ( promptTokens , completionTokens , totalTokens ) {
this . displayTokensUsageContainer . empty ( ) ;
this . displayTokensUsageContainer . createEl ( "p" , {
2023-11-17 13:37:43 +00:00
text : ` Tokens Usage Prompt: ${ promptTokens } /
Completion : $ { completionTokens } /
2023-05-08 01:44:02 +00:00
Total : $ { totalTokens } `
} ) ;
}
2023-04-01 13:31:26 +00:00
async sendRequestToChatGPT ( ) {
const maxTokens = parseInt ( this . maxTokensInput . value ) ;
try {
2023-04-06 02:29:58 +00:00
const response = await ( 0 , import _obsidian . request ) ( {
2023-04-15 00:58:06 +00:00
url : this . plugin . settings . apiUrl + this . plugin . settings . apiUrlPath ,
2023-04-01 13:31:26 +00:00
method : "POST" ,
headers : {
"Content-Type" : "application/json" ,
2023-04-15 00:58:06 +00:00
"Authorization" : ` Bearer ${ this . plugin . settings . apiKey } `
2023-04-01 13:31:26 +00:00
} ,
body : JSON . stringify ( {
2023-04-15 00:58:06 +00:00
model : this . plugin . settings . chatGPTModel ,
2023-04-01 13:31:26 +00:00
max _tokens : maxTokens ,
2023-04-15 00:58:06 +00:00
temperature : this . plugin . settings . temperature ,
2023-04-19 14:46:11 +00:00
stream : false ,
2023-04-01 13:31:26 +00:00
messages : [
{ role : "user" , content : this . inputTextArea . value }
]
} )
} ) ;
2023-04-23 02:27:27 +00:00
const currentResult = JSON . parse ( response ) ;
if ( currentResult . choices && currentResult . choices . length > 0 ) {
const gptResponse = currentResult . choices [ 0 ] . message . content ;
2023-05-08 01:44:02 +00:00
const promptTokens = currentResult . usage . prompt _tokens ;
const completionTokens = currentResult . usage . completion _tokens ;
const totalTokens = currentResult . usage . total _tokens ;
if ( this . plugin . settings . displayTokensUsage ) {
this . displayTokensUsage ( promptTokens , completionTokens , totalTokens ) ;
}
2023-04-01 13:31:26 +00:00
return gptResponse ;
2023-04-23 02:27:27 +00:00
} else if ( currentResult . error ) {
throw new Error ( JSON . stringify ( currentResult . error ) ) ;
2023-04-01 13:31:26 +00:00
} else {
2023-04-06 02:29:58 +00:00
throw new Error ( "Unexpected API response format" ) ;
2023-04-01 13:31:26 +00:00
}
} catch ( error ) {
2023-11-17 13:37:43 +00:00
console . error ( "Error during API request:" , extractErrorMessage ( error ) ) ;
2023-04-06 02:29:58 +00:00
new import _obsidian . Notice (
2023-11-17 13:37:43 +00:00
"Error during API request: " + extractErrorMessage ( error )
2023-04-06 02:29:58 +00:00
) ;
2023-04-01 13:31:26 +00:00
}
}
insertAtCursor ( textArea , text ) {
const startPos = textArea . selectionStart ;
const endPos = textArea . selectionEnd ;
textArea . value = textArea . value . substring ( 0 , startPos ) + text + textArea . value . substring ( endPos , textArea . value . length ) ;
textArea . selectionStart = startPos + text . length ;
textArea . selectionEnd = startPos + text . length ;
}
async appendToCurrentNote ( sentText , receivedText , insertionMode ) {
const receivedAPIText = receivedText || "" ;
if ( receivedAPIText . length <= 0 ) {
new import _obsidian . Notice ( "No text to add" ) ;
return ;
}
const activeView = this . app . workspace . getActiveViewOfType ( import _obsidian . MarkdownView ) ;
const activeLeaf = activeView == null ? void 0 : activeView . leaf ;
if ( activeView && activeLeaf && activeLeaf . view instanceof import _obsidian . MarkdownView ) {
const editor = activeLeaf . view . editor ;
const formattedText = `
-- -
$ { receivedAPIText }
-- -
` ;
if ( insertionMode === "end" ) {
const lastLine = editor . lastLine ( ) ;
editor . replaceRange ( formattedText , { line : lastLine + 1 , ch : 0 } ) ;
} else if ( insertionMode === "current" ) {
const cursorPosition = editor . getCursor ( ) ;
const currentLine = cursorPosition . line ;
editor . replaceRange ( formattedText , { line : currentLine + 1 , ch : 0 } ) ;
}
} else {
new import _obsidian . Notice ( "Cannot append content to the current view. Please open a markdown note." ) ;
}
}
async copyToClipboard ( receivedText ) {
const receivedAPIText = receivedText || "" ;
if ( receivedAPIText . length > 0 ) {
navigator . clipboard . writeText ( receivedAPIText ) . then ( ( ) => {
new import _obsidian . Notice ( "Copied to clipboard!" ) ;
} ) . catch ( ( error ) => {
2023-11-17 13:37:43 +00:00
console . error ( "Error copying to clipboard:" , extractErrorMessage ( error ) ) ;
2023-04-01 13:31:26 +00:00
new import _obsidian . Notice ( "Error copying to clipboard" ) ;
} ) ;
} else {
new import _obsidian . Notice ( "No text to copy" ) ;
}
}
onClose ( ) {
const { contentEl } = this ;
contentEl . empty ( ) ;
}
} ;
var LightweightChatGPTSettingTab = class extends import _obsidian . PluginSettingTab {
constructor ( app , plugin ) {
super ( app , plugin ) ;
this . plugin = plugin ;
}
display ( ) {
const { containerEl } = this ;
containerEl . empty ( ) ;
containerEl . createEl ( "h2" , { text : "Settings Lightweight ChatGPT Window" } ) ;
2023-04-23 02:27:27 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "API Key*" ) . setDesc (
createFragment ( ( frag ) => {
frag . appendText ( "Enter your OpenAI API key. " ) ;
frag . appendText ( "If you don't have it, you can " ) ;
frag . createEl ( "a" , {
href : "https://platform.openai.com/account/api-keys" ,
text : "Click Here"
} ) ;
frag . appendText ( " to apply." ) ;
} )
) . addText ( ( text ) => text . setPlaceholder ( "Enter your API key" ) . setValue ( this . plugin . settings . apiKey ) . onChange ( async ( value ) => {
2023-04-01 13:31:26 +00:00
this . plugin . settings . apiKey = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-04-23 02:27:27 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "OpenAI Model" ) . setDesc ( "Select the OpenAI model to use." ) . addDropdown ( ( dropDown ) => dropDown . addOption ( "gpt-3.5-turbo" , "gpt-3.5-turbo" ) . setValue ( this . plugin . settings . chatGPTModel ) . onChange ( async ( value ) => {
2023-04-15 00:58:06 +00:00
this . plugin . settings . chatGPTModel = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "API URL*" ) . setDesc ( "Modify here if you want to use a self-built server, otherwise keep the default without any changes." ) . addText ( ( text ) => text . setPlaceholder ( "https://api.openai.com" ) . setValue ( this . plugin . settings . apiUrl ) . onChange ( async ( value ) => {
this . plugin . settings . apiUrl = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "API URL Path*" ) . setDesc ( "Modify here if you want to use a self-built server, otherwise keep the default without any changes." ) . addText ( ( text ) => text . setPlaceholder ( "/v1/chat/completions" ) . setValue ( this . plugin . settings . apiUrlPath ) . onChange ( async ( value ) => {
this . plugin . settings . apiUrlPath = value ;
2023-04-01 13:31:26 +00:00
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-04-15 00:58:06 +00:00
containerEl . createEl ( "h6" , { text : "ChatGPT Model setting" } ) ;
2023-04-01 13:31:26 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "Temperature" ) . setDesc ( "Enter the temperature value between 0 and 2 (inclusive) for the API response" ) . addText ( ( text ) => text . setPlaceholder ( "Enter temperature" ) . setValue ( this . plugin . settings . temperature . toString ( ) ) . onChange ( async ( value ) => {
let parsedValue = parseFloat ( value ) ;
2023-05-08 01:44:02 +00:00
if ( isNaN ( parsedValue ) ) {
parsedValue = 1 ;
}
2023-04-01 13:31:26 +00:00
if ( parsedValue < 0 ) {
parsedValue = 0 ;
} else if ( parsedValue > 2 ) {
parsedValue = 2 ;
}
this . plugin . settings . temperature = parsedValue ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-04-23 02:27:27 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "Default Max Tokens" ) . setDesc ( this . plugin . settings . chatGPTModel === "gpt-4" ? "Enter the maximum number of tokens for the API response (integer, min: 1, max: 4096)" : "Enter the maximum number of tokens for the API response (integer, min: 1, max: 2048)" ) . addText ( ( text ) => text . setPlaceholder ( "Enter max tokens" ) . setValue ( this . plugin . settings . maxTokens . toString ( ) ) . onChange ( async ( value ) => {
2023-04-15 00:58:06 +00:00
let parsedValue = parseInt ( value ) ;
2023-04-23 02:27:27 +00:00
let parsedMaxValue = 2048 ;
if ( this . plugin . settings . chatGPTModel === "gpt-4" ) {
parsedMaxValue = 4096 ;
}
2023-05-08 01:44:02 +00:00
if ( isNaN ( parsedValue ) || parsedValue > parsedMaxValue ) {
2023-04-23 02:27:27 +00:00
parsedValue = parsedMaxValue ;
2023-05-08 01:44:02 +00:00
} else if ( parsedValue < 1 ) {
parsedValue = 1 ;
2023-04-15 00:58:06 +00:00
}
this . plugin . settings . maxTokens = parsedValue ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
new import _obsidian . Setting ( containerEl ) . setName ( "Default Prompt" ) . setDesc (
2023-04-23 02:27:27 +00:00
"Default Prompt will be automatically inserted into the requested Prompt. (Not necessary)"
2023-04-15 00:58:06 +00:00
) . addTextArea ( ( text ) => text . setPlaceholder ( "Enter Default Prompt" ) . setValue ( this . plugin . settings . defaultPrompt ) . onChange ( async ( value ) => {
this . plugin . settings . defaultPrompt = value ;
2023-04-01 13:31:26 +00:00
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-04-15 00:58:06 +00:00
containerEl . createEl ( "h6" , { text : "Additional setting" } ) ;
2023-04-01 13:31:26 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "Insertion Mode" ) . setDesc ( "Choose how to insert text" ) . addDropdown ( ( dropdown ) => dropdown . addOption ( "end" , "Insert at end of document" ) . addOption ( "current" , "Insert at current position" ) . setValue ( this . plugin . settings . insertionMode ) . onChange ( async ( value ) => {
this . plugin . settings . insertionMode = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-05-08 01:44:02 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "Display Tokens Usage" ) . setDesc ( "Toggle to display or hide the number of Tokens used per request." ) . addToggle ( ( toggle ) => toggle . setValue ( this . plugin . settings . displayTokensUsage ) . onChange ( async ( value ) => {
this . plugin . settings . displayTokensUsage = value ;
await this . plugin . saveSettings ( ) ;
} ) ) ;
2023-04-01 13:31:26 +00:00
new import _obsidian . Setting ( containerEl ) . setName ( "Show Sidebar Icon" ) . setDesc ( "Toggle to show or hide the sidebar icon" ) . addToggle ( ( toggle ) => toggle . setValue ( this . plugin . settings . showSidebarIcon ) . onChange ( async ( value ) => {
this . plugin . settings . showSidebarIcon = value ;
await this . plugin . saveSettings ( ) ;
if ( value ) {
this . plugin . addSidebarIcon ( ) ;
} else {
this . plugin . removeSidebarIcon ( ) ;
}
} ) ) ;
const politeMessage = containerEl . createEl ( "p" , {
2023-04-15 00:58:06 +00:00
cls : "settings-polite-message"
2023-04-01 13:31:26 +00:00
} ) ;
politeMessage . textContent = "If you enjoy this plugin or would like to show your support, please consider giving it a free star on GitHub~ Your appreciation means a lot to me!" ;
const githubLink = containerEl . createEl ( "div" , {
2023-04-15 00:58:06 +00:00
cls : "settings-github-link-container"
2023-04-01 13:31:26 +00:00
} ) ;
const githubAnchor = githubLink . createEl ( "a" , {
2023-04-15 00:58:06 +00:00
cls : "settings-github-link"
} ) ;
2023-04-02 02:59:38 +00:00
githubAnchor . href = "https://github.com/ittuann/obsidian-gpt-liteinquirer-plugin" ;
2023-04-01 13:31:26 +00:00
githubAnchor . target = "_blank" ;
githubAnchor . rel = "noopener" ;
2023-05-08 01:44:02 +00:00
const githubLogo = githubAnchor . createEl ( "img" , {
cls : "settings-github-logo"
2023-04-01 13:31:26 +00:00
} ) ;
2023-04-15 00:58:06 +00:00
githubLogo . src = "https://assets.stickpng.com/images/5847f98fcef1014c0b5e48c0.png" ;
githubLogo . alt = "GitHub" ;
2023-05-08 01:44:02 +00:00
const githubText = githubAnchor . createEl ( "span" , {
text : "View on GitHub"
} ) ;
2023-04-15 00:58:06 +00:00
githubText . style . display = "inline-block" ;
githubText . style . verticalAlign = "middle" ;
2023-04-01 13:31:26 +00:00
}
} ;