mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
Fix plugin loading when there is no openai key (#59)
* Fix onload issue when there is no openai key * Make openai key text field wider
This commit is contained in:
parent
5c137ed23f
commit
dadd890af8
3 changed files with 24 additions and 8 deletions
|
|
@ -124,6 +124,13 @@ class AIState {
|
|||
key, model, temperature, maxTokens,
|
||||
} = this.langChainParams;
|
||||
|
||||
if (!key) {
|
||||
new Notice(
|
||||
'No OpenAI API key provided. Please set it in Copilot settings, and restart the plugin.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
AIState.chatOpenAI = new ChatOpenAI({
|
||||
openAIApiKey: key,
|
||||
modelName: model,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import AIState from '@/aiState';
|
||||
import { ChatMessage } from '@/sharedState';
|
||||
import { Notice } from 'obsidian';
|
||||
|
||||
export type Role = 'assistant' | 'user' | 'system';
|
||||
|
||||
|
|
@ -12,17 +13,25 @@ export const getAIResponse = async (
|
|||
updateShouldAbort: (abortController: AbortController | null) => void,
|
||||
debug = false,
|
||||
) => {
|
||||
const {
|
||||
key,
|
||||
model,
|
||||
temperature,
|
||||
maxTokens,
|
||||
systemMessage,
|
||||
chatContextTurns,
|
||||
} = aiState.langChainParams;
|
||||
if (!key) {
|
||||
new Notice(
|
||||
'No OpenAI API key provided. Please set it in Copilot settings, and restart the plugin.'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const abortController = new AbortController();
|
||||
|
||||
updateShouldAbort(abortController);
|
||||
if (debug) {
|
||||
const {
|
||||
model,
|
||||
temperature,
|
||||
maxTokens,
|
||||
systemMessage,
|
||||
chatContextTurns,
|
||||
} = aiState.langChainParams;
|
||||
console.log(`*** DEBUG INFO ***\n`
|
||||
+ `user message: ${userMessage.message}\n`
|
||||
+ `model: ${model}\n`
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ export class CopilotSettingTab extends PluginSettingTab {
|
|||
)
|
||||
.addText((text) => {
|
||||
text.inputEl.type = "password";
|
||||
text.inputEl.style.width = "80%";
|
||||
text.inputEl.style.width = "100%";
|
||||
text
|
||||
.setPlaceholder("OpenAI API key")
|
||||
.setValue(this.plugin.settings.openAiApiKey)
|
||||
|
|
|
|||
Loading…
Reference in a new issue