generated from obsidianmd/obsidian-sample-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.ts
More file actions
377 lines (293 loc) · 12.1 KB
/
settings.ts
File metadata and controls
377 lines (293 loc) · 12.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
import { PluginSettingTab, App, Setting } from 'obsidian';
import askAIPlugin from './main';
export class askAISettingTab extends PluginSettingTab {
plugin: askAIPlugin;
constructor(app: App, plugin: askAIPlugin) {
super(app, plugin);
this.plugin = plugin;
}
display(): void {
const { containerEl } = this;
containerEl.empty();
containerEl.createEl("h1", { text: "Chat With Notes Settings" });
containerEl.createEl("br", { text: "" });
new Setting(containerEl)
.setName('Chat Provider')
.setDesc('Select the provider for AI completions')
.addDropdown((dropdown) =>
dropdown
.addOptions({
openrouter: 'Open Router',
groq: 'Groq',
google: 'Google',
openai: 'OpenAI',
cloudflare: "Cloudflare",
custom: 'Custom',
})
.setValue(this.plugin.settings.chatProvider || 'cloudflare')
.onChange(async (value) => {
this.plugin.settings.chatProvider = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName('Completion Provider')
.setDesc('Select the provider for AI completions')
.addDropdown((dropdown) =>
dropdown
.addOptions({
openrouter: 'Open Router',
//groq: 'Groq',
google: 'Google',
openai: 'OpenAI',
cloudflare: "Cloudflare",
custom: 'Custom',
})
.setValue(this.plugin.settings.completionProvider || 'google')
.onChange(async (value) => {
this.plugin.settings.completionProvider = value;
await this.plugin.saveSettings();
})
);
containerEl.createEl("br", { text: "" });
const openRouterSection = containerEl.createEl('details');
const orsummaryEl = openRouterSection.createEl('summary');
orsummaryEl.createEl('strong', { text: 'Open Router Settings' });
const openRouterSettingsContainer = openRouterSection.createEl('div');
openRouterSettingsContainer.createEl("br", { text: "" });
new Setting(openRouterSettingsContainer)
.setName('Open Router API Key')
.setDesc('Enter your free API key for Open Router, found here https://openrouter.io/')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.openRouterKey)
.onChange(async (value) => {
this.plugin.settings.openRouterKey = value;
await this.plugin.saveSettings();
})
);
new Setting(openRouterSettingsContainer)
.setName('Open Router Model')
.setDesc('Enter a model')
.addText((text) =>
text
.setPlaceholder('microsoft/phi-3-medium-128k-instruct:free')
.setValue(this.plugin.settings.openRouterModel || 'microsoft/phi-3-medium-128k-instruct:free')
.onChange(async (value) => {
this.plugin.settings.openRouterModel = value;
await this.plugin.saveSettings();
})
);
containerEl.createEl("br", { text: "" });
const groqSection = containerEl.createEl('details');
const summaryEl = groqSection.createEl('summary');
summaryEl.createEl('strong', { text: 'Groq Settings' });
containerEl.createEl("br", { text: "" });
const groqSettingsContainer = groqSection.createEl('div');
groqSettingsContainer.createEl("br", { text: "" });
new Setting(groqSettingsContainer)
.setName('Groq API Key')
.setDesc('Enter your free API key for Groq, found here https://console.groq.com/keys')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.groqKey)
.onChange(async (value) => {
this.plugin.settings.groqKey = value;
await this.plugin.saveSettings();
})
);
new Setting(groqSettingsContainer)
.setName('Groq Model')
.setDesc('Select a model')
.addDropdown((dropdown) =>
dropdown
.addOptions({
"gemma-7b-it": 'Gemma 7b',
"gemma2-9b-it": 'Gemma2 9b',
"llama3-70b-8192": 'Llama 3 70b',
"llama3-8b-8192": 'Llama 3 8b',
"mixtral-8x7b-32768": 'Mixtral 8x7b',
})
.setValue(this.plugin.settings.groqModel || "llama3-8b-8192")
.onChange(async (value) => {
this.plugin.settings.groqModel = value;
await this.plugin.saveSettings();
})
);
const googleSection = containerEl.createEl('details');
const gsummaryEl = googleSection.createEl('summary');
gsummaryEl.createEl('strong', { text: 'Google Settings' });
const googleSettingsContainer = googleSection.createEl('div');
googleSettingsContainer.createEl("br", { text: "" });
new Setting(googleSettingsContainer)
.setName('Google API Key')
.setDesc('Enter your free API key for Google, found here https://aistudio.google.com/app/apikey')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.googleKey)
.onChange(async (value) => {
this.plugin.settings.googleKey = value;
await this.plugin.saveSettings();
})
);
new Setting(googleSettingsContainer)
.setName('Vision')
.setDesc('Let the AI see images in your notes - in development, not working yet')
.addToggle((toggle) =>
toggle
.setValue(this.plugin.settings.googleVis || false)
.onChange((value) => {
this.plugin.settings.googleVis = value;
this.plugin.saveSettings();
})
);
containerEl.createEl("br", { text: "" });
const openaiSection = containerEl.createEl('details');
const osummaryEl = openaiSection.createEl('summary');
osummaryEl.createEl('strong', { text: 'OpenAI Settings' });
const openaiSettingsContainer = openaiSection.createEl('div');
openaiSettingsContainer.createEl("br", { text: "" });
new Setting(openaiSettingsContainer)
.setName('OpenAI API Key')
.setDesc('Enter your paid API key for OpenAI, found here https://platform.openai.com/account/api-keys')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.apiKey)
.onChange(async (value) => {
this.plugin.settings.apiKey = value;
await this.plugin.saveSettings();
})
);
new Setting(openaiSettingsContainer)
.setName('Chat Model')
.setDesc('Select your OpenAI model for chat')
.addDropdown((dropdown) =>
dropdown
.addOptions({
"gpt-3.5-turbo": 'GPT 3.5 Turbo',
"gpt-4-turbo": 'GPT 4 Turbo',
"gpt-4o": 'GPT 4o',
})
.setValue(this.plugin.settings.openaiChatModel || 'gpt-3.5-turbo')
.onChange(async (value) => {
this.plugin.settings.openaiChatModel = value;
await this.plugin.saveSettings();
})
);
new Setting(openaiSettingsContainer)
.setName('Though Finishing Model')
.setDesc('Select your OpenAI model for thought finishing')
.addDropdown((dropdown) =>
dropdown
.addOptions({
"gpt-3.5-turbo-instruct": 'GPT 3.5 turbo',
"davinci-002": 'Davinci',
"babbage-002": 'Babbage',
})
.setValue(this.plugin.settings.openaiCompleteModel || 'gpt-3.5-turbo')
.onChange(async (value) => {
this.plugin.settings.openaiCompleteModel = value;
await this.plugin.saveSettings();
})
);
containerEl.createEl("br", { text: "" });
const cloudflareSection = containerEl.createEl('details');
const cfsummaryEl = cloudflareSection.createEl('summary');
cfsummaryEl.createEl('strong', { text: 'Cloudflare Settings' });
const cloudflareSettingsContainer = cloudflareSection.createEl('div');
cloudflareSettingsContainer.createEl("br", { text: "" });
new Setting(cloudflareSettingsContainer)
.setName('Account ID')
.setDesc('Enter your free Cloudflare Account ID, found here https://dash.cloudflare.com/profile/api-tokens')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.cloudflareID)
.onChange(async (value) => {
this.plugin.settings.cloudflareID = value;
await this.plugin.saveSettings();
})
);
new Setting(cloudflareSettingsContainer)
.setName('API Key')
.setDesc('Enter your free Cloudflare API Key')
.addText((text) =>
text
.setPlaceholder('')
.setValue(this.plugin.settings.cloudflareKey)
.onChange(async (value) => {
this.plugin.settings.cloudflareKey = value;
await this.plugin.saveSettings();
})
);
new Setting(cloudflareSettingsContainer)
.setName('Enter Model')
.setDesc("Enter a huggingface model name, check cloudflare's dev docs for options")
.addText((text) =>
text
.setPlaceholder('thebloke/zephyr-7b-beta-awq')
.setValue(this.plugin.settings.cloudflareModel)
.onChange(async (value) => {
this.plugin.settings.cloudflareModel = value;
await this.plugin.saveSettings();
})
);
containerEl.createEl("br", { text: "" });
const customSection = containerEl.createEl('details');
const csummaryEl = customSection.createEl('summary');
csummaryEl.createEl('strong', { text: 'Custom/Local Settings' });
containerEl.createEl("br", { text: "" });
containerEl.createEl("br", { text: "" });
const customSettingsContainer = customSection.createEl('div');
customSettingsContainer.createEl("br", { text: "" });
new Setting(customSettingsContainer)
.setName('Custom API URL')
.setDesc("Enter the url for your backend's openAI compatible API, ends with /v1")
.addText((text) =>
text
.setPlaceholder('http://localhost:5001/v1')
.setValue(this.plugin.settings.customUrl)
.onChange(async (value) => {
this.plugin.settings.customUrl = value;
await this.plugin.saveSettings();
})
);
new Setting(customSettingsContainer)
.setName('Max Tokens for Thought finishing')
.setDesc('Set the maximum number of tokens the custom model will write when finishing your thoughts.')
.addText((text) =>
text
.setPlaceholder('192')
.setValue(this.plugin.settings.maxTokens.toString())
.onChange(async (value) => {
const parsedValue = parseInt(value, 10);
this.plugin.settings.maxTokens = isNaN(parsedValue) ? 512 : parsedValue;
await this.plugin.saveSettings();
})
);
const embeddingsSection = containerEl.createEl('details');
const esummaryEl = embeddingsSection.createEl('summary');
esummaryEl.createEl('strong', { text: 'Embeddings Settings' });
const embeddingsSettingsContainer = embeddingsSection.createEl('div');
embeddingsSettingsContainer.createEl("br", { text: "" });
new Setting(embeddingsSettingsContainer)
.setName('Embeddings Provider')
.setDesc('Select your embeddins provider, I reccomend not changing this often')
.addDropdown((dropdown) =>
dropdown
.addOptions({
google: 'Google',
jina: 'Jina.ai',
})
.setValue(this.plugin.settings.embeddingsProvider || 'google')
.onChange(async (value) => {
this.plugin.settings.embeddingsProvider = value;
await this.plugin.saveSettings();
})
);
}
}